]>
Commit | Line | Data |
---|---|---|
92f5a8d4 TL |
1 | // Copyright 2015-2019 Hans Dembinski |
2 | // | |
3 | // Distributed under the Boost Software License, Version 1.0. | |
4 | // (See accompanying file LICENSE_1_0.txt | |
5 | // or copy at http://www.boost.org/LICENSE_1_0.txt) | |
6 | ||
7 | #ifndef BOOST_HISTOGRAM_DETAIL_RELAXED_EQUAL_HPP | |
8 | #define BOOST_HISTOGRAM_DETAIL_RELAXED_EQUAL_HPP | |
9 | ||
20effc67 TL |
10 | #include <boost/histogram/detail/priority.hpp> |
11 | #include <type_traits> | |
92f5a8d4 TL |
12 | |
13 | namespace boost { | |
14 | namespace histogram { | |
15 | namespace detail { | |
16 | ||
20effc67 TL |
17 | struct relaxed_equal { |
18 | template <class T, class U> | |
19 | constexpr auto impl(const T& t, const U& u, priority<1>) const noexcept | |
20 | -> decltype(t == u) const { | |
21 | return t == u; | |
22 | } | |
23 | ||
24 | // consider T and U not equal, if there is no operator== defined for them | |
25 | template <class T, class U> | |
26 | constexpr bool impl(const T&, const U&, priority<0>) const noexcept { | |
27 | return false; | |
28 | } | |
29 | ||
30 | // consider two T equal if they are stateless | |
31 | template <class T> | |
32 | constexpr bool impl(const T&, const T&, priority<0>) const noexcept { | |
33 | return std::is_empty<T>::value; | |
34 | } | |
35 | ||
36 | template <class T, class U> | |
37 | constexpr bool operator()(const T& t, const U& u) const noexcept { | |
38 | return impl(t, u, priority<1>{}); | |
39 | } | |
40 | }; | |
92f5a8d4 TL |
41 | |
42 | } // namespace detail | |
43 | } // namespace histogram | |
44 | } // namespace boost | |
45 | ||
46 | #endif |