]>
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_right.hpp> | |
8 | #include <boost/hana/tuple.hpp> | |
9 | namespace hana = boost::hana; | |
10 | ||
11 | // | |
12 | // Make sure that we can fold_right 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& one = hana::fold_right(xs, state, [](int& i, int&) -> int& { | |
22 | return i; | |
23 | }); | |
24 | BOOST_HANA_RUNTIME_CHECK(one == 1); | |
25 | one = 10; | |
26 | BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(xs) == 10); | |
27 | } | |
28 | ||
29 | // without state | |
30 | { | |
31 | auto xs = hana::make_tuple(1, 2, 3); | |
32 | int& one = hana::fold_right(xs, [](int& i, int&) -> int& { | |
33 | return i; | |
34 | }); | |
35 | BOOST_HANA_RUNTIME_CHECK(one == 1); | |
36 | one = 10; | |
37 | BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(xs) == 10); | |
38 | } | |
39 | } |