• 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 #ifndef BOOST_HANA_TEST_LAWS_SEQUENCE_HPP
6 #define BOOST_HANA_TEST_LAWS_SEQUENCE_HPP
7 
8 #include <boost/hana/assert.hpp>
9 #include <boost/hana/concept/sequence.hpp>
10 #include <boost/hana/config.hpp>
11 #include <boost/hana/core/tag_of.hpp>
12 #include <boost/hana/functional/capture.hpp>
13 #include <boost/hana/functional/compose.hpp>
14 #include <boost/hana/functional/id.hpp>
15 #include <boost/hana/functional/partial.hpp>
16 #include <boost/hana/integral_constant.hpp>
17 #include <boost/hana/optional.hpp>
18 #include <boost/hana/plus.hpp>
19 #include <boost/hana/range.hpp>
20 #include <boost/hana/tuple.hpp>
21 
22 #include <laws/base.hpp>
23 #include <support/minimal_product.hpp>
24 #include <support/seq.hpp>
25 
26 #include <type_traits>
27 #include <vector>
28 
29 
30 namespace boost { namespace hana { namespace test {
31     template <typename S, typename = when<true>>
32     struct TestSequence : TestSequence<S, laws> {
33         using TestSequence<S, laws>::TestSequence;
34     };
35 
36     template <typename S>
37     struct TestSequence<S, laws> {
38         template <int i>
39         using eq = integer<i,
40               Policy::Comparable
41             | Policy::Constant
42         >;
43 
44         template <int i>
45         using cx_eq = integer<i,
46               Policy::Comparable
47             | Policy::Constexpr
48         >;
49 
50         template <int i>
51         using ord = integer<i,
52               Policy::Orderable
53             | Policy::Constant
54         >;
55 
56         struct undefined { };
57 
TestSequenceboost::hana::test::TestSequence58         TestSequence() {
59             constexpr auto list = make<S>; (void)list;
60             constexpr auto foldable = ::seq; (void)foldable;
61 
62             //////////////////////////////////////////////////////////////////
63             // Check for Sequence<...>
64             //////////////////////////////////////////////////////////////////
65             static_assert(Sequence<decltype(list())>{}, "");
66             static_assert(Sequence<decltype(list(1))>{}, "");
67             static_assert(Sequence<decltype(list(1, '2'))>{}, "");
68             static_assert(Sequence<decltype(list(1, '2', 3.4))>{}, "");
69 
70             //////////////////////////////////////////////////////////////////
71             // Check for basic tag consistency
72             //////////////////////////////////////////////////////////////////
73             struct Random;
74             static_assert(std::is_same<tag_of_t<decltype(list())>, S>{}, "");
75             static_assert(std::is_same<tag_of_t<decltype(list(1))>, S>{}, "");
76             static_assert(std::is_same<tag_of_t<decltype(list(1, '2'))>, S>{}, "");
77             static_assert(std::is_same<tag_of_t<decltype(list(1, '2', 3.3))>, S>{}, "");
78             static_assert(!std::is_same<tag_of_t<Random>, S>{}, "");
79 
80             //////////////////////////////////////////////////////////////////
81             // Foldable -> Sequence conversion
82             //////////////////////////////////////////////////////////////////
83             {
84                 BOOST_HANA_CONSTANT_CHECK(equal(
85                     to<S>(foldable()),
86                     list()
87                 ));
88                 BOOST_HANA_CONSTANT_CHECK(equal(
89                     to<S>(foldable(eq<0>{})),
90                     list(eq<0>{})
91                 ));
92                 BOOST_HANA_CONSTANT_CHECK(equal(
93                     to<S>(foldable(eq<0>{}, eq<1>{})),
94                     list(eq<0>{}, eq<1>{})
95                 ));
96                 BOOST_HANA_CONSTANT_CHECK(equal(
97                     to<S>(foldable(eq<0>{}, eq<1>{}, eq<2>{})),
98                     list(eq<0>{}, eq<1>{}, eq<2>{})
99                 ));
100                 BOOST_HANA_CONSTANT_CHECK(equal(
101                     to<S>(foldable(eq<0>{}, eq<1>{}, eq<2>{}, eq<3>{})),
102                     list(eq<0>{}, eq<1>{}, eq<2>{}, eq<3>{})
103                 ));
104             }
105 
106             //////////////////////////////////////////////////////////////////
107             // make (tautological given our definition of `list`)
108             //////////////////////////////////////////////////////////////////
109             BOOST_HANA_CONSTANT_CHECK(equal(
110                 make<S>(),
111                 list()
112             ));
113             BOOST_HANA_CONSTANT_CHECK(equal(
114                 make<S>(eq<0>{}),
115                 list(eq<0>{})
116             ));
117             BOOST_HANA_CONSTANT_CHECK(equal(
118                 make<S>(eq<0>{}, eq<1>{}),
119                 list(eq<0>{}, eq<1>{})
120             ));
121             BOOST_HANA_CONSTANT_CHECK(equal(
122                 make<S>(eq<0>{}, eq<1>{}, eq<2>{}),
123                 list(eq<0>{}, eq<1>{}, eq<2>{})
124             ));
125             BOOST_HANA_CONSTANT_CHECK(equal(
126                 make<S>(eq<0>{}, eq<1>{}, eq<2>{}, eq<3>{}),
127                 list(eq<0>{}, eq<1>{}, eq<2>{}, eq<3>{})
128             ));
129         }
130     };
131 }}} // end namespace boost::hana::test
132 
133 #endif // !BOOST_HANA_TEST_LAWS_SEQUENCE_HPP
134