This class is similar to the std::pair class.
However, this class uses a pair of homogeneous types (std::pair can use heterogeneous types) and sorts the first and second values such that the first value is less than or equal to the second one). Note that the sort is a stable one. Thus the SortedPair class is able to be used to generate keys (e.g., for std::map, etc.) from pairs of objects.
The availability of construction and assignment operations (i.e., default constructor, copy constructor, copy assignment, move constructor, move assignment) is the same as whatever T provides . All comparison operations (including equality, etc.) are always available.
To format this class for logging, include <fmt/ranges.h>
(exactly the same as for std::pair
).
T | A template type that provides operator< . |
#include <drake/common/sorted_pair.h>
Public Member Functions | |
SortedPair () | |
The default constructor creates first() and second() using T's default constructor, iff T has a default constructor. More... | |
SortedPair (T &&a, T &&b) | |
Rvalue reference constructor, permits constructing with std::unique_ptr types, for example. More... | |
SortedPair (const T &a, const T &b) | |
Constructs a SortedPair from two objects. More... | |
template<class U > | |
SortedPair (SortedPair< U > &&u) | |
Type-converting copy constructor. More... | |
template<class U > | |
void | set (U &&a, U &&b) |
Resets the stored objects. More... | |
const T & | first () const |
Gets the first (according to operator< ) of the objects. More... | |
const T & | second () const |
Gets the second (according to operator< ) of the objects. More... | |
void | Swap (drake::SortedPair< T > &t) |
Swaps this and t . More... | |
Friends | |
template<class HashAlgorithm > | |
void | hash_append (HashAlgorithm &hasher, const SortedPair &p) noexcept |
Implements the hash_append generic hashing concept. More... | |
Support for using SortedPair in structured bindings. | |
template<size_t Index> | |
const T & | get () const |
template<std::size_t Index> | |
const T & | get (const SortedPair< T > &self) |
SortedPair | ( | ) |
SortedPair | ( | T && | a, |
T && | b | ||
) |
Rvalue reference constructor, permits constructing with std::unique_ptr types, for example.
SortedPair | ( | const T & | a, |
const T & | b | ||
) |
Constructs a SortedPair from two objects.
SortedPair | ( | SortedPair< U > && | u | ) |
Type-converting copy constructor.
const T& first | ( | ) | const |
Gets the first (according to operator<
) of the objects.
const T& get | ( | ) | const |
const T& second | ( | ) | const |
Gets the second (according to operator<
) of the objects.
void set | ( | U && | a, |
U && | b | ||
) |
Resets the stored objects.
void Swap | ( | drake::SortedPair< T > & | t | ) |
Swaps this
and t
.
|
friend |
|
friend |
Implements the hash_append generic hashing concept.