]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/poly_collection/detail/is_equality_comparable.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / poly_collection / detail / is_equality_comparable.hpp
1 /* Copyright 2017 Joaquin M Lopez Munoz.
2 * Distributed under the Boost Software License, Version 1.0.
3 * (See accompanying file LICENSE_1_0.txt or copy at
4 * http://www.boost.org/LICENSE_1_0.txt)
5 *
6 * See http://www.boost.org/libs/poly_collection for library home page.
7 */
8
9 #ifndef BOOST_POLY_COLLECTION_DETAIL_IS_EQUALITY_COMPARABLE_HPP
10 #define BOOST_POLY_COLLECTION_DETAIL_IS_EQUALITY_COMPARABLE_HPP
11
12 #if defined(_MSC_VER)
13 #pragma once
14 #endif
15
16 #include <boost/config.hpp>
17 #include <type_traits>
18
19 #if !defined(BOOST_NO_SFINAE_EXPR)
20 #include <utility>
21 #else
22 #include <boost/poly_collection/detail/is_likely_stateless_lambda.hpp>
23 #include <boost/type_traits/has_equal_to.hpp>
24 #endif
25
26 namespace boost{
27
28 namespace poly_collection{
29
30 namespace detail{
31
32 #if !defined(BOOST_NO_SFINAE_EXPR)
33
34 /* trivial, expression SFINAE-based implementation */
35
36 template<typename T,typename=void>
37 struct is_equality_comparable:std::false_type{};
38
39 template<typename T>
40 struct is_equality_comparable<
41 T,
42 typename std::enable_if<
43 std::is_convertible<
44 decltype(std::declval<T>()==std::declval<T>()),bool
45 >::value
46 >::type
47 >:std::true_type{};
48
49 #else
50 /* boost::has_equal_to does a decent job without using expression SFINAE,
51 * but it produces a compile error when the type T being checked is
52 * convertible to an equality-comparable type Q. Exotic as it may seem,
53 * this is exactly the situation with the very important case of stateless
54 * lambda expressions, which are convertible to an equality-comparable
55 * function pointer with the same signature. We take explicit care of
56 * stateless lambdas then.
57 */
58
59 template<typename T,typename=void>
60 struct is_equality_comparable:std::integral_constant<
61 bool,
62 has_equal_to<T,T,bool>::value
63 >{};
64
65 template<typename T>
66 struct is_equality_comparable<
67 T,
68 typename std::enable_if<is_likely_stateless_lambda<T>::value>::type
69 >:
70 #if !defined(BOOST_MSVC)
71 std::true_type{};
72 #else
73 /* To complicate things further, in VS stateless lambdas are convertible not
74 * only to regular function pointers, but also to other call conventions
75 * such as __stdcall, __fastcall, etc., which makes equality comparison
76 * ambiguous.
77 */
78
79 std::false_type{};
80 #endif
81 #endif
82
83 } /* namespace poly_collection::detail */
84
85 } /* namespace poly_collection */
86
87 } /* namespace boost */
88
89 #endif