hyperion::mpl#
hyperion::mpl is a C++20 metaprogramming library focused on making metaprogramming simple and easy. With hyperion::mpl, metaprogramming almost as easy as typical application code: you can metaprogram using (relatively) normal variables, values, and functions, in an ergonomic and functional style, instead of the bloat and complexity of the struct templates, partial specializations, SFINAE, and other techniques and tricks typically used in C++ metaprogramming.
See the Quick Start Guide for how to get started using hyperion::mpl.
For an overview of each module, see the links in the left sidebar or below.
1#include <hyperion/mpl/list.h>
2#include <hyperion/mpl/type.h>
3#include <hyperion/mpl/value.h>
4
5#include <concepts>
6#include <ranges>
7
8using namespace hyperion;
9using namespace hyperion::mpl;
10
11constexpr auto add_const = [](MetaType auto type) noexcept {
12 return type.as_const();
13};
14
15constexpr auto list = List<int, double, float>{};
16constexpr auto zipped = list.zip(List<u32, usize, i32>{});
17constexpr auto constified = zipped.apply(add_const);
18
19static_assert(constified == List<Pair<const int, const u32>,
20 Pair<const double, const usize>,
21 Pair<const float, const i32>>{});
22static_assert(constified.all_of(is_const));
23
24constexpr auto list2 = List<int, const double, float>{};
25// ranges support is implemented for `mpl::List` at all times,
26// but usage in practice requires a complete standard library implementation
27// for ranges. (i.e. `operator|` isn't particularly useful without the
28// `std::ranges::<things>` to go along with it)
29constexpr auto ranged
30 = list
31 | std::ranges::views::filter([](MetaType auto type) { return not type.is_const(); })
32 | std::ranges::views::transform([](MetaType auto type) {
33 return type.as_lvalue_reference().as_volatile();
34 })
35 | std::ranges::views::reverse
36 | std::ranges::views::drop(1_value);
37static_assert(ranged == List<volatile int&>{});
38
39constexpr auto add_one = [](MetaValue auto value) {
40 return value + 1_value;
41};
42constexpr auto times_two = [](MetaValue auto value) {
43 return value * 2_value;
44};
45
46static_assert(2_value
47 .apply(add_one)
48 .apply(times_two)
49 .apply(add_one) == 7);
50
51constexpr auto val3 = 10;
52static_assert(decltype_(val3)
53 .apply<std::remove_reference>()
54 .apply<std::remove_const>()
55 .apply<std::add_rvalue_reference>()
56 == decltype_<int&&>());
57
58constexpr auto add_lvalue_reference = [](MetaType auto type) {
59 return type.as_lvalue_reference();
60};
61
62constexpr auto remove_reference = [](MetaType auto type)
63 -> std::remove_reference<typename decltype(type)::type>
64{
65 return {};
66};
67
68static_assert(decltype_<int&&>()
69 .apply(remove_reference)
70 .apply(add_const)
71 .apply(add_lvalue_reference)
72 == decltype_<const int&>());
73
74constexpr auto val1 = Value<4>{};
75constexpr auto val2 = Value<2>{};
76constexpr auto meaning_of_life = (val1 * 10_value) + val2;
77static_assert(meaning_of_life == 42);
- hyperion::mpl::Value
- hyperion::mpl::Type
Type
Type::type
Type::self()
Type::inner()
Type::has_inner()
Type::apply()
Type::apply()
Type::apply()
Type::apply()
Type::satisfies()
Type::satisfies()
Type::is()
Type::is_qualification_of()
Type::is_const()
Type::is_lvalue_reference()
Type::is_rvalue_reference()
Type::is_volatile()
Type::as_const()
Type::as_lvalue_reference()
Type::as_rvalue_reference()
Type::as_volatile()
Type::is_convertible_to()
Type::is_derived_from()
Type::is_base_of()
Type::is_constructible_from()
Type::is_constructible_from()
Type::is_noexcept_constructible_from()
Type::is_noexcept_constructible_from()
Type::is_default_constructible()
Type::is_noexcept_default_constructible()
Type::is_trivially_default_constructible()
Type::is_copy_constructible()
Type::is_noexcept_copy_constructible()
Type::is_trivially_copy_constructible()
Type::is_move_constructible()
Type::is_noexcept_move_constructible()
Type::is_trivially_move_constructible()
Type::is_copy_assignable()
Type::is_noexcept_copy_assignable()
Type::is_trivially_copy_assignable()
Type::is_move_assignable()
Type::is_noexcept_move_assignable()
Type::is_trivially_move_assignable()
Type::is_destructible()
Type::is_noexcept_destructible()
Type::is_trivially_destructible()
Type::is_swappable()
Type::is_noexcept_swappable()
Type::is_swappable_with()
Type::is_noexcept_swappable_with()
Type::sizeof_()
- hyperion::mpl::List
operator==()
operator!=()
make_list()
make_list()
operator|()
not_found_tag
List
List::size()
List::is_empty()
List::apply()
List::for_each()
List::for_each_n()
List::accumulate()
List::accumulate()
List::find_if()
List::find()
List::count_if()
List::count()
List::contains()
List::all_of()
List::any_of()
List::none_of()
List::index_if()
List::index_of()
List::filter()
List::remove_if()
List::remove()
List::sift()
List::unwrap()
List::at()
List::at()
List::front()
List::back()
List::push_front()
List::push_front()
List::push_front()
List::push_front()
List::push_back()
List::push_back()
List::push_back()
List::push_back()
List::pop_front()
List::pop_back()
List::zip()
- Metaprogramming Predicate Functions
equal_to()
not_equal_to()
less_than()
less_than_or_equal_to()
greater_than()
greater_than_or_equal_to()
is()
qualification_of()
convertible_to()
derived_from()
base_of()
constructible_from()
constructible_from()
noexcept_constructible_from()
noexcept_constructible_from()
swappable_with()
noexcept_swappable_with()
is_const
is_lvalue_reference
is_rvalue_reference
is_volatile
default_constructible
noexcept_default_constructible
trivially_default_constructible
copy_constructible
noexcept_copy_constructible
trivially_copy_constructible
move_constructible
noexcept_move_constructible
trivially_move_constructible
copy_assignable
noexcept_copy_assignable
trivially_copy_assignable
move_assignable
noexcept_move_assignable
trivially_move_assignable
destructible
noexcept_destructible
trivially_destructible
swappable
noexcept_swappable
- hyperion::mpl::type_traits
- Comparison Operator Detection
three_way_compare_result_t
is_equality_comparable_v
is_inequality_comparable_v
is_less_than_comparable_v
is_less_than_or_equal_comparable_v
is_greater_than_comparable_v
is_greater_than_or_equal_comparable_v
is_three_way_comparable_v
is_equality_comparable
is_inequality_comparable
is_less_than_comparable
is_less_than_or_equal_comparable
is_greater_than_comparable
is_greater_than_or_equal_comparable
is_three_way_comparable
- General Operator Detection
unary_plus_result_t
unary_minus_result_t
binary_not_result_t
boolean_not_result_t
address_result_t
arrow_result_t
dereference_result_t
add_result_t
subtract_result_t
multiply_result_t
divide_result_t
binary_and_result_t
binary_or_result_t
boolean_and_result_t
boolean_or_result_t
is_unary_plusable_v
is_unary_minusable_v
is_binary_notable_v
is_boolean_notable_v
is_addressable_v
is_arrowable_v
is_dereferencible_v
is_addable_v
is_subtractable_v
is_multipliable_v
is_dividible_v
is_binary_andable_v
is_binary_orable_v
is_boolean_andable_v
is_boolean_orable_v
is_unary_plusable
is_unary_minusable
is_binary_notable
is_boolean_notable
is_addressable
is_arrowable
is_dereferencible
is_addable
is_subtractable
is_multipliable
is_dividible
is_binary_andable
is_binary_orable
is_boolean_andable
is_boolean_orable
- Standard Supplemental Type Traits
- Comparison Operator Detection