]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*! |
2 | @file | |
3 | Defines concepts from the Standard library. | |
4 | ||
5 | @copyright Louis Dionne 2013-2016 | |
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_CONCEPTS_HPP | |
11 | #define BOOST_HANA_DETAIL_CONCEPTS_HPP | |
12 | ||
13 | #include <boost/hana/config.hpp> | |
14 | #include <boost/hana/detail/std_common_type.hpp> | |
15 | #include <boost/hana/detail/void_t.hpp> | |
16 | ||
17 | #include <type_traits> | |
18 | ||
19 | ||
20 | BOOST_HANA_NAMESPACE_BEGIN namespace detail { | |
21 | //! @cond | |
22 | ////////////////////////////////////////////////////////////////////////// | |
23 | // EqualityComparable | |
24 | ////////////////////////////////////////////////////////////////////////// | |
25 | template <typename T, typename U = T, typename = void> | |
26 | struct EqualityComparable : std::false_type { }; | |
27 | ||
28 | template <typename T> | |
29 | struct EqualityComparable<T, T, detail::void_t< | |
30 | decltype(static_cast<T&&>(*(T*)0) == static_cast<T&&>(*(T*)0) ? 0:0), | |
31 | decltype(static_cast<T&&>(*(T*)0) != static_cast<T&&>(*(T*)0) ? 0:0) | |
32 | >> : std::true_type { }; | |
33 | ||
34 | template <typename T, typename U> | |
35 | struct EqualityComparable<T, U, typename std::enable_if< | |
36 | !std::is_same<T, U>::value, detail::void_t< | |
37 | decltype(static_cast<T&&>(*(T*)0) == static_cast<U&&>(*(U*)0) ? 0:0), | |
38 | decltype(static_cast<U&&>(*(U*)0) == static_cast<T&&>(*(T*)0) ? 0:0), | |
39 | decltype(static_cast<T&&>(*(T*)0) != static_cast<U&&>(*(U*)0) ? 0:0), | |
40 | decltype(static_cast<U&&>(*(U*)0) != static_cast<T&&>(*(T*)0) ? 0:0), | |
41 | typename detail::std_common_type<T, U>::type | |
42 | >>::type> : std::integral_constant<bool, | |
43 | EqualityComparable<T>::value && | |
44 | EqualityComparable<U>::value && | |
45 | EqualityComparable<typename detail::std_common_type<T, U>::type>::value | |
46 | > { }; | |
47 | ||
48 | ||
49 | ////////////////////////////////////////////////////////////////////////// | |
50 | // LessThanComparable | |
51 | ////////////////////////////////////////////////////////////////////////// | |
52 | template <typename T, typename U = T, typename = void> | |
53 | struct LessThanComparable : std::false_type { }; | |
54 | ||
55 | template <typename T> | |
56 | struct LessThanComparable<T, T, detail::void_t< | |
57 | decltype(static_cast<T&&>(*(T*)0) < static_cast<T&&>(*(T*)0) ? 0:0) | |
58 | >> : std::true_type { }; | |
59 | ||
60 | template <typename T, typename U> | |
61 | struct LessThanComparable<T, U, std::enable_if_t< | |
62 | !std::is_same<T, U>::value, | |
63 | detail::void_t< | |
64 | decltype(static_cast<T&&>(*(T*)0) < static_cast<U&&>(*(U*)0) ? 0:0), | |
65 | decltype(static_cast<U&&>(*(U*)0) < static_cast<T&&>(*(T*)0) ? 0:0), | |
66 | typename detail::std_common_type<T, U>::type | |
67 | > | |
68 | >> | |
69 | : std::integral_constant<bool, | |
70 | LessThanComparable<T>::value && | |
71 | LessThanComparable<U>::value && | |
72 | LessThanComparable<typename detail::std_common_type<T, U>::type>::value | |
73 | > | |
74 | { }; | |
75 | //! @endcond | |
76 | } BOOST_HANA_NAMESPACE_END | |
77 | ||
78 | #endif // !BOOST_HANA_DETAIL_CONCEPTS_HPP |