]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/test/integral_constant/times.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/core/is_a.hpp>
7 #include <boost/hana/integral_constant.hpp>
8 #include <boost/hana/value.hpp>
9 namespace hana
= boost::hana
;
13 void function_index(...) { }
16 // times member function
19 hana::int_c
<3>.times([&] { ++counter
; });
20 BOOST_HANA_RUNTIME_CHECK(counter
== 3);
22 // Call .times with a normal function used to fail.
23 hana::int_c
<3>.times(function
);
25 // make sure times can be accessed as a static member function too
26 decltype(hana::int_c
<5>)::times([]{ });
28 // make sure xxx.times can be used as a function object
29 auto z
= hana::int_c
<5>.times
;
36 hana::int_c
<3>.times
.with_index([&](auto i
) {
37 static_assert(hana::is_an
<hana::integral_constant_tag
<int>>(i
), "");
38 BOOST_HANA_RUNTIME_CHECK(hana::value(i
) == index
);
42 // Calling .times.with_index with a normal function used to fail.
43 hana::int_c
<3>.times
.with_index(function_index
);
45 // make sure times.with_index can be accessed as a static member
47 auto times
= hana::int_c
<5>.times
;
48 decltype(times
)::with_index([](auto) { });
50 // make sure xxx.times.with_index can be used as a function object
51 auto z
= hana::int_c
<5>.times
.with_index
;
54 // make sure we're calling the function in the right order
56 hana::int_c
<5>.times
.with_index([&](auto i
) {
57 BOOST_HANA_RUNTIME_CHECK(hana::value(i
) == current
);