1 /*=============================================================================
2 Copyright (c) 2015 Paul Fultz II
3 and.h
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 ==============================================================================*/
7
8 #ifndef BOOST_HOF_GUARD_AND_H
9 #define BOOST_HOF_GUARD_AND_H
10
11 #include <type_traits>
12 #include <boost/hof/detail/using.hpp>
13 #include <boost/hof/detail/intrinsics.hpp>
14
15 namespace boost { namespace hof { namespace detail {
16
and_c()17 constexpr bool and_c()
18 {
19 return true;
20 }
21
22 template<class... Ts>
and_c(bool b,Ts...bs)23 constexpr bool and_c(bool b, Ts... bs)
24 {
25 return b && and_c(bs...);
26 }
27
28 #ifdef _MSC_VER
29
30 template<class... Ts>
31 struct and_;
32
33 template<class T, class... Ts>
34 struct and_<T, Ts...>
35 : std::integral_constant<bool, (T::value && and_<Ts...>::value)>
36 {};
37
38 template<>
39 struct and_<>
40 : std::true_type
41 {};
42
43 #define BOOST_HOF_AND_UNPACK(Bs) (boost::hof::detail::and_c(Bs...))
44 #else
45 template<bool...> struct bool_seq {};
46 template<class... Ts>
47 BOOST_HOF_USING(and_, std::is_same<bool_seq<Ts::value...>, bool_seq<(Ts::value, true)...>>);
48
49 #define BOOST_HOF_AND_UNPACK(Bs) BOOST_HOF_IS_BASE_OF(boost::hof::detail::bool_seq<Bs...>, boost::hof::detail::bool_seq<(Bs || true)...>)
50
51 #endif
52
53 }}} // namespace boost::hof
54
55 #endif
56