• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*!
2 @file
3 Defines logical operators.
4 
5 @copyright Louis Dionne 2013-2017
6 Distributed under the Boost Software License, Version 1.0.
7 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
8  */
9 
10 #ifndef BOOST_HANA_DETAIL_OPERATORS_LOGICAL_HPP
11 #define BOOST_HANA_DETAIL_OPERATORS_LOGICAL_HPP
12 
13 #include <boost/hana/config.hpp>
14 #include <boost/hana/core/tag_of.hpp>
15 #include <boost/hana/fwd/and.hpp>
16 #include <boost/hana/fwd/not.hpp>
17 #include <boost/hana/fwd/or.hpp>
18 
19 #include <type_traits>
20 
21 
22 BOOST_HANA_NAMESPACE_BEGIN namespace detail {
23     template <typename Tag>
24     struct logical_operators {
25         static constexpr bool value = false;
26     };
27 
28     namespace operators {
29         template <typename X, typename Y, typename = typename std::enable_if<
30             detail::logical_operators<typename hana::tag_of<X>::type>::value ||
31             detail::logical_operators<typename hana::tag_of<Y>::type>::value
32         >::type>
operator ||(X && x,Y && y)33         constexpr auto operator||(X&& x, Y&& y)
34         { return hana::or_(static_cast<X&&>(x), static_cast<Y&&>(y)); }
35 
36         template <typename X, typename Y, typename = typename std::enable_if<
37             detail::logical_operators<typename hana::tag_of<X>::type>::value ||
38             detail::logical_operators<typename hana::tag_of<Y>::type>::value
39         >::type>
operator &&(X && x,Y && y)40         constexpr auto operator&&(X&& x, Y&& y)
41         { return hana::and_(static_cast<X&&>(x), static_cast<Y&&>(y)); }
42 
43         template <typename X, typename = typename std::enable_if<
44             detail::logical_operators<typename hana::tag_of<X>::type>::value
45         >::type>
operator !(X && x)46         constexpr auto operator!(X&& x)
47         { return hana::not_(static_cast<X&&>(x)); }
48     } // end namespace operators
49 } BOOST_HANA_NAMESPACE_END
50 
51 #endif // !BOOST_HANA_DETAIL_OPERATORS_LOGICAL_HPP
52