Template Struct CheckedIntegral

Struct Documentation

template<std::integral I>
struct CheckedIntegral

Wraps an integer type and keeps track of Overflows and similar Undefined Behavior. Designed to be used in std::chrono::duration, but may be used standalone.

Template Parameters:

I – Integer type to wrap

Public Functions

inline constexpr CheckedIntegral(I value, bool invalid = false) noexcept

Creates a CheckedIntegral from the underlying type and optionally a invalid specifier.

Note

Not explicit to allow arithmetic operations on CheckedIntegral and its underlying type.

Parameters:
  • value

  • invalid

inline constexpr bool is_invalid() const noexcept

Checks if the contained value is invalid.

Returns:

inline constexpr I get_value() const noexcept

Returns the contained value.

Note

returned value is garbage, if is_invalid() evaluates to true.

Returns:

inline constexpr std::partial_ordering operator<=>(const CheckedIntegral &other) const noexcept
inline constexpr CheckedIntegral &operator+=(const CheckedIntegral &other) noexcept
inline constexpr CheckedIntegral operator+(const CheckedIntegral &other) const noexcept
inline constexpr CheckedIntegral &operator-=(const CheckedIntegral &other) noexcept
inline constexpr CheckedIntegral operator-(const CheckedIntegral &other) const noexcept
inline constexpr CheckedIntegral &operator*=(const CheckedIntegral &other) noexcept
inline constexpr CheckedIntegral operator*(const CheckedIntegral &other) const noexcept
inline constexpr CheckedIntegral &operator/=(const CheckedIntegral &other) noexcept
inline constexpr CheckedIntegral operator/(const CheckedIntegral &other) const noexcept

Friends

inline friend constexpr friend CheckedIntegral abs (CheckedIntegral const &val) noexcept