and.hpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*!
  2. @file
  3. Defines `boost::hana::and_`.
  4. @copyright Louis Dionne 2013-2017
  5. Distributed under the Boost Software License, Version 1.0.
  6. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  7. */
  8. #ifndef BOOST_HANA_AND_HPP
  9. #define BOOST_HANA_AND_HPP
  10. #include <boost/hana/fwd/and.hpp>
  11. #include <boost/hana/concept/logical.hpp>
  12. #include <boost/hana/config.hpp>
  13. #include <boost/hana/core/dispatch.hpp>
  14. #include <boost/hana/detail/variadic/foldl1.hpp>
  15. #include <boost/hana/if.hpp>
  16. BOOST_HANA_NAMESPACE_BEGIN
  17. //! @cond
  18. template <typename X, typename Y>
  19. constexpr decltype(auto) and_t::operator()(X&& x, Y&& y) const {
  20. using Bool = typename hana::tag_of<X>::type;
  21. using And = BOOST_HANA_DISPATCH_IF(and_impl<Bool>,
  22. hana::Logical<Bool>::value
  23. );
  24. #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
  25. static_assert(hana::Logical<Bool>::value,
  26. "hana::and_(x, y) requires 'x' to be a Logical");
  27. #endif
  28. return And::apply(static_cast<X&&>(x), static_cast<Y&&>(y));
  29. }
  30. template <typename X, typename ...Y>
  31. constexpr decltype(auto) and_t::operator()(X&& x, Y&& ...y) const {
  32. return detail::variadic::foldl1(
  33. *this,
  34. static_cast<X&&>(x),
  35. static_cast<Y&&>(y)...
  36. );
  37. }
  38. //! @endcond
  39. template <typename L, bool condition>
  40. struct and_impl<L, when<condition>> : default_ {
  41. template <typename X, typename Y>
  42. static constexpr decltype(auto) apply(X&& x, Y&& y) {
  43. return hana::if_(x, static_cast<Y&&>(y), x);
  44. }
  45. };
  46. BOOST_HANA_NAMESPACE_END
  47. #endif // !BOOST_HANA_AND_HPP