The class template pair provides a pair of public data members, first and second, of type T1 and T2 respectively. If either T1 or T2 uses bslma::Allocator for memory management, then provide an optional bslma::Allocator argument for each constructor, to be passed through to the constructors of first and/or second as appropriate. The interface to this class is identical to the standard std::pair except for the addition of the allocators. Note that the implementation of this class provides first and second through multiple base classes in order to simplify construction of each member when allowing for the various rules for passing allocators in C++11.

Synopsis

Declared in <bslstl_pair.h>

template<
    class T1,
    class T2>
class pair
    : public Pair_First<T1>
    , public Pair_Second<T2>

Base Classes

Name

Description

Pair_First<T1>

This component‐private class holds the first data member of a pair and constructs it appropriately. Note the partial specializations below for the cases that (template parameter) 'TYPE' is a reference.

Pair_Second<T2>

This component‐private class holds the second data member of a pair and constructs it appropriately. Note the partial specializations below for the cases that (template parameter) 'TYPE' is a reference.

Type Aliases

Name

Description

first_type

This typedef is an alias to the type of the first data member.

second_type

This typedef is an alias to the type of the second data member.

Member Functions

Name

Description

pair [constructor]

Constructors

operator=

Assignment operators

swap

Swap the value of this pair with the value of the specified other pair by applying swap to each of the first and second pair fields.

operator std::tuple<PARAM_1&, PARAM_2&>

Return an std::tuple object, holding references that provide modifiable access to the members of this object.

operator std::tuple<PARAM_1&, decltype(std::ignore)&>

This overload of `template <class PARAM_1, class PARAM_2> operator std::tuple<PARAM_1&, PARAM_2&>()` is called when the (template parameter) PARAM_2 (second element's type) is the type of std::ignore.

operator std::tuple<decltype(std::ignore)&, PARAM_2&>

This overload of `template <class PARAM_1, class PARAM_2> operator std::tuple<PARAM_1&, PARAM_2&>()` is called when the (template parameter) PARAM_1 (first element's type) is the type of std::ignore.

operator std::tuple<decltype(std::ignore)&, decltype(std::ignore)&>

This overload of `template <class PARAM_1, class PARAM_2> operator std::tuple<PARAM_1&, PARAM_2&>()` is called when the (template parameters) PARAM_1 (first element's type) and PARAM_2 (second element's type) are the type of std::ignore. Note that this method is defined within the class body intentionally to avoid build failure on MSVC 2015.

Using Declarations

Name

first

second

Protected Data Members

Name

Description

first

First element of the pair.

second

Second element of the pair.

Deduction Guides

Name

Description

pair<T1, T2>

Deduce the specified types T1 and T2 from the corresponding template parameters of the std::pair supplied to the constructor of pair.

pair<T1, T2>

Deduce the specified types T1 and T2 from the corresponding types supplied to the constructor of pair.

pair<T1, T2>

Deduce the specified types T1 and T2 from the corresponding template parameters of the bsl::pair supplied to the constructor of pair. This guide does not participate in deduction unless the specified ALLOC inherits from bslma::Allocator.

pair<T1, T2>

Deduce the specified types T1 and T2 from the corresponding template parameters of the std::pair supplied to the constructor of pair. This guide does not participate in deduction unless the specified ALLOC inherits from bslma::Allocator.

pair<T1, T2>

Deduce the specified types T1 and T2 from the corresponding types supplied to the constructor of pair. This guide does not participate in deduction unless the specified ALLOC inherits from bslma::Allocator.

Non-Member Functions

Name

Description

get

Return a reference providing modifiable access to the element of the specified p, having the ordinal number specified by the (template parameter) INDEX. This function will not compile unless the INDEX is either 0 or 1.

get

Return a rvalue reference providing non‐modifiable access to the element of the specified p, having the (template parameter) TYPE. This function will not compile unless the types T1 and T2 are different and the TYPE is the same as either T1 or T2.

get

Return a reference providing non‐modifiable access to the element of the specified p, having the ordinal number specified by the (template parameter) INDEX. This function will not compile unless the INDEX is either 0 or 1.

get

Return a reference providing non‐modifiable access to the element of the specified p, having the (template parameter) TYPE. This function will not compile unless the types T1 and T2 are different and the TYPE is the same as either T1 or T2.

get

Return a reference providing modifiable access to the element of the specified p, having the (template parameter) TYPE. This function will not compile unless the types T1 and T2 are different and the TYPE is the same as either T1 or T2.

get

Return a rvalue reference providing modifiable access to the element of the specified p, having the ordinal number specified by the (template parameter) INDEX. This function will not compile unless the INDEX is either 0 or 1.

get

Return a rvalue reference providing modifiable access to the element of the specified p, having the (template parameter) TYPE. This function will not compile unless the types T1 and T2 are different and the TYPE is the same as either T1 or T2.

operator<=>

Perform a lexicographic three‐way comparison of the specified lhs and the specified rhs pairs by using the comparison operators of T1 and T2; return the result of that comparison.

operator==

Return true if the specified lhs and rhs pair objects have the same value and false otherwise. lhs has the same value as rhs if lhs.first == rhs.first and lhs.second == rhs.second. A call to this operator will not compile unless both T1 and T2 supply operator==.

swap

Swap the values of the specified a and b pairs by applying swap to each of the first and second pair fields. Note that this method is no‐throw only if swap on each field is no‐throw.

Created with MrDocs