3 Defines operators for Orderables.
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)
10 #ifndef BOOST_HANA_DETAIL_OPERATORS_ORDERABLE_HPP
11 #define BOOST_HANA_DETAIL_OPERATORS_ORDERABLE_HPP
13 #include <boost/hana/config.hpp>
14 #include <boost/hana/core/tag_of.hpp>
15 #include <boost/hana/fwd/greater.hpp>
16 #include <boost/hana/fwd/greater_equal.hpp>
17 #include <boost/hana/fwd/less.hpp>
18 #include <boost/hana/fwd/less_equal.hpp>
20 #include <type_traits>
23 BOOST_HANA_NAMESPACE_BEGIN namespace detail {
24 template <typename Tag>
25 struct orderable_operators {
26 static constexpr bool value = false;
30 template <typename X, typename Y, typename = typename std::enable_if<
31 detail::orderable_operators<typename hana::tag_of<X>::type>::value ||
32 detail::orderable_operators<typename hana::tag_of<Y>::type>::value
34 constexpr auto operator<(X&& x, Y&& y)
35 { return hana::less(static_cast<X&&>(x), static_cast<Y&&>(y)); }
37 template <typename X, typename Y, typename = typename std::enable_if<
38 detail::orderable_operators<typename hana::tag_of<X>::type>::value ||
39 detail::orderable_operators<typename hana::tag_of<Y>::type>::value
41 constexpr auto operator>(X&& x, Y&& y)
42 { return hana::greater(static_cast<X&&>(x), static_cast<Y&&>(y)); }
44 template <typename X, typename Y, typename = typename std::enable_if<
45 detail::orderable_operators<typename hana::tag_of<X>::type>::value ||
46 detail::orderable_operators<typename hana::tag_of<Y>::type>::value
48 constexpr auto operator<=(X&& x, Y&& y)
49 { return hana::less_equal(static_cast<X&&>(x), static_cast<Y&&>(y)); }
51 template <typename X, typename Y, typename = typename std::enable_if<
52 detail::orderable_operators<typename hana::tag_of<X>::type>::value ||
53 detail::orderable_operators<typename hana::tag_of<Y>::type>::value
55 constexpr auto operator>=(X&& x, Y&& y)
56 { return hana::greater_equal(static_cast<X&&>(x), static_cast<Y&&>(y)); }
57 } // end namespace operators
58 } BOOST_HANA_NAMESPACE_END
60 #endif // !BOOST_HANA_DETAIL_OPERATORS_ORDERABLE_HPP