MCPcopy Create free account
hub / github.com/boostorg/hana / main

Function main

example/misc/restricted_function.cpp:110–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

108}} // end namespace boost::hana
109
110int main() {
111 auto f = function(hana::make_set(1_c, 2_c, 3_c), hana::make_set(1_c, 2_c, 3_c, 4_c, 5_c, 6_c))(
112 [](auto x) { return x + 1_c; }
113 );
114
115 auto g = function(hana::make_set(1_c, 2_c, 3_c), hana::make_set(2_c, 3_c, 4_c))(
116 [](auto x) { return x + 1_c; }
117 );
118
119 auto h = function(hana::make_set(1_c, 2_c, 3_c), hana::make_set(0_c, 1_c, 2_c))(
120 [](auto x) { return x - 1_c; }
121 );
122
123 BOOST_HANA_CONSTANT_CHECK(f == g);
124 BOOST_HANA_CONSTANT_CHECK(f != h);
125 BOOST_HANA_CONSTANT_CHECK(f(1_c) == 2_c);
126
127 BOOST_HANA_CONSTANT_CHECK(range(f) == hana::make_set(4_c, 3_c, 2_c));
128 BOOST_HANA_CONSTANT_CHECK(range(g) == hana::make_set(2_c, 3_c, 4_c));
129 BOOST_HANA_CONSTANT_CHECK(range(h) == hana::make_set(0_c, 1_c, 2_c));
130
131 BOOST_HANA_CONSTANT_CHECK(hana::not_(is_onto(f)));
132 BOOST_HANA_CONSTANT_CHECK(is_onto(g));
133 BOOST_HANA_CONSTANT_CHECK(is_onto(h));
134
135 auto even = function(hana::make_set(1_c, 2_c, 3_c), hana::make_set(hana::true_c, hana::false_c))(
136 [](auto x) { return x % 2_c == 0_c; }
137 );
138
139 BOOST_HANA_CONSTANT_CHECK(is_injective(f));
140 BOOST_HANA_CONSTANT_CHECK(is_injective(g));
141 BOOST_HANA_CONSTANT_CHECK(is_injective(h));
142 BOOST_HANA_CONSTANT_CHECK(hana::not_(is_injective(even)));
143}

Callers

nothing calls this directly

Calls 5

is_ontoFunction · 0.85
is_injectiveFunction · 0.85
rangeFunction · 0.70
functionFunction · 0.50
fClass · 0.50

Tested by

no test coverage detected