• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)
4 
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;
10 
11 
function()12 void function() { }
function_index(...)13 void function_index(...) { }
14 
main()15 int main() {
16     // times member function
17     {
18         int counter = 0;
19         hana::int_c<3>.times([&] { ++counter; });
20         BOOST_HANA_RUNTIME_CHECK(counter == 3);
21 
22         // Call .times with a normal function used to fail.
23         hana::int_c<3>.times(function);
24 
25         // make sure times can be accessed as a static member function too
26         decltype(hana::int_c<5>)::times([]{ });
27 
28         // make sure xxx.times can be used as a function object
29         auto z = hana::int_c<5>.times;
30         (void)z;
31     }
32 
33     // times.with_index
34     {
35         int index = 0;
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);
39             ++index;
40         });
41 
42         // Calling .times.with_index with a normal function used to fail.
43         hana::int_c<3>.times.with_index(function_index);
44 
45         // make sure times.with_index can be accessed as a static member
46         // function too
47         auto times = hana::int_c<5>.times;
48         decltype(times)::with_index([](auto) { });
49 
50         // make sure xxx.times.with_index can be used as a function object
51         auto z = hana::int_c<5>.times.with_index;
52         (void)z;
53 
54         // make sure we're calling the function in the right order
55         int current = 0;
56         hana::int_c<5>.times.with_index([&](auto i) {
57             BOOST_HANA_RUNTIME_CHECK(hana::value(i) == current);
58             ++current;
59         });
60     }
61 }
62