| 1 | /*============================================================================= |
| 2 | Copyright (c) 2016 Lee Clagett |
| 3 | Copyright (c) 2018 Kohei Takahashi |
| 4 | |
| 5 | Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 6 | file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 7 | ==============================================================================*/ |
| 8 | #ifndef FUSION_AND_07152016_1625 |
| 9 | #define FUSION_AND_07152016_1625 |
| 10 | |
| 11 | #include <boost/config.hpp> |
| 12 | #include <boost/config/workaround.hpp> |
| 13 | #include <boost/type_traits/integral_constant.hpp> |
| 14 | |
| 15 | #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) |
| 16 | #error fusion::detail::and_ requires variadic templates |
| 17 | #endif |
| 18 | |
| 19 | namespace boost { namespace fusion { namespace detail { |
| 20 | #if defined(BOOST_NO_CXX17_FOLD_EXPRESSIONS) \ |
| 21 | || BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1913)) |
| 22 | template<typename ...Cond> |
| 23 | struct and_impl : false_type {}; |
| 24 | |
| 25 | template<typename ...T> |
| 26 | struct and_impl<integral_constant<T, true>...> : true_type {}; |
| 27 | |
| 28 | // This specialization is necessary to avoid MSVC-12 variadics bug. |
| 29 | template<bool ...Cond> |
| 30 | struct and_impl1 : and_impl<integral_constant<bool, Cond>...> {}; |
| 31 | |
| 32 | /* fusion::detail::and_ differs from mpl::and_ in the following ways: |
| 33 | - The empty set is valid and returns true |
| 34 | - A single element set is valid and returns the identity |
| 35 | - There is no upper bound on the set size |
| 36 | - The conditions are evaluated at once, and are not short-circuited. This |
| 37 | reduces instantations when returning true; the implementation is not |
| 38 | recursive. */ |
| 39 | template<typename ...Cond> |
| 40 | struct and_ : and_impl1<Cond::value...> {}; |
| 41 | #else |
| 42 | template <typename ...Cond> |
| 43 | struct and_ : integral_constant<bool, ((bool)Cond::value && ...)> {}; |
| 44 | #endif |
| 45 | }}} |
| 46 | |
| 47 | #endif // FUSION_AND_07152016_1625 |
| 48 | |