]>
Commit | Line | Data |
---|---|---|
b32b8144 | 1 | // Copyright Louis Dionne 2013-2017 |
7c673cae FG |
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/at.hpp> | |
7 | #include <boost/hana/fold_left.hpp> | |
8 | #include <boost/hana/tuple.hpp> | |
9 | namespace hana = boost::hana; | |
10 | ||
11 | // | |
12 | // Make sure that we can fold_left and take arguments by reference. | |
13 | // | |
14 | ||
15 | int main() { | |
16 | // with state | |
17 | { | |
18 | auto xs = hana::make_tuple(1, 2, 3); | |
19 | int state = 99; | |
20 | ||
21 | int& three = hana::fold_left(xs, state, [](int&, int& i) -> int& { | |
22 | return i; | |
23 | }); | |
24 | BOOST_HANA_RUNTIME_CHECK(three == 3); | |
25 | three = 10; | |
26 | BOOST_HANA_RUNTIME_CHECK(hana::at_c<2>(xs) == 10); | |
27 | } | |
28 | ||
29 | // without state | |
30 | { | |
31 | auto xs = hana::make_tuple(1, 2, 3); | |
32 | ||
33 | int& three = hana::fold_left(xs, [](int&, int& i) -> int& { | |
34 | return i; | |
35 | }); | |
36 | BOOST_HANA_RUNTIME_CHECK(three == 3); | |
37 | three = 10; | |
38 | BOOST_HANA_RUNTIME_CHECK(hana::at_c<2>(xs) == 10); | |
39 | } | |
40 | } |