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)
6 * See http://www.boost.org/libs/poly_collection for library home page.
9 #ifndef BOOST_POLY_COLLECTION_DETAIL_IS_EQUALITY_COMPARABLE_HPP
10 #define BOOST_POLY_COLLECTION_DETAIL_IS_EQUALITY_COMPARABLE_HPP
16 #include <boost/config.hpp>
17 #include <type_traits>
19 #if !defined(BOOST_NO_SFINAE_EXPR)
22 #include <boost/poly_collection/detail/is_likely_stateless_lambda.hpp>
23 #include <boost/type_traits/has_equal_to.hpp>
28 namespace poly_collection{
32 #if !defined(BOOST_NO_SFINAE_EXPR)
34 /* trivial, expression SFINAE-based implementation */
36 template<typename T,typename=void>
37 struct is_equality_comparable:std::false_type{};
40 struct is_equality_comparable<
42 typename std::enable_if<
44 decltype(std::declval<T>()==std::declval<T>()),bool
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.
59 template<typename T,typename=void>
60 struct is_equality_comparable:std::integral_constant<
62 has_equal_to<T,T,bool>::value
66 struct is_equality_comparable<
68 typename std::enable_if<is_likely_stateless_lambda<T>::value>::type
70 #if !defined(BOOST_MSVC)
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
83 } /* namespace poly_collection::detail */
85 } /* namespace poly_collection */
87 } /* namespace boost */