The class is defined as:
| 1 2 3 4 5 6 7 8 9 10 11 12 |
|
Members
- first_type, second_type
- Alises of template parameters T1 and T2 respectively.
- first, second
- Data members containing the first and second values stored in the pair.
- pair()
- Constructs a pair object with each of its members first and second constructed with their respective default constructors.
- pair(const T1& x, const T2& y)
- Constructs a pair object with its members first and second initialized to x and y, respectively.
- template <class U, class V> pair (const pair<U,V> &p)
- Constructs a pair object with its members first and second initialized to the corresponding elements in p, which must be of any couple of implicitly-convertible types (including the same types).
Global operators
The header <utility> also overloads the relational operators ==, <, !=, >, >= and <= , so as to be able to compare pair objects of the same type directly:Two pair objects are compared equal if the first elements in both objects compare equal to each other and both second elements compare equal to each other - they all have to match.
In inequality comparisons (<, >), only the first element is compared, except if both first elements compare equal to each other, in this case only the second element is taken into consideration for the comparison operation.
Example
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
Output:
The price of tomatoes is $3.25 The price of lightbulbs is $0.99 The price of shoes is $20 |
See also
| make_pair | Construct pair object (function template) |
