• 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/concept/struct.hpp>
7 #include <boost/hana/equal.hpp>
8 #include <boost/hana/fold_right.hpp>
9 #include <boost/hana/integral_constant.hpp>
10 
11 #include "minimal_struct.hpp"
12 #include <laws/base.hpp>
13 #include <support/minimal_product.hpp>
14 namespace hana = boost::hana;
15 using hana::test::ct_eq;
16 
17 
18 template <int i = 0>
19 struct undefined { };
20 
21 struct MoveOnly {
22     MoveOnly()                           = default;
23     MoveOnly(MoveOnly&&)                 = default;
24     MoveOnly(MoveOnly const&)            = delete;
25     MoveOnly& operator=(MoveOnly&&)      = default;
26     MoveOnly& operator=(MoveOnly const&) = delete;
27 };
28 
main()29 int main() {
30     constexpr auto pair = ::minimal_product;
31     ct_eq<999> s{};
32     hana::test::_injection<0> f{};
33 
34     BOOST_HANA_CONSTANT_CHECK(hana::equal(
35         hana::fold_right(obj(), s, undefined<>{}),
36         s
37     ));
38 
39     BOOST_HANA_CONSTANT_CHECK(hana::equal(
40         hana::fold_right(obj(ct_eq<0>{}), s, f),
41         f(pair(hana::int_c<0>, ct_eq<0>{}), s)
42     ));
43 
44     BOOST_HANA_CONSTANT_CHECK(hana::equal(
45         hana::fold_right(obj(ct_eq<0>{}, ct_eq<1>{}), s, f),
46         f(pair(hana::int_c<0>, ct_eq<0>{}), f(pair(hana::int_c<1>, ct_eq<1>{}), s))
47     ));
48 
49     BOOST_HANA_CONSTANT_CHECK(hana::equal(
50         hana::fold_right(obj(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), s, f),
51         f(pair(hana::int_c<0>, ct_eq<0>{}),
52             f(pair(hana::int_c<1>, ct_eq<1>{}),
53                 f(pair(hana::int_c<2>, ct_eq<2>{}), s)))
54     ));
55 
56     // fold_right with move-only members
57     hana::fold_right(obj(MoveOnly{}), 0, [](auto, int) { return 0; });
58     hana::fold_right(obj(MoveOnly{}, MoveOnly{}), 0, [](auto, int) { return 0; });
59 }
60