Definition

Defined in the standard header utility, and in the nonstandard backward-compatibility header function.h.

Requirements on types

The requirement for operator!= is that x == y is a valid expression for objects x and y of type T.

The requirement for operator> is that y < x is a valid expression for objects x and y of type T.

The requirement for operator<= is that y < x is a valid expression for objects x and y of type T.

The requirement for operator>= is that x < y is a valid expression for objects x and y of type T.

Preconditions

The precondition for operator!= is that x and y are in the domain of operator==.

The precondition for operator>, operator<=, and operator>= is that x and y are in the domain of operator<.

Example

template <class T>

void relations(T x, T y) {

 if (x == y) assert(!(x != y));

 else assert(x != y);

 if (x < y) {

  assert(x <= y);

  assert(y > x);

  assert(y >= x);

 } else if (y < x) {

  assert(y <= x);

  assert(x < y);

  assert(x <= y);

 } else {

  assert(x <= y);

  assert(x >= y);

 }

}

See also

Equality Comparable, LessThan Comparable

Classes

pair<T1, T2>

Category: utilities

Component type: type

Description

Pair<T1,T2> is a heterogeneous pair: it holds one object of type T1 and one of type T2. A pair is much like a Container, in that it 'owns' its elements. It is not actually a model of Container, though, because it does not support the standard methods (such as iterators) for accessing the elements of a Container.

Functions that need to return two values often return a pair.

Example

pair<bool, double> result = do_a_calculation();

if (result.first) do_something_more(result.second);

else report_error();

Definition

Defined in the standard header utility, and in the nonstandard backward-compatibility header pair.h.

Template parameters
Parameter Description
T1 The type of the first element stored in the pair
T2 The type of the second element stored in the pair
Model of

Assignable

Type requirements

T1 and T2 must both be models of Assignable. Additional operations have additional requirements. Pair's default constructor may only be used if both T1 and T2 are DefaultConstructible, operator== may only be used if both T1 and T2 are EqualityComparable, and operator< may only be used if both T1 and T2 are LessThanComparable.

Public base classes

None.

Members
Member Where defined Description
Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату