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

Function main

example/while.cpp:17–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15
16
17int main() {
18 // while_ with a Constant condition (loop is unrolled at compile-time)
19 {
20 std::vector<int> ints;
21 auto final_state = hana::while_(hana::less.than(10_c), 0_c, [&](auto i) {
22 ints.push_back(i);
23 return i + 1_c;
24 });
25
26 // The state is known at compile-time
27 BOOST_HANA_CONSTANT_CHECK(final_state == 10_c);
28
29 BOOST_HANA_RUNTIME_CHECK(ints == std::vector<int>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
30 }
31
32 // while_ with a constexpr or runtime condition (loop is not unrolled)
33 {
34 std::vector<int> ints;
35 int final_state = hana::while_(hana::less.than(10), 0, [&](int i) {
36 ints.push_back(i);
37 return i + 1;
38 });
39
40 // The state is known only at runtime, or at compile-time if constexpr
41 BOOST_HANA_RUNTIME_CHECK(final_state == 10);
42
43 BOOST_HANA_RUNTIME_CHECK(ints == std::vector<int>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
44 }
45}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected