📄 utility.html
字号:
<HTML><HEAD><TITLE><utility></TITLE></HEAD><BODY><H1><A NAME="<utility>"><CODE><utility></CODE></A></H1><HR><P>Include the <A HREF="index.html#STL">STL</A>standard header <B><CODE><utility></CODE></B>to define several templates of general usethroughout the Standard Template Library.</P><P>Four template operators --<CODE>operator!=</CODE>,<CODE>operator<=</CODE>,<CODE>operator></CODE>, and<CODE>operator>=</CODE> -- define a<B><A NAME="total ordering">total ordering</A></B>on pairs of operands of the same type, given definitions of<CODE>operator==</CODE> and <CODE>operator<</CODE>.<P>If an <A HREF="index.html#implementation">implementation</A>supports namespaces,these template operators are defined in the<B><CODE><A NAME="rel_ops">rel_ops</A></CODE></B> namespace,nested within the <CODE>std</CODE> namespace.If you wish to make use of these template operators,write the declaration:</P><PRE>using namespace std::rel_ops;</PRE><P>which promotes the template operators into the current namespace.</P><PRE>namespace std {template<class T, class Ty2> struct <B><A HREF="#pair">pair</A></B>; // TEMPLATE FUNCTIONStemplate<class Ty1, class Ty2> pair<Ty, Ty2> <B><A HREF="#make_pair">make_pair</A></B>(Ty1 val1, Ty2 val2);template<class Ty1, class Ty2> bool <B><A HREF="#operator==">operator==</A></B>(const pair<Ty, Ty2>& left, const pair<Ty1, Ty2>& right);template<class Ty1, class Ty2> bool <B><A HREF="#operator!=">operator!=</A></B>(const pair<Ty, Ty2>& left, const pair<Ty1, Ty2>& right);template<class Ty1, class Ty2> bool <B><A HREF="#operator<">operator<</A></B>(const pair<Ty, Ty2>& left, const pair<Ty1, Ty2>& right);template<class Ty1, class Ty2> bool <B><A HREF="#operator>">operator></A></B>(const pair<Ty1, Ty2>& left, const pair<Ty1, Ty2>& right);template<class Ty1, class Ty2> bool <B><A HREF="#operator<=">operator<=</A></B>(const pair<Ty1, Ty2>& left, const pair<Ty1, Ty2>& right);template<class Ty1, class Ty2> bool <B><A HREF="#operator>=">operator>=</A></B>(const pair<Ty1, Ty2>& left, const pair<Ty1, Ty2>& right);namespace rel_ops { template<class Ty> bool <B><A HREF="#operator!=">operator!=</A></B>(const Ty& left, const Ty& right); template<class Ty> bool <B><A HREF="#operator<=">operator<=</A></B>(const Ty& left, const Ty& right); template<class Ty> bool <B><A HREF="#operator>">operator></A></B>(const Ty& left, const Ty& right); template<class Ty> bool <B><A HREF="#operator>=">operator>=</A></B>(const Ty& left, const Ty& right); }; };</PRE><H2><A NAME="make_pair"><CODE>make_pair</CODE></A></H2><PRE>template<class Ty1, class Ty2> pair<Ty1, Ty2> <B>make_pair</B>(Ty1 val1, Ty2 val2);</PRE><P>The template function returns<CODE><A HREF="#pair">pair</A><Ty1, Ty2>(val1, val2)</CODE>.</P><H2><A NAME="operator!="><CODE>operator!=</CODE></A></H2><PRE>template<class Ty> bool <B>operator!=</B>(const Ty& left, const Ty& right);template<class Ty1, class Ty2> bool <B>operator!=</B>(const pair<Ty1, Ty2>& left, const pair<Ty1, Ty2>& right);</PRE><P>The template function returns <CODE>!(left == right)</CODE>.</P><H2><A NAME="operator=="><CODE>operator==</CODE></A></H2><PRE>template<class Ty1, class Ty2> bool <B>operator==</B>(const pair<Ty1, Ty2>& left, const pair<Ty1, Ty2>& right);</PRE><P>The template function returns<CODE>left.<A HREF="#pair::first">first</A> == right.first &&left.<A HREF="#pair::second">second</A> == right.second</CODE>.</P><H2><A NAME="operator<"><CODE>operator<</CODE></A></H2><PRE>template<class Ty1, class Ty2> bool <B>operator<</B>(const pair<Ty1, Ty2>& left, const pair<Ty1, Ty2>& right);</PRE><P>The template function returns<CODE>left.<A HREF="#pair::first">first</A> < right.first ||!(right.first < left.first &&left.<A HREF="#pair::second">second</A> < right.second)</CODE>.</P><H2><A NAME="operator<="><CODE>operator<=</CODE></A></H2><PRE>template<class Ty> bool <B>operator<=</B>(const Ty& left, const Ty& right);template<class Ty1, class Ty2> bool <B>operator<=</B>(const pair<Ty1, Ty2>& left, const pair<Ty1, Ty2>& right);</PRE><P>The template function returns <CODE>!(right < left)</CODE>.</P><H2><A NAME="operator>"><CODE>operator></CODE></A></H2><PRE>template<class Ty> bool <B>operator></B>(const Ty& left, const Ty& right);template<class Ty1, class Ty2> bool <B>operator></B>(const pair<Ty1, Ty2>& left, const pair<Ty1, Ty2>& right);</PRE><P>The template function returns <CODE>right < left</CODE>.</P><H2><A NAME="operator>="><CODE>operator>=</CODE></A></H2><PRE>template<class Ty> bool <B>operator>=</B>(const Ty& left, const Ty& right);template<class Ty1, class Ty2> bool <B>operator>=</B>(const pair<Ty1, Ty2>& left, const pair<Ty1, Ty2>& right);</PRE><P>The template function returns <CODE>!(left < right)</CODE>.</P><H2><A NAME="pair"><CODE>pair</CODE></A></H2><PRE>template<class Ty1, class Ty2> struct <B>pair</B> { typedef Ty1 <B>first_type</B>; typedef Ty2 <B>second_type</B> Ty1 <B>first</B>; Ty2 <B>second</B>; <B>pair</B>(); <B>pair</B>(const Ty1& val1, const Ty2& val2); template<class Other1, class Other2> pair(const pair<Other1, Other2>& right); };</PRE><P>The template class stores a pair of objects,<B><A NAME="pair::first"><CODE>first</CODE></A></B>,of type <CODE>Ty1</CODE>, and<B><A NAME="pair::second"><CODE>second</CODE></A></B>,of type <CODE>Ty2</CODE>. The type definition<B><A NAME="pair::first_type"><CODE>first_type</CODE></A></B>,is the same as the template parameter <CODE>Ty1</CODE>, while<B><A NAME="pair::second_type"><CODE>second_type</CODE></A></B>,is the same as the template parameter <CODE>Ty2</CODE>.</P><P>The first (default) constructor initializes<CODE>first</CODE> to <CODE>Ty1()</CODE> and <CODE>second</CODE>to <CODE>Ty2()</CODE>. The second constructor initializes<CODE>first</CODE> to <CODE>val1</CODE> and <CODE>second</CODE>to <CODE>val2</CODE>. The third (template) constructor initializes<CODE>first</CODE> to <CODE>right.first</CODE> and <CODE>second</CODE>to <CODE>right.second</CODE>. <CODE>Ty1</CODE> and <CODE>Ty2</CODE> eachneed supply only a default constructor, single-argument constructor,and a destructor.</P><HR><P>See also the<B><A HREF="index.html#Table of Contents">Table of Contents</A></B> and the<B><A HREF="_index.html">Index</A></B>.</P><P><I><A HREF="crit_pjp.html">Copyright</A> © 1994-2002by P.J. Plauger. Portions derived from work<A HREF="crit_hp.html">copyright</A> © 1994by Hewlett-Packard Company. All rights reserved.</I></P><!--V4.01:1125--></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -