Include the STL standard header <utility> to define several templates of general use throughout the Standard Template Library.
Four template operators — operator!=, operator<=, operator>, and operator>= — define a total ordering on pairs of operands of the same type, given definitions of operator== and operator<.
If an implementation supports namespaces, these template operators are defined in the rel_ops namespace, nested within the std namespace. If you wish to make use of these template operators, write the declaration:
using namespace std::rel_ops;
which promotes the template operators into the current namespace.
namespace std {
template<class T, class Ty2>
struct pair;
// TEMPLATE FUNCTIONS
template<class Ty1, class Ty2>
pair<Ty, Ty2> make_pair(Ty1 val1, Ty2 val2);
template<class Ty1, class Ty2>
bool operator==(const pair<Ty, Ty2>& left,
const pair<Ty1, Ty2>& right);
template<class Ty1, class Ty2>
bool operator!=(const pairTy, Ty2>& left,
const pair<Ty1, Ty2>& right);
template<class Ty1, class Ty2>
bool operator<(const pair<Ty, Ty2>& left,
const pair<Ty1, Ty2>& right);
template<class Ty1, class Ty2>
bool operator>(const pair<Ty1, Ty2>& left,
const pair<Ty1, Ty2>& right);
template<class Ty1, class Ty2>
bool operator<=(const pair<Ty1, Ty2>& left,
const pair<Ty1, Ty2>& right);
template<class Ty1, class Ty2>
bool operator>=(const pair<Ty1, Ty2>& left,
const pair<Ty1, Ty2>& right);
namespace rel_ops {
template<class Ty>
bool operator!=(const Ty& left, const Ty& right);
template<class Ty>
bool operator<=(const Ty& left, const Ty& right);
template<class Ty>
bool operator>(const Ty& left, const Ty& right);
template<class Ty>
bool operator>=(const Ty& left, const Ty& right);
}; // namespace rel_ops
namespace tr1 { [added with (TR1)]
template<int Idx, class T1, class T2>
RI& get(pair<T1, T2>& pr);
template<int Idx, class T1, class T2>
const RI& get(const pair<T1, T2>& pr);
template<class T1, class T2>
class tuple_element<0, pair<T1, T2> >;
template<class T1, class T2>
class tuple_element<1, pair<T1, T2> >;
template<class T1, class T2>
class tuple_size<pair<T1, T2> >;
} // namespace tr1
} // namespace std
template<class Ty1, class Ty2>
struct pair {
typedef Ty1 first_type;
typedef Ty2 second_type
Ty1 first;
Ty2 second;
pair();
pair(const Ty1& val1, const Ty2& val2);
template<class Other1, class Other2>
pair(const pair<Other1, Other2>& right);
};
The template class stores a pair of objects, first, of type Ty1, and second, of type Ty2. The type definition first_type, is the same as the template parameter Ty1, while second_type, is the same as the template parameter Ty2.
The first default constructor initializes first to Ty1() and second to Ty2(). The second constructor initializes first to val1 and second to val2. The third template constructor initializes first to right.first and second to right.second. Ty1 and Ty2 each need supply only a default constructor, single-argument constructor, and a destructor.
template<class T1, class T2>
class tuple_element<0, pair<T1, T2> > {
typedef T1 type;
};
template<class T1, class T2>
class tuple_element<1, pair<T1, T2> > {
typedef T2 type;
};
[Added with TR1]
The templates are specializations of the template class tuple_element. Each has a nested typedef type that is a synonym for the type of the corresponding pair element.
template<class T1, class T2>
class tuple_size<pair<T1, T2> > {
static const unsigned value = 2;
};
[Added with TR1]
The template is a specialization of the template class tuple_size. It has a member value that is an integral constant expression whose value is 2.
template<int Idx, class T1, class T2>
RI& get(pair<T1, T2>& pr);
template<int Idx, class T1, class T2>
const RI& get(const pair<T1, T2>& pr);
[Added with TR1]
The template functions return a reference to an element of its pair argument. If the value of Idx is 0 the functions return pr.first and if the value of Idx is 1 the functions return pr.second. The type RI is the type of the returned element.
template<class Ty1, class Ty2>
pair<Ty1, Ty2> make_pair(Ty1 val1, Ty2 val2);
The template function returns pair<Ty1, Ty2>(val1, val2).
template<class Ty>
bool operator!=(const Ty& left, const Ty& right);
template<class Ty1, class Ty2>
bool operator!=(const pair<Ty1, Ty2>& left, const pair<Ty1, Ty2>& right);
The template function returns !(left == right).
template<class Ty1, class Ty2>
bool operator==(const pair<Ty1, Ty2>& left,
const pair<Ty1, Ty2>& right);
The template function returns left.first == right.first && left.second == right.second.
template<class Ty1, class Ty2>
bool operator<(const pair<Ty1, Ty2>& left,
const pair<Ty1, Ty2>& right);
The template function returns left.first < right.first || !(right.first < left.first) && left.second < right.second.
template<class Ty>
bool operator<=(const Ty& left, const Ty& right);
template<class Ty1, class Ty2>
bool operator<=(const pair<Ty1, Ty2>& left, const pair<Ty1, Ty2>& right);
The template function returns !(right < left).
template<class Ty>
bool operator>(const Ty& left, const Ty& right);
template<class Ty1, class Ty2>
bool operator>(const pair<Ty1, Ty2>& left, const pair<Ty1, Ty2>& right);
The template function returns right < left.
template<class Ty>
bool operator>=(const Ty& left, const Ty& right);
template<class Ty1, class Ty2>
bool operator>=(const pair<Ty1, Ty2>& left, const pair<Ty1, Ty2>& right);
The template function returns !(left < right).
Certain materials included or referred to in this document are copyright P.J. Plauger and/or Dinkumware, Ltd. or are based on materials that are copyright P.J. Plauger and/or Dinkumware, Ltd.
Certain materials included or referred to in this document are copyright Hewlett-Packard Company or are based on materials that are copyright Hewlett-Packard Company.
Notwithstanding the meta-data for this document, copyright information for this document is as follows:
Copyright © IBM Corp. 1999, 2010. & Copyright © P.J. Plauger and/or Dinkumware, Ltd. 1992-2006. & Copyright © 1994 Hewlett-Packard Company.