Drake
Drake C++ Documentation
SortedPair< T > Struct Template Reference

Detailed Description

template<class T>
struct drake::SortedPair< T >

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).

Template Parameters
TA 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)
 

Constructor & Destructor Documentation

◆ SortedPair() [1/4]

The default constructor creates first() and second() using T's default constructor, iff T has a default constructor.

Otherwise, this constructor is not available.

◆ SortedPair() [2/4]

SortedPair ( T &&  a,
T &&  b 
)

Rvalue reference constructor, permits constructing with std::unique_ptr types, for example.

◆ SortedPair() [3/4]

SortedPair ( const T &  a,
const T &  b 
)

Constructs a SortedPair from two objects.

◆ SortedPair() [4/4]

SortedPair ( SortedPair< U > &&  u)

Type-converting copy constructor.

Member Function Documentation

◆ first()

const T& first ( ) const

Gets the first (according to operator<) of the objects.

◆ get()

const T& get ( ) const

◆ second()

const T& second ( ) const

Gets the second (according to operator<) of the objects.

◆ set()

void set ( U &&  a,
U &&  b 
)

Resets the stored objects.

◆ Swap()

void Swap ( drake::SortedPair< T > &  t)

Swaps this and t.

Friends And Related Function Documentation

◆ get

const T& get ( const SortedPair< T > &  self)
friend

◆ hash_append

void hash_append ( HashAlgorithm &  hasher,
const SortedPair< T > &  p 
)
friend

Implements the hash_append generic hashing concept.


The documentation for this struct was generated from the following file: