hyperion::mpl::List#
- group list
Hyperion provides
mpl::List
as a metaprogramming type for storing, communicating, working with, and operating on lists of types or values.Example#
#include <hyperion/mpl/list.h> #include <hyperion/mpl/metapredicates.h> using namespace hyperion::mpl; constexpr auto add_const = [](MetaType auto type) noexcept { return type.add_const(); }; constexpr auto list = List<int, double, float>{}; constexpr auto zipped = list.zip(List<u32, usize, i32>{}); constexpr auto constified = zipped.apply(add_const); static_assert(constified == List<Pair<const int, const u32>, Pair<const double, const usize>, Pair<const float, const i32>>{}); static_assert(constified.all_of(is_const));
Exposition-Only Types#
struct as_meta
: Exposition-only template metafunction that converts a type,TType
, to the corresponding metaprogramming type, exposed via the memberusing
aliastype
. MapsTType
in the following manner:If
TType
is aMetaType
, maps toType<typename as_meta<typename TType::type>::type>
, elseIf
TType
is aMetaValue
, maps toValue<TType::value>
, elseIf
TType
is aMetaPair
, maps to, elsePair<typename as_meta<typename TType::first>::type, typename as_meta<typename TType::second>::type>
Maps to
Type<TType>
struct as_raw
: Exposition-only template metafunction that converts a type,TType
, to the corresponding raw type, exposed via the memberusing
aliastype
. MapsTType
in the following manner:If
TType
is aMetaType
, maps totypename as_raw<typename TType::type>::type
, elseIf
TType
is aMetaValue
, maps toValue<TType::value>
, elseIf
TType
is aMetaPair
, maps to, elsePair<typename as_raw<typename TType::first>::type, typename as_raw<typename TType::second>::type>
Maps to
TType
Functions
-
template<typename ...TLHTypes, typename ...TRHTypes>
constexpr auto operator==(const List<TLHTypes...> &lhs, const List<TRHTypes...> &rhs) noexcept# Equality comparison operator for
List
Checks that each element of
lhs
is equal to the corresponding (by index) element ofrhs
, as if byequal_to(lhs.at(index))(rhs.at(index))
.Example#
static_assert(List<int, double, float>{} == List<int, double, float>{}); static_assert(List<Value<1, i32>, double, float>{} == List<Value<1, u32>, double, float>{});
-
template<typename ...TLHTypes, typename ...TRHTypes>
constexpr auto operator!=(const List<TLHTypes...> &lhs, const List<TRHTypes...> &rhs) noexcept# Inequality comparison operator for
List
Checks that any element of
lhs
is not equal to the corresponding (by index) element ofrhs
, as if bynot_equal_to(lhs.at(index))(rhs.at(index))
.Example#
static_assert(List<int, double, float>{} != List<float, double, float>{}); static_assert(List<Value<1, i32>, double, float>{} != List<Value<2, u32>, double, float>{});
-
template<typename ...TTypes>
constexpr auto make_list(TTypes&&... types) noexcept# Creates an
mpl::List
representing the types of the given arguments,types
Example#
static_assert(make_list(1, 1.0, 1_usize, 1_value) == List<int, double, usize, Value<1_usize>>{});
-
template<typename ...TTypes>
constexpr auto make_list() noexcept# Creates an
mpl::List
representing the specified types.Example#
static_assert(make_list<int, double, usize, Value<1>, Type<int>>() == List<int, double, usize, Value<1>, int>{});
-
template<typename ...TTypes>
constexpr auto operator|(List<TTypes...> list, auto range_object)# Pipeline operator for
mpl::List
s. Provides support for pipingmpl::List
s intostd::ranges
algorithms and views.Example#
constexpr auto list = List<int, const double, float>{}; constexpr auto ranged = list | std::ranges::views::filter([](auto type) { return not type.is_const(); }) | std::ranges::views::transform([](auto type) { return type.as_lvalue_reference().as_volatile(); }) | std::ranges::views::reverse | std::ranges::views::drop(1_value); static_assert(ranged == List<volatile int&>{});
- Template Parameters:
TTypes – the types represented in the
List
- Parameters:
list – the list to pipe into a
std::ranges
algorithm or viewrange_object – the
std::ranges
algorithm or view to pipe into
- Returns:
the result of the pipeline, up to this point
-
struct not_found_tag#
- #include <hyperion/mpl/list.h>
Tag type indicating that a searching operation in an
mpl::List
could not find a/the desired result.
-
template<typename ...TTypes>
struct List# - #include <hyperion/mpl/list.h>
List
is a metaprogramming type for storing, communicating, working with, and operating on lists of types or values.Example#
#include <hyperion/mpl/list.h> #include <hyperion/mpl/metapredicates.h> using namespace hyperion::mpl; constexpr auto add_const = [](MetaType auto type) noexcept { return type.add_const(); }; constexpr auto const_zipped = List<int, double, float>{} .zip(List<u32, usize, i32>{}) .apply(add_const); static_assert(const_zipped == List<Pair<const int, const u32>, Pair<const double, const usize>, Pair<const float, const i32>>{}); static_assert(const_zipped.all_of(is_const)); constexpr auto nums = List<Value<1>, Value<2>, Value<3>>{}; static_assert(nums.accumulate(0_value) == 6_value);
- Template Parameters:
TTypes – The types to represent in the list
Public Functions
-
inline constexpr auto size() const noexcept#
Returns the size of this
List
- Returns:
the size of this
List
-
template<typename TFunction>
inline constexpr auto apply(TFunction &&func) const noexcept# Applies the metafunction
func
to the elements of thisList
, returning the result as a newList
specialization.Using the exposition-only template metafunctions
as_meta
andas_raw
(see the corresponding section in the Metaprogramming List Type module-level documentation), appliesfunc
to each element,TElement
, of thisList
as if bytypename as_raw<decltype(typename as_meta<TElement>::type{}.apply(func))>::type
.Requirements#
func
must be a metafunction invocable with the corresponding metaprogramming type of each element in thisList
. That is,func
must be aMetaFunctionOf<TFunction, typename as_meta<TElement>::type>
for each element,TElement
, of thisList
OR,
func
must be a metafunction appliable to the corresponding metaprogramming type of each element in thisList
. That is,typename as_meta<TElement>::type{}.apply(func)
must be well formed for each element,TElement
, of thisList
Example#
constexpr auto add_const = [](MetaType auto type) noexcept { return type.add_const(); }; static_assert(List<int, double>{}.apply(add_const) == List<const int, const double>{});
-
template<typename TVisitor>
inline constexpr auto for_each(TVisitor &&vis) const noexcept -> void# Invokes the function
vis
with each element of thisList
.This is the canonical way to iterate through the elements of a
List
.Using the exposition-only template metafunction
as_meta
(see the corresponding section in the Metaprogramming List Type module-level documentation), appliesvis
to each element,TElement
, of thisList
as if byvis(typename as_meta<TElement>::type{})
.Requirements#
Example#
constexpr auto example = List<Value<1>, int, float, double, int>{}; constexpr auto count_if = [](auto list, auto predicate) noexcept { auto num_satisfied = 0; list.for_each([&num_satisfied, predicate](auto element) { if(element.satisfies(predicate)) { num_satisfied++; } }); return num_satisfied; }; constexpr auto num_ints = count_if(example, equal_to(decltype_<int>())); static_assert(num_ints == 2);
-
template<typename TVisitor, MetaValue TCount>
inline constexpr auto for_each_n(TVisitor &&vis, TCount count) const noexcept -> void# Invokes the function
vis
with the firstcount
elements of thisList
.This is the canonical way to iterate through a subset of the elements of a
List
.Using the exposition-only template metafunction
as_meta
(see the corresponding section in the Metaprogramming List Type module-level documentation), appliesvis
to each element,TElement
, of thisList
as if byvis(typename as_meta<TElement>::type{})
.Requirements#
vis
must be invocable with the corresponding metaprogramming type for each element of thisList
. This is, for each element,TElement
,std::invocable<TVisitor, typename as_meta<TElement>::type>
must be true.The invoke result of
vis
for each element of thisList
must bevoid
.count
must be less than or equal to the number of elements of thisList
Example#
constexpr auto example = List<Value<1>, int, float, double, int>{}; constexpr auto count_if_in_first_half = [](auto list, auto predicate) noexcept { auto num_satisfied = 0; list.for_each_n([&num_satisfied, predicate](auto element) { if(element.satisfies(predicate)) { num_satisfied++; } }, list.size() / 2_value); return num_satisfied; }; constexpr auto num_ints = count_if_in_first_half(example, equal_to(decltype_<int>())); static_assert(num_ints == 1);
-
inline constexpr auto accumulate(MetaValue auto state) const noexcept#
Computes the arithmetic sum of
state
and the elements of thisList
.Requirements#
Example#
static_assert(List<Value<1>, Value<2>, Value<3>>{}.accumulate(4_value) == 10);
-
template<typename TDelay = List<as_meta<TTypes>...>>
inline constexpr auto accumulate(auto state, auto &&accumulator) const noexcept# Computes the accumulation of
state
and the elements of thisList
.Using the exposition-only template metafunction
as_meta
(see the corresponding section in the Metaprogramming List Type module-level documentation), andTElement_N
to represent the type of each element in thisList
, uses the accumulation operationaccumulator
, performs the accumulation of the elements of thisList
, in order, by first invokingaccumulator
withas_meta<decltype(state)>{}, as_meta<TElement_0>{}
, then continues to callaccumulator
for each successiveTElement
, using the result of the previous invocation as thestate
parameter for the next invocation in the sequence.Requirements#
Using
TElement_N
to represent the type of each element in thisList
andTState
to represent bothdecltype(state)
and the (possibly different) type(s) of the return value of each possible invocation ofaccumulator
,accumulator
must be a callable taking two parameters, separately invocable with parameters of typesas_meta<TState_N>, as_meta<TElement_N>
, for each of allTElement
s andTState
s. That is, the recursive call chainmust be well-formed.accumulator( accumulator( ...( accumulator(as_meta<decltype(state)>{}, as_meta<TElement_0>{}), as_meta<TElement_1>{}), ...), as_meta<TElement_N-1>{})
Example#
static_assert(List<int, double, float, int>{} .accumulate(0_value, [](auto state, auto element) { // increment state if `element` is a `MetaType` representing `int` if constexpr(MetaType<decltype(element)>) { if constexpr(decltype(element){} == decltype_<int>()) { return state + 1_value; } else { return state; } } else { return state; } }) == 2);
- Parameters:
state – the initial state to begin the accumulation with
accumulator – the callable to perform the accumulation operation
- Returns:
the accumulation of
state
and the elements of thisList
, according toaccumulator
-
template<typename TPredicate>
inline constexpr auto find_if(TPredicate &&predicate) const noexcept# Returns the first element of this
List
that satisfies the metafunction predicatepredicate
.Using the exposition-only template metafunction
as_meta
(see the corresponding section in the Metaprogramming List Type module-level documentation), checks each element,TElement
, of thisList
to see whether it satisfiespredicate
, as if bytypename as_meta<TElement>::type{}.satisfies(predicate)
, and if satisfied, returns that element.If no element satisfying
predicate
is found, returnsType<not_found_tag>
Requirements#
predicate
must be a metapredicate invocable with the corresponding metaprogramming type of each element in thisList
. That is,func
must be aMetaPredicateOf<TFunction, typename as_meta<TElement>::type>
for each element,TElement
, of thisList
OR,
predicate
must be a metapredicate satisfiable with the corresponding metaprogramming type of each element in thisList
. That is,typename as_meta<TElement>::type{}.satisfy(predicate)
must be well formed for each element,TElement
, of thisList
Example#
static_assert(List<int, const double, float>{}.find_if(is_const) == decltype_<const double>()); static_assert(List<int, const double, float>{}.find_if(is_volatile) == decltype_<not_found_tag>()); static_assert(List<Value<1>, Value<2>, Value<3>>{}.find_if(is_const) == decltype_<not_found_tag>());
- Template Parameters:
TPredicate – The type of the metapredicate to use for searcch
- Parameters:
predicate – The metapredicate to use for search
- Returns:
the first element satisfying
predicate
, orType<not_found_tag>
if no element satisfiespredicate
-
inline constexpr auto find(auto value) const noexcept#
Returns the first element of this
List
that is equal tovalue
.If no element equal to
value
is found, returnsType<not_found_tag>
Example#
static_assert(List<int, const double, float>{}.find(decltype_<const double>()) == decltype_<const double>()); static_assert(List<int, const double, float>{}.find(decltype_<usize>()) == decltype_<not_found_tag>()); static_assert(List<int, const double, float>{}.find(1_value) == decltype_<not_found_tag>()); static_assert(List<int, Value<1>, const double, float>{}.find(1_value) == 1); static_assert(List<Value<1>, Value<2>, Value<3>>{}.find(4_value) == decltype_<not_found_tag>());
- Parameters:
value – The metaprogramming value to search for
- Returns:
the first element equal to
value
, orType<not_found_tag>
if no element equalsvalue
-
template<typename TPredicate>
inline constexpr auto count_if(TPredicate &&predicate) const noexcept# Returns the number of elements of this
List
that satisfy the metafunction predicatepredicate
, as aValue
specialization.Using the exposition-only template metafunction
as_meta
(see the corresponding section in the Metaprogramming List Type module-level documentation), checks each element,TElement
, of thisList
to see whether it satisfiespredicate
, as if bytypename as_meta<TElement>::type{}.satisfies(predicate)
, and if satisfied, increments the internal count.Requirements#
predicate
must be a metapredicate invocable with the corresponding metaprogramming type of each element in thisList
. That is,func
must be aMetaPredicateOf<TFunction, typename as_meta<TElement>::type>
for each element,TElement
, of thisList
OR,
predicate
must be a metapredicate satisfiable with the corresponding metaprogramming type of each element in thisList
. That is,typename as_meta<TElement>::type{}.satisfy(predicate)
must be well formed for each element,TElement
, of thisList
Example#
static_assert(List<int, const double, float>{}.count_if(is_const) == 1_value); static_assert(List<int, const double, float>{}.count_if(is_volatile) == 0_value); static_assert(List<Value<1>, Value<2>, Value<3>>{}.count_if(is_const) == 0_value);
- Template Parameters:
TPredicate – The type of the metapredicate to use
- Parameters:
predicate – The metapredicate to use
- Returns:
the number of elements satisfying
predicate
-
inline constexpr auto count(auto value) const noexcept#
Returns the number of elements of this
List
that are equal tovalue
, as aValue
specialization.Example#
static_assert(List<int, const double, float>{}.count(decltype_<const double>()) == 1); static_assert(List<int, const double, float>{}.count(decltype_<usize>()) == 0); static_assert(List<int, const double, float, int>{}.count(decltype_<int>()) == 2); static_assert(List<int, const double, float>{}.count(1_value) == 0); static_assert(List<int, Value<1>, const double, float>{}.count(1_value) == 1); static_assert(List<Value<1>, Value<2>, Value<3>>{}.count(4_value) == 0);
-
inline constexpr auto contains(auto value) const noexcept#
Returns whether this
List
contains an element equal tovalue
, as aValue
specialization.Example#
static_assert(List<int, const double, float>{}.contains(decltype_<const double>())); static_assert(not List<int, const double, float>{}.contains(decltype_<usize>())); static_assert(not List<int, const double, float>{}.contains(1_value)); static_assert(List<int, Value<1>, const double, float>{}.contains(1_value)); static_assert(not List<Value<1>, Value<2>, Value<3>>{}.contains(4_value));
-
template<typename TPredicate>
inline constexpr auto all_of(TPredicate &&predicate) const noexcept# Returns whether all elements of this
List
satisfy the metafunction predicatepredicate
, as aValue
specialization.Using the exposition-only template metafunction
as_meta
(see the corresponding section in the Metaprogramming List Type module-level documentation), checks each element,TElement
, of thisList
to see whether it satisfiespredicate
, as if bytypename as_meta<TElement>::type{}.satisfies(predicate)
.Requirements#
predicate
must be a metapredicate invocable with the corresponding metaprogramming type of each element in thisList
. That is,func
must be aMetaPredicateOf<TFunction, typename as_meta<TElement>::type>
for each element,TElement
, of thisList
OR,
predicate
must be a metapredicate satisfiable with the corresponding metaprogramming type of each element in thisList
. That is,typename as_meta<TElement>::type{}.satisfy(predicate)
must be well formed for each element,TElement
, of thisList
Example#
static_assert(List<const int, const double, const float>{}.all_of(is_const)); static_assert(not List<int, const double, float>{}.all_of(is_const)); static_assert(not List<Value<1>, Value<2>, Value<3>>{}.all_of(is_const));
- Template Parameters:
TPredicate – The type of the metapredicate to use
- Parameters:
predicate – The metapredicate to use
- Returns:
whether all elements satisfy
predicate
-
template<typename TPredicate>
inline constexpr auto any_of(TPredicate &&predicate) const noexcept# Returns whether any elements of this
List
satisfy the metafunction predicatepredicate
, as aValue
specialization.Using the exposition-only template metafunction
as_meta
(see the corresponding section in the Metaprogramming List Type module-level documentation), checks each element,TElement
, of thisList
to see whether it satisfiespredicate
, as if bytypename as_meta<TElement>::type{}.satisfies(predicate)
.Requirements#
predicate
must be a metapredicate invocable with the corresponding metaprogramming type of each element in thisList
. That is,func
must be aMetaPredicateOf<TFunction, typename as_meta<TElement>::type>
for each element,TElement
, of thisList
OR,
predicate
must be a metapredicate satisfiable with the corresponding metaprogramming type of each element in thisList
. That is,typename as_meta<TElement>::type{}.satisfy(predicate)
must be well formed for each element,TElement
, of thisList
Example#
static_assert(List<const int, const double, const float>{}.any_of(is_const)); static_assert(List<int, const double, float>{}.any_of(is_const)); static_assert(not List<int, double, float>{}.any_of(is_const)); static_assert(not List<Value<1>, Value<2>, Value<3>>{}.all_of(is_const));
- Template Parameters:
TPredicate – The type of the metapredicate to use
- Parameters:
predicate – The metapredicate to use
- Returns:
whether any elements satisfy
predicate
-
template<typename TPredicate>
inline constexpr auto none_of(TPredicate &&predicate) const noexcept# Returns whether zero elements of this
List
satisfy the metafunction predicatepredicate
, as aValue
specialization.Using the exposition-only template metafunction
as_meta
(see the corresponding section in the Metaprogramming List Type module-level documentation), checks each element,TElement
, of thisList
to see whether it satisfiespredicate
, as if bytypename as_meta<TElement>::type{}.satisfies(predicate)
.Requirements#
predicate
must be a metapredicate invocable with the corresponding metaprogramming type of each element in thisList
. That is,func
must be aMetaPredicateOf<TFunction, typename as_meta<TElement>::type>
for each element,TElement
, of thisList
OR,
predicate
must be a metapredicate satisfiable with the corresponding metaprogramming type of each element in thisList
. That is,typename as_meta<TElement>::type{}.satisfy(predicate)
must be well formed for each element,TElement
, of thisList
Example#
static_assert(not List<const int, const double, const float>{}.none_of(is_const)); static_assert(not List<int, const double, float>{}.none_of(is_const)); static_assert(List<int, double, float>{}.none_of(is_const)); static_assert(List<Value<1>, Value<2>, Value<3>>{}.none_of(is_const));
- Template Parameters:
TPredicate – The type of the metapredicate to use
- Parameters:
predicate – The metapredicate to use
- Returns:
whether zero elements satisfy
predicate
-
template<typename TPredicate>
inline constexpr auto index_if(TPredicate &&predicate) const noexcept# Returns the index of the first element satisfying
predicate
, as aValue
specialization orValue<sizeof...(TTypes)>
if no element satisfiespredicate
.Using the exposition-only template metafunction
as_meta
(see the corresponding section in the Metaprogramming List Type module-level documentation), checks each element,TElement
, of thisList
to see whether it satisfiespredicate
, as if bytypename as_meta<TElement>::type{}.satisfies(predicate)
, and if satisfied, returns the index of that element.Requirements#
predicate
must be a metapredicate invocable with the corresponding metaprogramming type of each element in thisList
. That is,func
must be aMetaPredicateOf<TFunction, typename as_meta<TElement>::type>
for each element,TElement
, of thisList
OR,
predicate
must be a metapredicate satisfiable with the corresponding metaprogramming type of each element in thisList
. That is,typename as_meta<TElement>::type{}.satisfy(predicate)
must be well formed for each element,TElement
, of thisList
Example#
static_assert(List<int, const double, float>{}.index_if(is_const) == 1_value); static_assert(List<int, double, const float>{}.index_if(is_const) == 2_value); static_assert(List<int, double, float>{}.index_if(is_const) == 3_value); static_assert(List<Value<1>, Value<2>, Value<3>>{}.index_if(is_const) == 3_value);
- Template Parameters:
TPredicate – The type of the metapredicate to use
- Parameters:
predicate – The metapredicate to use
- Returns:
the index of the first element to satisfy
predicate
, orsizeof...(TTypes)
if no element satisfiespredicate
-
inline constexpr auto index_of(auto value) const noexcept#
Returns the index of the first element of this
List
that is equal tovalue
, as aValue
specialization.If no element equal to
value
is found, returnsValue<sizeof...(TTypes)>
Example#
static_assert(List<int, const double, float>{}.index_of(decltype_<const double>()) == 1); static_assert(List<int, const double, float>{}.index_of(decltype_<usize>()) == 3); static_assert(List<int, const double, float>{}.index_of(1_value) == 3); static_assert(List<int, const double, float, int>{}.index_of(decltype_<int>()) == 0); static_assert(List<int, Value<1>, const double, float>{}.index_of(1_value) == 1); static_assert(List<Value<1>, Value<2>, Value<3>>{}.index_of(4_value) == 3);
- Parameters:
value – The metaprogramming value to search for
- Returns:
the index of the first element equal to
value
, orValue<sizeof...(TTypes)>
if no element equalsvalue
-
template<typename TPredicate>
inline constexpr auto filter(TPredicate &&predicate) const noexcept# Returns a
List
containing only the elements of thisList
that satisfypredicate
.Using the exposition-only template metafunction
as_meta
(see the corresponding section in the Metaprogramming List Type module-level documentation), checks each element,TElement
, of thisList
to see whether it satisfiespredicate
, as if bytypename as_meta<TElement>::type{}.satisfies(predicate)
, and if satisfied, that element is included in the returnedList
.Relative ordering of elements is maintained in the returned
List
.Requirements#
predicate
must be a metapredicate invocable with the corresponding metaprogramming type of each element in thisList
. That is,func
must be aMetaPredicateOf<TFunction, typename as_meta<TElement>::type>
for each element,TElement
, of thisList
OR,
predicate
must be a metapredicate satisfiable with the corresponding metaprogramming type of each element in thisList
. That is,typename as_meta<TElement>::type{}.satisfy(predicate)
must be well formed for each element,TElement
, of thisList
Example#
constexpr auto is_value = [](MetaValue auto val) noexcept { return Value<true>{}; }; static_assert(List<int, const double, float>{}.filter(is_const) == List<const double>{}); static_assert(List<int, double, float>{}.filter(is_const) == List<>{}); static_assert(List<int, double, const float>{}.filter(is_const) == List<const float>{}); static_assert(List<int, Value<1>, double, Value<2>, float>{}.filter(is_value) == List<Value<1>, Value<2>>{});
-
template<typename TPredicate>
inline constexpr auto remove_if(TPredicate &&predicate) const noexcept# Returns a copy of this
List
, but with all elements that satisfypredicate
removed.Using the exposition-only template metafunction
as_meta
(see the corresponding section in the Metaprogramming List Type module-level documentation), checks each element,TElement
, of thisList
to see whether it satisfiespredicate
, as if bytypename as_meta<TElement>::type{}.satisfies(predicate)
, and if satisfied, that element is not included in the returnedList
.Relative ordering of elements is maintained in the returned
List
.Requirements#
predicate
must be a metapredicate invocable with the corresponding metaprogramming type of each element in thisList
. That is,func
must be aMetaPredicateOf<TFunction, typename as_meta<TElement>::type>
for each element,TElement
, of thisList
OR,
predicate
must be a metapredicate satisfiable with the corresponding metaprogramming type of each element in thisList
. That is,typename as_meta<TElement>::type{}.satisfy(predicate)
must be well formed for each element,TElement
, of thisList
Example#
constexpr auto is_value = [](MetaValue auto val) noexcept { return Value<true>{}; }; static_assert(List<int, const double, float>{}.remove_if(is_const) == List<int, float>{}); static_assert(List<int, double, float>{}.remove_if(is_const) == List<int, double, float>{}); static_assert(List<int, double, const float>{}.remove_if(is_const) == List<int, double>{}); static_assert(List<int, Value<1>, double, Value<2>, float>{}.remove_if(is_value) == List<int, double, float>{});
- Template Parameters:
TPredicate – The type of the metapredicate to use
- Parameters:
predicate – The metapredicate to use
- Returns:
a copy of this
List
, but with all elements that satisfypredicate
removed
-
inline constexpr auto remove(auto value) const noexcept#
Returns a copy of this
List
, but with all elements that are equal tovalue
removed.Using the exposition-only template metafunction
as_meta
(see the corresponding section in the Metaprogramming List Type module-level documentation), checks each element,TElement
, of thisList
to see whether it is equal tovalue
, as if bytypename as_meta<TElement>::type{}.satisfies(equal_to(value))
, and if equal, that element is not included in the returnedList
.Relative ordering of elements is maintained in the returned
List
.Requirements#
predicate
must be a metapredicate invocable with the corresponding metaprogramming type of each element in thisList
. That is,func
must be aMetaPredicateOf<TFunction, typename as_meta<TElement>::type>
for each element,TElement
, of thisList
OR,
predicate
must be a metapredicate satisfiable with the corresponding metaprogramming type of each element in thisList
. That is,typename as_meta<TElement>::type{}.satisfy(predicate)
must be well formed for each element,TElement
, of thisList
Example#
static_assert(List<int, const double, float>{}.remove(decltype_<const double>()) == List<int, float>{}); static_assert(List<int, double, float>{}.remove(decltype_<u32>()) == List<int, double, float>{}); static_assert(List<int, double, const float>{}.remove(decltype_<const float>()) == List<int, double>{}); static_assert(List<int, Value<1>, double, Value<2>, float>{}.remove(1_value) == List<int, double, Value<2>, float>{});
- Template Parameters:
TPredicate – The type of the metapredicate to use
- Parameters:
predicate – The metapredicate to use
- Returns:
a copy of this
List
, but with all elements that are equal tovalue
removed
-
template<template<typename...> typename TList, typename ...TValues>
inline constexpr auto sift(TList<TValues...> list) const noexcept# Returns a
List
containing the elements of thisList
occurring at the indices specified inlist
.Ordering of elements in the returned list follows ordering of indices specified in
list
.Requirements#
Example#
constexpr auto sifter = List<Value<1>, Value<2>>{}; static_assert(List<int, const double, float>{}.sift(sifter) == List<const double, float>{}); static_assert(List<int, double, float>{}.sift(sifter) == List<double, float>{}); static_assert(List<int, Value<1>, double, Value<2>, float>{}.sift(sifter) == List<Value<1>, double>{});
- Template Parameters:
TList – The metaprogramming list class template
TValues – The metaprogramming value types stored in
list
- Parameters:
list – The metaprogramming list containing the indices of the elements of this
List
to get- Returns:
a
List
containing the elements of thisList
occurring at the indices specified inlist
-
template<typename TFunction>
inline constexpr auto unwrap(TFunction &&func) const noexcept -> std::invoke_result_t<TFunction, as_meta<TTypes>...># Converts the elements of this list into a parameter pack, and invokes
func
with that pack, returning the result of the invocation.Requirements#
func
must be invocable with the elements of thisList
as a parameter pack. That is, using the exposition-only template metafunctionas_meta
(see the corresponding section in the Metaprogramming List Type module-level documentation),std::invoke(std::forward<TFunction>(func), typename as_meta<TTypes>::type{}...)
must be well-formed
Example#
constexpr auto sum = [](MetaValue auto... values) noexcept { return (values + ...); }; static_assert(List<Value<1>, Value<2>, Value<3>>{}.unwrap(sum) == 6);
-
template<usize TIndex>
inline constexpr auto at() const noexcept# Returns the element of this
List
at indexTIndex
.Given type,
type
, being the element at indexTIndex
of thisList
, and using the exposition-only template metafunctionas_meta
(see the corresponding section in the Metaprogramming List Type module-level documentation), returns the element at indexTIndex
, converted to the correspondingmpl
metaprogramming type, as if byreturn typename as_meta<type>::type{};
Requirements#
TIndex
must be less than the size of thisList
Example#
static_assert(List<int, double, float>{}.at<0>() == decltype_<int>()); static_assert(List<int, double, float>{}.at<1>() == decltype_<double>()); static_assert(List<int, double, float>{}.at<2>() == decltype_<float>());
- Template Parameters:
TIndex – the index of the element to access
- Returns:
the element at index
TIndex
-
inline constexpr auto at(MetaValue auto index) const noexcept#
Returns the element of this
List
at index,index
.Given type,
type
, being the element at index,index
, of thisList
, and using the exposition-only template metafunctionas_meta
(see the corresponding section in the Metaprogramming List Type module-level documentation), returns the element atindex
, converted to the correspondingmpl
metaprogramming type, as if byreturn typename as_meta<type>::type{};
Requirements#
index
must be less than the size of thisList
Example#
static_assert(List<int, double, float>{}.at(0_value) == decltype_<int>()); static_assert(List<int, double, float>{}.at(1_value) == decltype_<double>()); static_assert(List<int, double, float>{}.at(2_value) == decltype_<float>());
- Parameters:
index – the index of the element to access
- Returns:
the element at index
TIndex
-
inline constexpr auto front() const noexcept#
Returns the first element of this
List
Given type,
type
, being the first element of thisList
, and using the exposition-only template metafunctionas_meta
(see the corresponding section in the Metaprogramming List Type module-level documentation), returns the first element, converted to the correspondingmpl
metaprogramming type, as if byreturn typename as_meta<type>::type{};
Example#
static_assert(List<int, double, float>{}.front() == decltype_<int>()); static_assert(List<double, int, float>{}.front() == decltype_<double>()); static_assert(List<float, double, int>{}.front() == decltype_<float>());
- Returns:
the first element of this
List
-
inline constexpr auto back() const noexcept#
Returns the last element of this
List
Given type,
type
, being the last element of thisList
, and using the exposition-only template metafunctionas_meta
(see the corresponding section in the Metaprogramming List Type module-level documentation), returns the last element, converted to the correspondingmpl
metaprogramming type, as if byreturn typename as_meta<type>::type{};
Example#
static_assert(List<float, double, int>{}.back() == decltype_<int>()); static_assert(List<int, float, double>{}.back() == decltype_<double>()); static_assert(List<int, double, float>{}.back() == decltype_<float>());
- Returns:
the last element of this
List
-
inline constexpr auto push_front(MetaType auto type) const noexcept#
Returns a copy of this
List
, withtype
prepended to the beginning of theList
.Using the exposition-only template metafunction
as_raw
(see the corresponding section in the Metaprogramming List Type module-level documentation), returns aList
containingtypename as_raw<decltype(type)>::type, TTypes...
.Example#
static_assert(List<float, double, int>{}.push_front(decltype_<int>()) == List<int, float, double, int>{}); static_assert(List<float, double, int>{}.push_front(decltype_<float>()) == List<float, float, double, int>{}); static_assert(List<float, double, int>{}.push_front(decltype_usize>()) == List<usize, float, double, int>{});
-
inline constexpr auto push_front(MetaValue auto value) const noexcept#
Returns a copy of this
List
, withvalue
prepended to the beginning of theList
.Using the exposition-only template metafunction
as_raw
(see the corresponding section in the Metaprogramming List Type module-level documentation), returns aList
containingtypename as_raw<decltype(value)>::type, TTypes...
.Example#
static_assert(List<float, double, int>{}.push_front(1_value) == List<Value<1>, float, double, int>{}); static_assert(List<float, double, int>{}.push_front(2_value) == List<Value<2>, float, double, int>{}); static_assert(List<float, double, int>{}.push_front(3_value) == List<Value<3>, float, double, int>{});
-
inline constexpr auto push_front(MetaPair auto pair) const noexcept#
Returns a copy of this
List
, withpair
prepended to the beginning of theList
.Using the exposition-only template metafunction
as_raw
(see the corresponding section in the Metaprogramming List Type module-level documentation), returns aList
containingtypename as_raw<decltype(pair)>::type, TTypes...
.Example#
static_assert(List<float, double, int>{}.push_front(Pair<int, double>{}) == List<Pair<int, double>, float, double, int>{}); static_assert(List<float, double, int>{}.push_front(Pair<Value<1>, float>{}) == List<Pair<Value<1>, float>, float, double, int>{}); static_assert(List<float, double, int>{}.push_front(Pair<usize, void>{}) == List<Pair<usize, void>, float, double, int>{});
-
template<typename ...TOthers>
inline constexpr auto push_front(List<TOthers...> list) const noexcept -> List<TOthers..., TTypes...># Returns a copy of this
List
, with the elements oflist
prepended to the beginning of theList
.Using the exposition-only template metafunction
as_raw
(see the corresponding section in the Metaprogramming List Type module-level documentation), returns aList
containingTOthers..., TTypes...
.Example#
static_assert(List<float, double, int>{}.push_front(List<Value<1>, int, double>{}) == List<Value<1>, int, double, float, double, int>{}); static_assert(List<float, double, int>{}.push_front(List<usize, Pair<i32, f32>, i64>{}) == List<usize, Pair<i32, f32>, i64, float, double, int>{}); static_assert(List<float, double, int>{}.push_front(List<i64, f64, Value<2>>{}) == List<i64, f64, Value<2>, float, double, int>{});
-
inline constexpr auto push_back(MetaType auto type) const noexcept#
Returns a copy of this
List
, withtype
appended to the end of theList
.Using the exposition-only template metafunction
as_raw
(see the corresponding section in the Metaprogramming List Type module-level documentation), returns aList
containingTTypes..., typename as_raw<decltype(type)>::type
.Example#
static_assert(List<float, double, int>{}.push_back(decltype_<int>()) == List<float, double, int, int>{}); static_assert(List<float, double, int>{}.push_back(decltype_<float>()) == List<float, double, int, float>{}); static_assert(List<float, double, int>{}.push_back(decltype_usize>()) == List<float, double, int, usize>{});
-
inline constexpr auto push_back(MetaValue auto value) const noexcept#
Returns a copy of this
List
, withvalue
appended to the end of theList
.Using the exposition-only template metafunction
as_raw
(see the corresponding section in the Metaprogramming List Type module-level documentation), returns aList
containingTTypes..., typename as_raw<decltype(value)>::type
.Example#
static_assert(List<float, double, int>{}.push_back(1_value) == List<float, double, int, Value<1>>{}); static_assert(List<float, double, int>{}.push_back(2_value) == List<float, double, int, Value<2>>{}); static_assert(List<float, double, int>{}.push_back(3_value) == List<float, double, int, Value<3>>{});
-
inline constexpr auto push_back(MetaPair auto pair) const noexcept#
Returns a copy of this
List
, withpair
appended to the end of theList
.Using the exposition-only template metafunction
as_raw
(see the corresponding section in the Metaprogramming List Type module-level documentation), returns aList
containingTTypes..., typename as_raw<decltype(pair)>::type
.Example#
static_assert(List<float, double, int>{}.push_back(Pair<int, double>{}) == List<float, double, int, Pair<int, double>>{}); static_assert(List<float, double, int>{}.push_back(Pair<Value<1>, float>{}) == List<float, double, int, Pair<Value<1>, float>>{}); static_assert(List<float, double, int>{}.push_back(Pair<usize, i32>{}) == List<float, double, int, Pair<usize, i32>>{});
-
template<typename ...TOthers>
inline constexpr auto push_back(List<TOthers...> list) const noexcept -> List<TTypes..., TOthers...># Returns a copy of this
List
, with the elements oflist
appended to the end of theList
.Using the exposition-only template metafunction
as_raw
(see the corresponding section in the Metaprogramming List Type module-level documentation), returns aList
containingTTypes..., TOthers...
.Example#
static_assert(List<float, double, int>{}.push_back(List<Value<1>, int, double>{}) == List<float, double, int, Value<1>, int, double>{}); static_assert(List<float, double, int>{}.push_back(List<usize, Pair<i32, f32>, i64>{}) == List<float, double, int, usize, Pair<i32, f32>, i64>{}); static_assert(List<float, double, int>{}.push_back(List<i64, f64, Value<2>>{}) == List<float, double, int, i64, f64, Value<2>>{});
-
inline constexpr auto pop_front() const noexcept#
Returns a copy of this
List
with the first element removed.- Returns:
a copy of this
List
with the first element removed
-
inline constexpr auto pop_back() const noexcept#
Returns a copy of this
List
with the last element removed.- Returns:
a copy of this
List
with the last element removed
-
template<typename ...TRHTypes>
inline constexpr auto zip(List<TRHTypes...> rhs) const noexcept# Converts the elements of this
List
andrhs
into a single list ofPair
s of elements.Returns a
List
ofPair
s of elements, created as if byList<Pair<this->at(0), rhs.at(0)>, Pair<this->at(1), rhs.at(1)>, ..., Pair<this->at(this->size() - 1), rhs.at(rhs.size() - 1)>>{}
Requirements#
this
List
andrhs
must be the same size
Example#
static_assert(List<int, double>{}.zip(List<u32, u64>{}) == List<Pair<int, u32>, Pair<double, u64>>{});