hyperion::mpl::Value#
- group Metaprogramming Value Type
Hyperion provides
mpl::Valueas a metaprogramming type for storing, communicating, working with, and calculating compile-time values.Example#
#include <hyperion/mpl/value.h> using namespace hyperion::mpl; constexpr auto val1 = Value<4>{}; constexpr auto val2 = Value<2>{}; constexpr auto meaning_of_life = (val1 * 10_value) + val2; static_assert(meaning_of_life == 42);
Functions
-
template<char... TChars>
static inline auto operator""_value() noexcept# Numeric literal operator to create a compile-time
Value.Valuerepresents a compile time value, storing that value in itsstatic constexprmember variable,value.- Template Parameters:
TChars – The characters of the numeric literal
-
template<auto TValue, typename TType = decltype(TValue)>
decltype(TValue) value_of(const Value<TValue, TType> &value) noexcept# Returns the compile-time value of the given
mpl::Value- Template Parameters:
TValue – The compile-time value of
valueTType – The type of the compile-time value
- Parameters:
value – The
mpl::Valueto get the compile-time value of- Returns:
the compile-time value of the given
mpl::Value
-
template<MetaValue TType>
decltype(TType::value) value_of(const TType &value) noexcept# Returns the compile-time value of the given
mpl::ValueRequirements#
TTypemust be anmpl::MetaValueTTypemust not be a specialization ofmpl::Value
- Template Parameters:
TType – The
mpl::MetaValuestoring the compile-time value- Parameters:
value – The
mpl::MetaValueto get the compile-time value of- Returns:
the compile-time value of the given
mpl::Value
-
template<MetaValue TType>
Value<TType::value, std::remove_cvref_t<decltype(TType::value)>> as_value(const TType &value) noexcept# Returns the given
mpl::MetaValueinto anmpl::ValueRequirements#
TTypemust be anmpl::MetaValueTTypemust not be a specialization ofmpl::Value
- Template Parameters:
TType – The
mpl::MetaValuestoring the compile-time value- Parameters:
value – The
mpl::MetaValueto get the compile-time value of- Returns:
the compile-time value of the given
mpl::Value
-
template<auto TValue, typename TType = decltype(TValue)>
Value<TValue> operator+(const Value<TValue, TType> &value) noexcept# Unary plus operator for
mpl::Value.Requirements#
The type of
TValuemust beUnaryPlusable(it must support unaryoperator+).
- Template Parameters:
TValue – The value of this
ValueTType – The type of
TValue
- Parameters:
value – The
mpl::Valueto +- Returns:
The
mpl::Valuerepresenting+TValue
-
template<auto TValue, typename TType = decltype(TValue)>
Value<-TValue> operator-(const Value<TValue, TType> &value) noexcept# Unary minus operator for
mpl::Value.Requirements#
The type of
TValuemust beUnaryMinusable(it must support unaryoperator-).
- Template Parameters:
TValue – The value of this
ValueTType – The type of
TValue
- Parameters:
value – The
mpl::Valueto -- Returns:
The
mpl::Valuerepresenting-TValue
-
template<auto TLhs, auto TRhs, typename TTypeLhs = decltype(TLhs), typename TTypeRhs = decltype(TRhs)>
Value<TLhs + TRhs> operator+(const Value<TLhs, TTypeLhs> &lhs, const Value<TRhs, TTypeRhs> &rhs) noexcept# Adds the two given
mpl::Values and returns the result as anothermpl::Valuespecialization.Requirements#
TLhsandTRhsmust be addable
- Template Parameters:
TLhs – The value of the left-hand
mpl::ValueTRhs – The value of the right-hand
mpl::ValueTTypeLhs – The type of
TLhsTTypeRhs – The type of
RLhs
- Parameters:
lhs – The left-hand
mpl::Valueto addrhs – The right-hand
mpl::Valueto add
- Returns:
The
mpl::ValuerepresentingTLhs + TRhs
-
template<auto TLhs, auto TRhs, typename TTypeLhs = decltype(TLhs), typename TTypeRhs = decltype(TRhs)>
Value<TLhs - TRhs> operator-(const Value<TLhs, TTypeLhs> &lhs, const Value<TRhs, TTypeRhs> &rhs) noexcept# Subtracts
rhsfromlhsand returns the result as anothermpl::Valuespecialization.Requirements#
TLhsandTRhsmust be subtractable
- Template Parameters:
TLhs – The value of the left-hand
mpl::ValueTRhs – The value of the right-hand
mpl::ValueTTypeLhs – The type of
TLhsTTypeRhs – The type of
RLhs
- Parameters:
lhs – The left-hand
mpl::Valueto subtract fromrhs – The right-hand
mpl::Valueto subtract
- Returns:
The
mpl::ValuerepresentingTLhs - TRhs
-
template<auto TLhs, auto TRhs, typename TTypeLhs = decltype(TLhs), typename TTypeRhs = decltype(TRhs)>
Value<TLhs * TRhs> operator*(const Value<TLhs, TTypeLhs> &lhs, const Value<TRhs, TTypeRhs> &rhs) noexcept# Multiplies the two given
mpl::Values and returns the result as anothermpl::Valuespecialization.Requirements#
TLhsandTRhsmust be multipliable
- Template Parameters:
TLhs – The value of the left-hand
mpl::ValueTRhs – The value of the right-hand
mpl::ValueTTypeLhs – The type of
TLhsTTypeRhs – The type of
RLhs
- Parameters:
lhs – The left-hand
mpl::Valueto addrhs – The right-hand
mpl::Valueto add
- Returns:
The
mpl::ValuerepresentingTLhs * TRhs
-
template<auto TLhs, auto TRhs, typename TTypeLhs = decltype(TLhs), typename TTypeRhs = decltype(TRhs)>
Value<TLhs / TRhs> operator/(const Value<TLhs, TTypeLhs> &lhs, const Value<TRhs, TTypeRhs> &rhs) noexcept# Divides
lhsbyrhsand returns the result as anothermpl::Valuespecialization.Requirements#
TLhsandTRhsmust be dividible
- Template Parameters:
TLhs – The value of the left-hand
mpl::ValueTRhs – The value of the right-hand
mpl::ValueTTypeLhs – The type of
TLhsTTypeRhs – The type of
RLhs
- Parameters:
lhs – The left-hand
mpl::Valueto dividerhs – The right-hand
mpl::Valueto divide by
- Returns:
The
mpl::ValuerepresentingTLhs / TRhs
-
template<auto TLhs, auto TRhs, typename TTypeLhs = decltype(TLhs), typename TTypeRhs = decltype(TRhs)>
Value<TLhs && TRhs> operator&&(const Value<TLhs, TTypeLhs> &lhs, const Value<TRhs, TTypeRhs> &rhs) noexcept# Performs the boolean and of
lhsandrhsRequirements#
TLhsandTRhsmust be boolean andable
- Template Parameters:
TLhs – The value of the left-hand
mpl::ValueTRhs – The value of the right-hand
mpl::ValueTTypeLhs – The type of
TLhsTTypeRhs – The type of
RLhs
- Parameters:
lhs – The left-hand
mpl::Valueto andrhs – The right-hand
mpl::Valueto and
- Returns:
The
mpl::ValuerepresentingTLhs && TRhs
-
template<auto TLhs, auto TRhs, typename TTypeLhs = decltype(TLhs), typename TTypeRhs = decltype(TRhs)>
Value<TLhs || TRhs> operator||(const Value<TLhs, TTypeLhs> &lhs, const Value<TRhs, TTypeRhs> &rhs) noexcept# Performs the boolean or of
lhsandrhsRequirements#
TLhsandTRhsmust be boolean orable
- Template Parameters:
TLhs – The value of the left-hand
mpl::ValueTRhs – The value of the right-hand
mpl::ValueTTypeLhs – The type of
TLhsTTypeRhs – The type of
RLhs
- Parameters:
lhs – The left-hand
mpl::Valueto orrhs – The right-hand
mpl::Valueto or
- Returns:
The
mpl::ValuerepresentingTLhs || TRhs
-
template<auto TValue, typename TType = decltype(TValue)>
Value<!TValue, TType> operator!(const Value<TValue, TType> &value) noexcept# Performs the boolean not of
valueRequirements#
TValueboolean notable
- Template Parameters:
TValue – The value of the
mpl::ValueTType – The type of
TValue
- Parameters:
value – The
mpl::Valueto not- Returns:
The
mpl::Valuerepresenting!TLhs
-
template<auto TLhs, auto TRhs, typename TTypeLhs = decltype(TLhs), typename TTypeRhs = decltype(TRhs)>
Value<TLhs & TRhs> operator&(const Value<TLhs, TTypeLhs> &lhs, const Value<TRhs, TTypeRhs> &rhs) noexcept# Performs the binary and of
lhsandrhsRequirements#
TLhsandTRhsmust be binary andable
- Template Parameters:
TLhs – The value of the left-hand
mpl::ValueTRhs – The value of the right-hand
mpl::ValueTTypeLhs – The type of
TLhsTTypeRhs – The type of
RLhs
- Parameters:
lhs – The left-hand
mpl::Valueto andrhs – The right-hand
mpl::Valueto and
- Returns:
The
mpl::ValuerepresentingTLhs & TRhs
-
template<auto TLhs, auto TRhs, typename TTypeLhs = decltype(TLhs), typename TTypeRhs = decltype(TRhs)>
Value<TLhs | TRhs> operator|(const Value<TLhs, TTypeLhs> &lhs, const Value<TRhs, TTypeRhs> &rhs) noexcept# Performs the binary or of
lhsandrhsRequirements#
TLhsandTRhsmust be binary orable
- Template Parameters:
TLhs – The value of the left-hand
mpl::ValueTRhs – The value of the right-hand
mpl::ValueTTypeLhs – The type of
TLhsTTypeRhs – The type of
RLhs
- Parameters:
lhs – The left-hand
mpl::Valueto orrhs – The right-hand
mpl::Valueto or
- Returns:
The
mpl::ValuerepresentingTLhs | TRhs
-
template<auto TValue, typename TType = decltype(TValue)>
Value<~TValue, TType> operator~(const Value<TValue, TType> &value) noexcept# Performs the binary not of
valueRequirements#
TValuebinary notable
- Template Parameters:
TValue – The value of the
mpl::ValueTType – The type of
TValue
- Parameters:
value – The
mpl::Valueto not- Returns:
The
mpl::Valuerepresenting!TLhs
-
template<auto TLhs, auto TRhs, typename TTypeLhs = decltype(TLhs), typename TTypeRhs = decltype(TRhs)>
Value<TLhs == TRhs> operator==(const Value<TLhs, TTypeLhs> &lhs, const Value<TRhs, TTypeRhs> &rhs) noexcept# Equality comparison operator between two
mpl::Values.Requirements#
TLhsandTRhsmust be equality comparable
- Template Parameters:
TLhs – The value of the left-hand
mpl::ValueTRhs – The value of the right-hand
mpl::ValueTTypeLhs – The type of
TLhsTTypeRhs – The type of
RLhs
- Parameters:
lhs – The left-hand
mpl::Valueto comparerhs – The right-hand
mpl::Valueto compare with
- Returns:
Whether the value of
lhsis equal to the value ofrhs
-
template<auto TLhs, auto TRhs, typename TTypeLhs = decltype(TLhs), typename TTypeRhs = decltype(TRhs)>
Value<TLhs != TRhs> operator!=(const Value<TLhs, TTypeLhs> &lhs, const Value<TRhs, TTypeRhs> &rhs) noexcept# Inequality comparison operator between two
mpl::Values.Requirements#
TLhsandTRhsmust be inequality comparable
- Template Parameters:
TLhs – The value of the left-hand
mpl::ValueTRhs – The value of the right-hand
mpl::ValueTTypeLhs – The type of
TLhsTTypeRhs – The type of
RLhs
- Parameters:
lhs – The left-hand
mpl::Valueto comparerhs – The right-hand
mpl::Valueto compare with
- Returns:
Whether the value of
lhsis not equal to the value ofrhs
-
template<auto TLhs, auto TRhs, typename TTypeLhs = decltype(TLhs), typename TTypeRhs = decltype(TRhs)>
Value<TLhs <=> TRhs> operator<=>(const Value<TLhs, TTypeLhs> &lhs, const Value<TRhs, TTypeRhs> &rhs) noexcept# Three-way comparison operator between two
mpl::Values.Requirements#
TLhsandTRhsmust be three-way comparable
- Template Parameters:
TLhs – The value of the left-hand
mpl::ValueTRhs – The value of the right-hand
mpl::ValueTTypeLhs – The type of
TLhsTTypeRhs – The type of
RLhs
- Parameters:
lhs – The left-hand
mpl::Valueto comparerhs – The right-hand
mpl::Valueto compare with
- Returns:
The result of three-way comparing the value of
lhswith the value ofrhs
-
template<auto TLhs, auto TRhs, typename TTypeLhs = decltype(TLhs), typename TTypeRhs = decltype(TRhs)>
Value<(TLhs < TRhs)> operator<(const Value<TLhs, TTypeLhs> &lhs, const Value<TRhs, TTypeRhs> &rhs) noexcept# Less-than comparison operator between two
mpl::Values.Requirements#
TLhsandTRhsmust be less-than comparable
- Template Parameters:
TLhs – The value of the left-hand
mpl::ValueTRhs – The value of the right-hand
mpl::ValueTTypeLhs – The type of
TLhsTTypeRhs – The type of
RLhs
- Parameters:
lhs – The left-hand
mpl::Valueto comparerhs – The right-hand
mpl::Valueto compare with
- Returns:
Whether the value of
lhsis less than the value ofrhs
-
template<auto TLhs, auto TRhs, typename TTypeLhs = decltype(TLhs), typename TTypeRhs = decltype(TRhs)>
Value<(TLhs <= TRhs)> operator<=(const Value<TLhs, TTypeLhs> &lhs, const Value<TRhs, TTypeRhs> &rhs) noexcept# Less-than-or-equal comparison operator between two
mpl::Values.Requirements#
TLhsandTRhsmust be less-than-or-equal comparable
- Template Parameters:
TLhs – The value of the left-hand
mpl::ValueTRhs – The value of the right-hand
mpl::ValueTTypeLhs – The type of
TLhsTTypeRhs – The type of
RLhs
- Parameters:
lhs – The left-hand
mpl::Valueto comparerhs – The right-hand
mpl::Valueto compare with
- Returns:
Whether the value of
lhsis less than or equal to the value ofrhs
-
template<auto TLhs, auto TRhs, typename TTypeLhs = decltype(TLhs), typename TTypeRhs = decltype(TRhs)>
Value<(TLhs > TRhs)> operator>(const Value<TLhs, TTypeLhs> &lhs, const Value<TRhs, TTypeRhs> &rhs) noexcept# Greater-than comparison operator between two
mpl::Values.Requirements#
TLhsandTRhsmust be greater-than comparable
- Template Parameters:
TLhs – The value of the left-hand
mpl::ValueTRhs – The value of the right-hand
mpl::ValueTTypeLhs – The type of
TLhsTTypeRhs – The type of
RLhs
- Parameters:
lhs – The left-hand
mpl::Valueto comparerhs – The right-hand
mpl::Valueto compare with
- Returns:
Whether the value of
lhsis greater than the value ofrhs
-
template<auto TLhs, auto TRhs, typename TTypeLhs = decltype(TLhs), typename TTypeRhs = decltype(TRhs)>
Value<(TLhs >= TRhs)> operator>=(const Value<TLhs, TTypeLhs> &lhs, const Value<TRhs, TTypeRhs> &rhs) noexcept# Greater-than-or-equal comparison operator between two
mpl::Values.Requirements#
TLhsandTRhsmust be greater-than-or-equal comparable
- Template Parameters:
TLhs – The value of the left-hand
mpl::ValueTRhs – The value of the right-hand
mpl::ValueTTypeLhs – The type of
TLhsTTypeRhs – The type of
RLhs
- Parameters:
lhs – The left-hand
mpl::Valueto comparerhs – The right-hand
mpl::Valueto compare with
- Returns:
Whether the value of
lhsis greater than or equal to the value ofrhs
-
template<auto TValue, typename TType = std::remove_cvref_t<decltype(TValue)>>
struct Value# - #include <hyperion/mpl/value.h>
Valueis Hyperion’s preferred metaprogramming value type.Valuerepresents a compile time value, storing that value in itsstatic constexprmember variable,value.- Template Parameters:
TValue – The value of this
ValueTType – The type of
TValue. This can be manually specified to enforce thatTValueis coerced toTType(for example, in order to forceTValueto be anint, instead ofstd::size_t)
Public Functions
-
inline constexpr operator TType() const noexcept#
Conversion operator to the
value.- Returns:
The
valueof this specialization ofValue
-
inline TType operator()() const noexcept#
Call operator to get the
value.- Returns:
The
valueof this specialization ofValue
-
inline explicit constexpr operator bool() const noexcept#
Conversion operator to
bool. Converts thevalueof this specialization ofValuetobool.Requirements#
TTypemust be convertible toboolTTypemust not bebool
- Returns:
the
valueof this specialization ofValue, converted tobool
-
template<template<typename> typename TMetaFunction>
inline detail::unwrap_inner_t<detail::convert_to_meta_t<TMetaFunction<Value>>> apply() const noexcept# Applies the specified template metafunction to this specialization of
Value.Applies
TMetaFunctionto this specialization ofValueand returns the calculated result as a metaprogramming type.Requirements#
TMetaFunctionmust be aTypeMetaFunction:It must be a template taking a single type parameter,
It must have a
static constexprmember variable,value, or a using alias type,type
Example#
template<typename TValue> struct add_one_typed { using type = Value<TValue::value + 1>; }; // `two` is `Value<2, usize>` constexpr auto two = (1_value).apply<add_one>(); static_assert(two == 2_value); template<typename TValue> struct add_one_typed { using type = Type<Value<TValue::value + 1>>; }; // `two_typed` is `Value<2, usize>` constexpr auto two_typed = (1_value).apply<add_one_typed>().inner(); static_assert(two_typed == 2_value);
- Template Parameters:
TMetaFunction – The template metafunction to apply to this
Value- Returns:
The result of applying
TMetaFunction
-
template<template<auto> typename TMetaFunction>
inline detail::unwrap_inner_t<detail::convert_to_meta_t<TMetaFunction<value>>> apply() const noexcept# Applies the specified template metafunction to this specialization of
Value.Applies
TMetaFunctionto this specialization ofValueand returns the calculated result as a metaprogramming type.Requirements#
TMetaFunctionmust be aValueMetaFunction:It must be a template taking a single value parameter,
It must have a
static constexprmember variable,value, or a using alias type,type
Example#
template<auto TValue> struct add_one { static inline constexpr auto value = TValue + 1>; }; constexpr auto two = (1_value).apply<add_one>(); // `two` is `Value<2, usize>` static_assert(two == 2_value); template<auto TValue> struct add_one_typed { using type = Type<Value<TValue + 1>>; }; // `two_typed` is `Value<2, usize>` constexpr auto two_typed = (1_value).apply<add_one_typed>().inner(); static_assert(two_typed == 2_value);
- Template Parameters:
TMetaFunction – The template metafunction to apply to this
Value- Returns:
The result of applying
TMetaFunction
-
template<typename TFunction>
inline detail::unwrap_inner_t<detail::convert_to_meta_t<meta_result_t<TFunction, Value>>> apply(TFunction &&func) const noexcept# Applies the given metafunction to this specialization of
Value.Applies
functo this specialization ofValueand returns the calculated result as a metaprogramming type.Requirements#
Example#
constexpr auto add_one = [](MetaValue auto value) { return value + 1_value; }; // `two` is `Value<2, usize>` constexpr auto two = (1_value).apply(add_one_typed); static_assert(two == 2_value); constexpr auto add_one_typed = [](MetaValue auto value) { return decltype_(value + 1_value); }; // `two` is `Value<2, usize>` constexpr auto two_typed = (1_value).apply(add_one_typed).inner(); static_assert(two_typed == 2_value);
- Template Parameters:
TFunction – The type of the metafunction to apply
- Parameters:
func – The metafunction to apply
- Returns:
The result of applying
functo thisValuespecialization
-
template<template<auto> typename TPredicate>
inline Value<TPredicate<value>::value> satisfies() const noexcept# Checks to see if this
Valuespecialization satisfies the given metafunction predicate,TPredicateRequirements#
TPredicatemust be aValueMetaFunctionIt must be a template taking a single value parameter,
It must have a
static constexprmember variable,value, or a using alias type,type
TPredicate<value>must be aMetaValueThe type of the value of
TPredicate,TPredicate<value>::value, must be (possibly cv-ref qualified)bool)
Example#
template<auto TValue> struct is_two { static inline constexpr auto value = TValue == 2; }; constexpr auto not_two = (1_value).satisfies<is_two>(); // `not_two` is // `Value<false, bool>` constexpr auto was_two = (2_value).satisfies<is_two>(); // `was_two` is // `Value<true, bool>`
-
template<template<typename> typename TPredicate>
inline Value<TPredicate<Value>::value> satisfies() const noexcept# Checks to see if this
Valuespecialization satisfies the given metafunction predicate,TPredicateRequirements#
TPredicatemust be aTypeMetaFunctionIt must be a template taking a single type parameter,
It must have a
static constexprmember variable,value, or a using alias type,type
The type of the value of
TPredicate,TPredicate<Value>::value, must be (possibly cv-ref qualified)bool)
Example#
template<MetaValue TValue> struct is_two { static inline constexpr auto value = TValue::value == 2; }; constexpr auto not_two = (1_value).satisfies<is_two>(); // `not_two` is // `Value<false, bool>` constexpr auto was_two = (2_value).satisfies<is_two>(); // `was_two` is // `Value<true, bool>`
-
template<typename TPredicate>
inline auto satisfies(TPredicate &&predicate) const noexcept# Checks to see if this
Valuespecialization satisfies the given metafunction predicate,predicateIf
predicateis not aMetaPredicateOf<Value>type, returnsValue<false>Example#
constexpr auto is_two = [](MetaValue auto value) -> Value<decltype(value)::value == 2> { return {}; }; constexpr auto not_two = (1_value).satisfies(is_two); // `not_two` is // `Value<false, bool>` constexpr auto was_two = (2_value).satisfies(is_two); // `was_two` is // `Value<true, bool>`
-
template<char... TChars>