Template Struct Value

Struct Documentation

template<typename T, typename Tag>
struct Value

Wraps a geometry value and prevents it from being accidentally used for invalid operations (such as setting a width to a height or adding two x positions together). Of course, explicit casts are possible to get around these restrictions (see the as_*() functions).

Public Types

using ValueType = T
using TagType = Tag

Public Functions

template<typename Q = T>
inline constexpr std::enable_if<std::is_integral<Q>::value, int>::type as_int() const
template<typename Q = T>
inline constexpr std::enable_if<std::is_integral<Q>::value, uint32_t>::type as_uint32_t() const
template<typename Q>
inline constexpr Q as() const

Losslessly extract the underlying value.

The as<Q> accessor will exist for any numeric type Q that can exactly represent any valid ValueType

For example, if ValueType is int32_t, then as<int64_t> and as<double> both exist as an i32 is exactly representable in a double, but as<uint64_t> and as<float> do not exist, as int32_t can contain negative values not representable in uint64_t, and float does not have sufficient precision to exactly represent any int32_t value.

template<typename Q>
inline constexpr Q round_to() const

Convert to a different type, possibly losing precision but not range.

The round_to<Q> accessor will exist for any numeric type Q that have enough range to represent any valid ValueType.

inline constexpr T as_value() const noexcept
inline constexpr Value() noexcept
inline Value &operator=(Value const &that) noexcept
inline constexpr Value(Value const &that) noexcept
template<typename U>
inline explicit constexpr Value(Value<U, Tag> const &value) noexcept
template<typename U, typename std::enable_if<std::is_scalar<U>::value, bool>::type = true>
inline explicit constexpr Value(U const &value) noexcept

Protected Attributes

T value

Friends

friend auto operator<=>(Value const &lhs, Value const &rhs) = default