• 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_AUTO_NONE_OF_HPP
6 #define BOOST_HANA_TEST_AUTO_NONE_OF_HPP
7 
8 #include <boost/hana/assert.hpp>
9 #include <boost/hana/bool.hpp>
10 #include <boost/hana/equal.hpp>
11 #include <boost/hana/none_of.hpp>
12 #include <boost/hana/not.hpp>
13 
14 #include "test_case.hpp"
15 #include <laws/base.hpp>
16 
17 
__anone8e107fc0102null18 TestCase test_none_of{[]{
19     namespace hana = boost::hana;
20     using hana::test::ct_eq;
21 
22     BOOST_HANA_CONSTANT_CHECK(hana::none_of(
23         MAKE_TUPLE(),
24         [](auto) { return hana::false_c; }
25     ));
26 
27     BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::none_of(
28         MAKE_TUPLE(ct_eq<0>{}),
29         [](auto) { return hana::true_c; }
30     )));
31     BOOST_HANA_CONSTANT_CHECK(hana::none_of(
32         MAKE_TUPLE(ct_eq<0>{}),
33         [](auto) { return hana::false_c; }
34     ));
35     BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::none_of(
36         MAKE_TUPLE(ct_eq<0>{}),
37         hana::equal.to(ct_eq<0>{})
38     )));
39     BOOST_HANA_CONSTANT_CHECK(hana::none_of(
40         MAKE_TUPLE(ct_eq<0>{}),
41         hana::equal.to(ct_eq<999>{})
42     ));
43 
44     BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::none_of(
45         MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}),
46         hana::equal.to(ct_eq<0>{})
47     )));
48     BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::none_of(
49         MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}),
50         hana::equal.to(ct_eq<1>{})
51     )));
52     BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::none_of(
53         MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}),
54         hana::equal.to(ct_eq<2>{})
55     )));
56     BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::none_of(
57         MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}),
58         hana::equal.to(ct_eq<3>{})
59     )));
60     BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::none_of(
61         MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}),
62         hana::equal.to(ct_eq<4>{})
63     )));
64     BOOST_HANA_CONSTANT_CHECK(hana::none_of(
65         MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}),
66         hana::equal.to(ct_eq<999>{})
67     ));
68 
69     // Make sure `none_of` short-circuits with runtime predicates
70     // See http://stackoverflow.com/q/42012512/627587
71     {
72         {
73             int counter = 0;
74             auto tuple = MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{});
75             hana::none_of(tuple, [&](auto) { ++counter; return true; });
76             BOOST_HANA_RUNTIME_CHECK(counter == 1);
77         }
78         {
79             int counter = 0;
80             auto tuple = MAKE_TUPLE(ct_eq<999>{}, ct_eq<0>{}, ct_eq<999>{});
81             hana::none_of(tuple, [&](auto x) -> bool {
82                 ++counter;
83                 return hana::equal(x, ct_eq<0>{});
84             });
85             BOOST_HANA_RUNTIME_CHECK(counter == 2);
86         }
87     }
88 }};
89 
90 #endif // !BOOST_HANA_TEST_AUTO_NONE_OF_HPP
91