]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/example/while.cpp
1 // Copyright Louis Dionne 2013-2017
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
5 #include <boost/hana/assert.hpp>
6 #include <boost/hana/equal.hpp>
7 #include <boost/hana/integral_constant.hpp>
8 #include <boost/hana/less.hpp>
9 #include <boost/hana/plus.hpp>
10 #include <boost/hana/while.hpp>
13 namespace hana
= boost::hana
;
14 using namespace hana::literals
;
18 // while_ with a Constant condition (loop is unrolled at compile-time)
20 std::vector
<int> ints
;
21 auto final_state
= hana::while_(hana::less
.than(10_c
), 0_c
, [&](auto i
) {
26 // The state is known at compile-time
27 BOOST_HANA_CONSTANT_CHECK(final_state
== 10_c
);
29 BOOST_HANA_RUNTIME_CHECK(ints
== std::vector
<int>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
32 // while_ with a constexpr or runtime condition (loop is not unrolled)
34 std::vector
<int> ints
;
35 int final_state
= hana::while_(hana::less
.than(10), 0, [&](int i
) {
40 // The state is known only at runtime, or at compile-time if constexpr
41 BOOST_HANA_RUNTIME_CHECK(final_state
== 10);
43 BOOST_HANA_RUNTIME_CHECK(ints
== std::vector
<int>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9});