rippled
Loading...
Searching...
No Matches
comparators.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_BASICS_COMPARATORS_H_INCLUDED
21#define RIPPLE_BASICS_COMPARATORS_H_INCLUDED
22
23#include <functional>
24
25namespace ripple {
26
27#ifdef _MSC_VER
28
29/*
30 * MSVC 2019 version 16.9.0 added [[nodiscard]] to the std comparison
31 * operator() functions. boost::bimap checks that the comparitor is a
32 * BinaryFunction, in part by calling the function and ignoring the value.
33 * These two things don't play well together. These wrapper classes simply
34 * strip [[nodiscard]] from operator() for use in boost::bimap.
35 *
36 * See also:
37 * https://www.boost.org/doc/libs/1_75_0/libs/bimap/doc/html/boost_bimap/the_tutorial/controlling_collection_types.html
38 */
39
40template <class T = void>
41struct less
42{
43 using result_type = bool;
44
45 constexpr bool
46 operator()(T const& left, T const& right) const
47 {
48 return std::less<T>()(left, right);
49 }
50};
51
52template <class T = void>
54{
55 using result_type = bool;
56
57 constexpr bool
58 operator()(T const& left, T const& right) const
59 {
60 return std::equal_to<T>()(left, right);
61 }
62};
63
64#else
65
66template <class T = void>
67using less = std::less<T>;
68
69template <class T = void>
70using equal_to = std::equal_to<T>;
71
72#endif
73
74} // namespace ripple
75
76#endif
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
constexpr bool operator()(T const &left, T const &right) const
Definition comparators.h:58
constexpr bool operator()(T const &left, T const &right) const
Definition comparators.h:46