📄 functio2.html
字号:
<HTML><HEAD><TITLE><functional></TITLE></HEAD><BODY><H1><A NAME="<functional>"><CODE><functional></CODE></A></H1><HR><P><B><CODE><A HREF="#binary_function">binary_function</A>· <A HREF="#binary_negate">binary_negate</A>· <A HREF="#binder1st">binder1st</A>· <A HREF="#binder2nd">binder2nd</A>· <A HREF="#const_mem_fun_t">const_mem_fun_t</A>· <A HREF="#const_mem_fun_ref_t">const_mem_fun_ref_t</A>· <A HREF="#const_mem_fun1_t">const_mem_fun1_t</A>· <A HREF="#const_mem_fun1_ref_t">const_mem_fun1_ref_t</A>· <A HREF="#divides">divides</A>· <A HREF="#equal_to">equal_to</A>· <A HREF="#greater">greater</A>· <A HREF="#greater_equal">greater_equal</A>· <A HREF="#less">less</A>· <A HREF="#less_equal">less_equal</A>· <A HREF="#logical_and">logical_and</A>· <A HREF="#logical_not">logical_not</A>· <A HREF="#logical_or">logical_or</A>· <A HREF="#mem_fun_t">mem_fun_t</A>· <A HREF="#mem_fun_ref_t">mem_fun_ref_t</A>· <A HREF="#mem_fun1_t">mem_fun1_t</A>· <A HREF="#mem_fun1_ref_t">mem_fun1_ref_t</A>· <A HREF="#minus">minus</A>· <A HREF="#modulus">modulus</A>· <A HREF="#multiplies">multiplies</A>· <A HREF="#negate">negate</A>· <A HREF="#not_equal_to">not_equal_to</A>· <A HREF="#plus">plus</A>· <A HREF="#pointer_to_binary_function">pointer_to_binary_function</A>· <A HREF="#pointer_to_unary_function">pointer_to_unary_function</A>· <A HREF="#unary_function">unary_function</A>· <A HREF="#unary_negate">unary_negate</A></CODE></B></P><P><B><CODE><A HREF="#bind1st">bind1st</A>· <A HREF="#bind2nd">bind2nd</A>· <A HREF="#mem_fun">mem_fun</A>· <A HREF="#mem_fun_ref">mem_fun_ref</A>· <A HREF="#not1">not1</A>· <A HREF="#not2">not2</A>· <A HREF="#ptr_fun">ptr_fun</A></CODE></B></P><HR><P>Include the <A HREF="index.html#STL">STL</A>standard header <B><CODE><functional></CODE></B>to define several templates that help construct<B><A NAME="function objects">function objects</A></B>,objects of a type that defines <CODE>operator()</CODE>.A function object can thus be a function pointer, but inthe more general case the object can store additional informationthat can be used during a function call.</P><PRE>namespace std {template<class Arg, class Result> struct <B><A HREF="#unary_function">unary_function</A></B>;template<class Arg1, class Arg2, class Result> struct <B><A HREF="#binary_function">binary_function</A></B>;template<class Ty> struct <B><A HREF="#plus">plus</A></B>;template<class Ty> struct <B><A HREF="#minus">minus</A></B>;template<class Ty> struct <B><A HREF="#multiplies">multiplies</A></B>;template<class Ty> struct <B><A HREF="#divides">divides</A></B>;template<class Ty> struct <B><A HREF="#modulus">modulus</A></B>;template<class Ty> struct <B><A HREF="#negate">negate</A></B>;template<class Ty> struct <B><A HREF="#equal_to">equal_to</A></B>;template<class Ty> struct <B><A HREF="#not_equal_to">not_equal_to</A></B>;template<class Ty> struct <B><A HREF="#greater">greater</A></B>;template<class Ty> struct <B><A HREF="#less">less</A></B>;template<class Ty> struct <B><A HREF="#greater_equal">greater_equal</A></B>;template<class Ty> struct <B><A HREF="#less_equal">less_equal</A></B>;template<class Ty> struct <B><A HREF="#logical_and">logical_and</A></B>;template<class Ty> struct <B><A HREF="#logical_or">logical_or</A></B>;template<class Ty> struct <B><A HREF="#logical_not">logical_not</A></B>;template<class Fn1> struct <B><A HREF="#unary_negate">unary_negate</A></B>;template<class Fn2> struct <B><A HREF="#binary_negate">binary_negate</A></B>;template<class Fn2> class <B><A HREF="#binder1st">binder1st</A></B>;template<class Fn2> class <B><A HREF="#binder2nd">binder2nd</A></B>;template<class Arg, class Result> class <B><A HREF="#pointer_to_unary_function">pointer_to_unary_function</A></B>;template<class Arg1, class Arg2, class Result> class <B><A HREF="#pointer_to_binary_function">pointer_to_binary_function</A></B>;template<class Result, class Ty> struct <B><A HREF="#mem_fun_t">mem_fun_t</A></B>;template<class Result, class Ty, class Arg> struct <B><A HREF="#mem_fun1_t">mem_fun1_t</A></B>;template<class Result, class Ty> struct <B><A HREF="#const_mem_fun_t">const_mem_fun_t</A></B>;template<class Result, class Ty, class Arg> struct <B><A HREF="#const_mem_fun1_t">const_mem_fun1_t</A></B>;template<class Result, class Ty> struct <B><A HREF="#mem_fun_ref_t">mem_fun_ref_t</A></B>;template<class Result, class Ty, class Arg> struct <B><A HREF="#mem_fun1_ref_t">mem_fun1_ref_t</A></B>;template<class Result, class Ty> struct <B><A HREF="#const_mem_fun_ref_t">const_mem_fun_ref_t</A></B>;template<class Result, class Ty, class Arg> struct <B><A HREF="#const_mem_fun1_ref_t">const_mem_fun1_ref_t</A></B>; // TEMPLATE FUNCTIONStemplate<class Fn1> unary_negate<Fn1> <B><A HREF="#not1">not1</A></B>(const Fn1& func);template<class Fn2> binary_negate<Fn2> <B><A HREF="#not2">not2</A></B>(const Fn2& func);template<class Fn2, class Ty> binder1st<Fn2> <B><A HREF="#bind1st">bind1st</A></B>(const Fn2& func, const Ty& left);template<class Fn2, class Ty> binder2nd<Fn2> <B><A HREF="#bind2nd">bind2nd</A></B>(const Fn2& func, const Ty& right);template<class Arg, class Result> pointer_to_unary_function<Arg, Result> <B><A HREF="#ptr_fun">ptr_fun</A></B>(Result (*)(Arg));template<class Arg1, class Arg2, class Result> pointer_to_binary_function<Arg1, Arg2, Result> <B><A HREF="#ptr_fun">ptr_fun</A></B>(Result (*)(Arg1, Arg2));template<class Result, class Ty> mem_fun_t<Result, Ty> <B><A HREF="#mem_fun">mem_fun</A></B>(Result (Ty::*pm)());template<class Result, class Ty, class Arg> mem_fun1_t<Result, Ty, Arg> <B><A HREF="#mem_fun">mem_fun</A></B>(Result (Ty::*pm)(Arg left));template<class Result, class Ty> const_mem_fun_t<Result, Ty> <B><A HREF="#mem_fun">mem_fun</A></B>(Result (Ty::*pm)() const);template<class Result, class Ty, class Arg> const_mem_fun1_t<Result, Ty, Arg> <B><A HREF="#mem_fun">mem_fun</A></B>(Result (Ty::*pm)(Arg left) const);template<class Result, class Ty> mem_fun_ref_t<Result, Ty> <B><A HREF="#mem_fun_ref">mem_fun_ref</A></B>(Result (Ty::*pm)());template<class Result, class Ty, class Arg> mem_fun1_ref_t<Result, Ty, Arg> <B><A HREF="#mem_fun_ref">mem_fun_ref</A></B>(Result (Ty::*pm)(Arg left));template<class Result, class Ty> const_mem_fun_ref_t<Result, Ty> <B><A HREF="#mem_fun_ref">mem_fun_ref</A></B>(Result (Ty::*pm)() const);template<class Result, class Ty, class Arg> const_mem_fun1_ref_t<Result, Ty, Arg> <B><A HREF="#mem_fun_ref">mem_fun_ref</A></B>(Result (Ty::*pm)(Arg left) const); };</PRE><H2><A NAME="binary_function"><CODE>binary_function</CODE></A></H2><PRE>template<class Arg1, class Arg2, class Result> struct <B>binary_function</B> { typedef Arg1 <B>first_argument_type</B>; typedef Arg2 <B>second_argument_type</B>; typedef Result <B>result_type</B>; };</PRE><P>The template class serves as a base for classes that definea member function of the form:</P><PRE>result_type operator()(const first_argument_type&, const second_argument_type&) const</PRE><P>or a similar form taking two arguments.</P><P>Hence, all such<B><A NAME="binary functions">binary functions</A></B>can refer to their first argument type as<B><A NAME="binary_function::first_argument_type"><CODE>first_argument_type</CODE></A></B>,their second argument type as<B><A NAME="binary_function::second_argument_type"><CODE>second_argument_type</CODE></A></B>,and their return type as<B><A NAME="binary_function::result_type"><CODE>result_type</CODE></A></B>.</P><H2><A NAME="binary_negate"><CODE>binary_negate</CODE></A></H2><PRE>template<class Fn2> class <B>binary_negate</B> : public <A HREF="#binary_function">binary_function</A>< typename Fn2::first_argument_type, typename Fn2::second_argument_type, bool> {public: explicit <B>binary_negate</B>(const Fn2& func); bool <B>operator()</B>( const typename Fn2::first_argument_type& left, const typename Fn2::second_argument_type& right) const; };</PRE><P>The template class stores a copy of <CODE>func</CODE>, whichmust be a <A HREF="#binary functions">binary function</A> object.It defines its member function <B><CODE>operator()</CODE></B>as returning <CODE>!func(left, right)</CODE>.</P><H2> <A NAME="bind1st"><CODE>bind1st</CODE></A></H2><PRE>template<class Fn2, class Ty> <A HREF="#binder1st">binder1st</A><Fn2> <B>bind1st</B>(const Fn2amp; func, const Ty& left);</PRE><P>The function returns<CODE><A HREF="#binder1st">binder1st</A><Fn2>(func,typename Fn2::first_argument_type(left))</CODE>.</P><H2> <A NAME="bind2nd"><CODE>bind2nd</CODE></A></H2><PRE>template<class Fn2, class Ty> <A HREF="#binder2nd">binder2nd</A><Fn2> <B>bind2nd</B>(const Fn2& func, const Ty& right);</PRE><P>The function returns<CODE><A HREF="#binder2nd">binder2nd</A><Fn2>(func,typename Fn2::second_argument_type(right))</CODE>.</P><H2><A NAME="binder1st"><CODE>binder1st</CODE></A></H2><PRE>template<class Fn2> class <B>binder1st</B> : public <A HREF="#unary_function">unary_function</A>< typename Fn2::second_argument_type, typename Fn2::result_type> {public: typedef typename Fn2::second_argument_type argument_type; typedef typename Fn2::result_type result_type; <B>binder1st</B>(const Fn2& func, const typename Fn2::first_argument_type& left); result_type <B>operator()</B>(const argument_type& right) const;protected: Fn2 <B>op</B>; typename Fn2::first_argument_type <B>value</B>; };</PRE><P>The template class stores a copy of <CODE>func</CODE>, whichmust be a <A HREF="#binary functions">binary function</A> object, in<B><A NAME="binder1st::op"><CODE>op</CODE></A></B>,and a copy of <CODE>left</CODE> in<B><A NAME="binder1st::value"><CODE>value</CODE></A></B>.It defines its member function <B><CODE>operator()</CODE></B>as returning <CODE>op(value, right)</CODE>.</P><H2><A NAME="binder2nd"><CODE>binder2nd</CODE></A></H2><PRE>template<class Fn2> class <B>binder2nd</B> : public <A HREF="#unary_function">unary_function</A>< typename Fn2::first_argument_type, typename Fn2::result_type> {public: typedef typename Fn2::first_argument_type argument_type; typedef typename Fn2::result_type result_type; <B>binder2nd</B>(const Fn2& func, const typename Fn2::second_argument_type& right); result_type <B>operator()</B>(const argument_type& left) const;protected: Fn2 <B>op</B>; typename Fn2::second_argument_type <B>value</B>; };</PRE><P>The template class stores a copy of <CODE>func</CODE>, whichmust be a <A HREF="#binary functions">binary function</A> object, in<B><A NAME="binder2nd::op"><CODE>op</CODE></A></B>,and a copy of <CODE>right</CODE> in<B><A NAME="binder2nd::value"><CODE>value</CODE></A></B>.It defines its member function <B><CODE>operator()</CODE></B>as returning <CODE>op(left, value)</CODE>.</P><H2><A NAME="const_mem_fun_t"><CODE>const_mem_fun_t</CODE></A></H2><PRE>template<class Result, class Ty> struct <B>const_mem_fun_t</B> : public <A HREF="#unary_function">unary_function</A><const Ty *, Result> { explicit <B>const_mem_fun_t</B>(Result (Ty::*pm)() const); Result <B>operator()</B>(const Ty *pleft) const; };</PRE><P>The template class stores a copy of <CODE>pm</CODE>, whichmust be a pointer to a member function of class <CODE>Ty</CODE>, ina private member object.It defines its member function <B><CODE>operator()</CODE></B>as returning <CODE>(pleft->*pm)() const</CODE>.</P><H2><A NAME="const_mem_fun_ref_t"><CODE>const_mem_fun_ref_t</CODE></A></H2><PRE>template<class Result, class Ty> struct <B>const_mem_fun_ref_t</B> : public <A HREF="#unary_function">unary_function</A><Ty, Result> { explicit <B>const_mem_fun_t</B>(Result (Ty::*pm)() const); Result <B>operator()</B>(const Ty& left) const; };</PRE><P>The template class stores a copy of <CODE>pm</CODE>, whichmust be a pointer to a member function of class <CODE>Ty</CODE>, ina private member object.It defines its member function <B><CODE>operator()</CODE></B>as returning <CODE>(left.*pm)() const</CODE>.</P><H2><A NAME="const_mem_fun1_t"><CODE>const_mem_fun1_t</CODE></A></H2><PRE>template<class Result, class Ty, class Arg> struct <B>const_mem_fun1_t</B> : public <A HREF="#binary_function">binary_function</A><const Ty *, Arg, Result> { explicit <B>const_mem_fun1_t</B>(Result (Ty::*pm)(Arg) const); Result <B>operator()</B>(const Ty *pleft, Arg right) const; };</PRE><P>The template class stores a copy of <CODE>pm</CODE>, whichmust be a pointer to a member function of class <CODE>Ty</CODE>, ina private member object.It defines its member function <B><CODE>operator()</CODE></B>as returning <CODE>(pleft->*pm)(right) const</CODE>.</P><H2><A NAME="const_mem_fun1_ref_t"><CODE>const_mem_fun1_ref_t</CODE></A></H2><PRE>template<class Result, class Ty, class Arg> struct <B>const_mem_fun1_ref_t</B> : public <A HREF="#binary_function">binary_function</A><Ty, Arg, Result> { explicit <B>const_mem_fun1_ref_t</B>(Result (Ty::*pm)(Arg) const); Result <B>operator()</B>(const Ty& left, Arg right) const; };</PRE><P>The template class stores a copy of <CODE>pm</CODE>, whichmust be a pointer to a member function of class <CODE>Ty</CODE>, ina private member object.It defines its member function <B><CODE>operator()</CODE></B>as returning <CODE>(left.*pm)(right) const</CODE>.</P><H2><A NAME="divides"><CODE>divides</CODE></A></H2><PRE>template<class Ty> struct <B>divides</B> : public <A HREF="#binary_function">binary_function</A><Ty, Ty, Ty> { Ty <B>operator()</B>(const Ty& left, const Ty& right) const; };</PRE><P>The template class defines its member function as returning<CODE>left / right</CODE>.</P><H2><A NAME="equal_to"><CODE>equal_to</CODE></A></H2><PRE>template<class Ty> struct <B>equal_to</B> : public <A HREF="#binary_function">binary_function</A><Ty, Ty, bool> { bool <B>operator()</B>(const Ty& left, const Ty& right) const; };</PRE><P>The template class defines its member function as returning<CODE>left == right</CODE>.</P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -