and.hpp 1.8 KB

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