logical.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*!
  2. @file
  3. Defines logical operators.
  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_DETAIL_OPERATORS_LOGICAL_HPP
  9. #define BOOST_HANA_DETAIL_OPERATORS_LOGICAL_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/tag_of.hpp>
  12. #include <boost/hana/fwd/and.hpp>
  13. #include <boost/hana/fwd/not.hpp>
  14. #include <boost/hana/fwd/or.hpp>
  15. #include <type_traits>
  16. BOOST_HANA_NAMESPACE_BEGIN namespace detail {
  17. template <typename Tag>
  18. struct logical_operators {
  19. static constexpr bool value = false;
  20. };
  21. namespace operators {
  22. template <typename X, typename Y, typename = typename std::enable_if<
  23. detail::logical_operators<typename hana::tag_of<X>::type>::value ||
  24. detail::logical_operators<typename hana::tag_of<Y>::type>::value
  25. >::type>
  26. constexpr auto operator||(X&& x, Y&& y)
  27. { return hana::or_(static_cast<X&&>(x), static_cast<Y&&>(y)); }
  28. template <typename X, typename Y, typename = typename std::enable_if<
  29. detail::logical_operators<typename hana::tag_of<X>::type>::value ||
  30. detail::logical_operators<typename hana::tag_of<Y>::type>::value
  31. >::type>
  32. constexpr auto operator&&(X&& x, Y&& y)
  33. { return hana::and_(static_cast<X&&>(x), static_cast<Y&&>(y)); }
  34. template <typename X, typename = typename std::enable_if<
  35. detail::logical_operators<typename hana::tag_of<X>::type>::value
  36. >::type>
  37. constexpr auto operator!(X&& x)
  38. { return hana::not_(static_cast<X&&>(x)); }
  39. } // end namespace operators
  40. } BOOST_HANA_NAMESPACE_END
  41. #endif // !BOOST_HANA_DETAIL_OPERATORS_LOGICAL_HPP