1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
// Copyright Louis Dionne 2013-2017
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#include <boost/hana/detail/any_of.hpp>
#include <boost/hana/detail/wrong.hpp>
#include <boost/hana/integral_constant.hpp>
namespace hana = boost::hana;
template <typename I>
struct is_even {
static constexpr bool value = I::value % 2 == 0;
};
static_assert(!hana::detail::any_of<is_even>::value, "");
static_assert(!hana::detail::any_of<is_even, hana::int_<1>>::value, "");
static_assert(!hana::detail::any_of<is_even, hana::int_<1>, hana::int_<3>>::value, "");
static_assert(!hana::detail::any_of<is_even, hana::int_<1>, hana::int_<3>, hana::int_<5>>::value, "");
static_assert(!hana::detail::any_of<is_even, hana::int_<1>, hana::int_<3>, hana::int_<5>, hana::int_<7>>::value, "");
static_assert(hana::detail::any_of<is_even, hana::int_<0>>::value, "");
static_assert(hana::detail::any_of<is_even, hana::int_<0>, hana::int_<2>>::value, "");
static_assert(hana::detail::any_of<is_even, hana::int_<0>, hana::int_<2>, hana::int_<4>>::value, "");
static_assert(hana::detail::any_of<is_even, hana::int_<0>, hana::int_<2>, hana::int_<4>, hana::int_<6>>::value, "");
static_assert(hana::detail::any_of<is_even, hana::int_<0>, hana::int_<1>>::value, "");
static_assert(hana::detail::any_of<is_even, hana::int_<0>, hana::int_<1>, hana::int_<2>>::value, "");
static_assert(hana::detail::any_of<is_even, hana::int_<0>, hana::int_<1>, hana::int_<2>, hana::int_<3>>::value, "");
static_assert(hana::detail::any_of<is_even, hana::int_<0>, hana::int_<1>, hana::int_<2>, hana::int_<3>, hana::int_<4>>::value, "");
static_assert(hana::detail::any_of<is_even, hana::int_<1>, hana::int_<3>, hana::int_<5>, hana::int_<8>>::value, "");
static_assert(hana::detail::any_of<is_even, hana::int_<1>, hana::int_<8>, hana::int_<5>, hana::int_<7>>::value, "");
// Make sure we short-circuit properly
template <typename ...Dummy>
struct fail {
static_assert(hana::detail::wrong<Dummy...>::value,
"this must never be instantiated");
};
static_assert(hana::detail::any_of<is_even, hana::int_<1>, hana::int_<2>, fail<>>::value, "");
static_assert(hana::detail::any_of<is_even, hana::int_<1>, hana::int_<2>, fail<>, hana::int_<3>>::value, "");
static_assert(hana::detail::any_of<is_even, hana::int_<1>, hana::int_<2>, fail<>, hana::int_<4>>::value, "");
int main() { }
|