and.hpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. #ifndef BOOST_HOF_GUARD_AND_H
  8. #define BOOST_HOF_GUARD_AND_H
  9. #include <type_traits>
  10. #include <boost/hof/detail/using.hpp>
  11. #include <boost/hof/detail/intrinsics.hpp>
  12. namespace boost { namespace hof { namespace detail {
  13. constexpr bool and_c()
  14. {
  15. return true;
  16. }
  17. template<class... Ts>
  18. constexpr bool and_c(bool b, Ts... bs)
  19. {
  20. return b && and_c(bs...);
  21. }
  22. #ifdef _MSC_VER
  23. template<class... Ts>
  24. struct and_;
  25. template<class T, class... Ts>
  26. struct and_<T, Ts...>
  27. : std::integral_constant<bool, (T::value && and_<Ts...>::value)>
  28. {};
  29. template<>
  30. struct and_<>
  31. : std::true_type
  32. {};
  33. #define BOOST_HOF_AND_UNPACK(Bs) (boost::hof::detail::and_c(Bs...))
  34. #else
  35. template<bool...> struct bool_seq {};
  36. template<class... Ts>
  37. BOOST_HOF_USING(and_, std::is_same<bool_seq<Ts::value...>, bool_seq<(Ts::value, true)...>>);
  38. #define BOOST_HOF_AND_UNPACK(Bs) BOOST_HOF_IS_BASE_OF(boost::hof::detail::bool_seq<Bs...>, boost::hof::detail::bool_seq<(Bs || true)...>)
  39. #endif
  40. }}} // namespace boost::hof
  41. #endif