<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>libstdc++: Adaptors for pointers to functions</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="navtree.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="navtree.js"></script> <script type="text/javascript" src="resize.js"></script> <script type="text/javascript"> $(document).ready(initResizable); </script> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.7.4 --> <div id="top"> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td style="padding-left: 0.5em;"> <div id="projectname">libstdc++</div> </td> </tr> </tbody> </table> </div> </div> <div id="side-nav" class="ui-resizable side-nav-resizable"> <div id="nav-tree"> <div id="nav-tree-contents"> </div> </div> <div id="splitbar" style="-moz-user-select:none;" class="ui-resizable-handle"> </div> </div> <script type="text/javascript"> initNavTree('a01198.html',''); </script> <div id="doc-content"> <div class="header"> <div class="summary"> <a href="#nested-classes">Classes</a> | <a href="#func-members">Functions</a> </div> <div class="headertitle"> <div class="title">Adaptors for pointers to functions</div> </div> <div class="ingroups"><a class="el" href="a01193.html">Function Objects</a></div></div> <div class="contents"> <div class="dynheader"> Collaboration diagram for Adaptors for pointers to functions:</div> <div class="dyncontent"> <center><table><tr><td><img src="a01198.png" border="0" alt="" usemap="#a01198"/> <map name="a01198" id="a01198"> <area shape="rect" id="node2" href="a01193.html" title="Function Objects" alt="" coords="7,5,119,35"/></map> </td></tr></table></center> </div> <h2><a name="nested-classes"></a> Classes</h2> <ul> <li>class <a class="el" href="a00658.html">std::pointer_to_binary_function< _Arg1, _Arg2, _Result ></a> <dl class="el"><dd class="mdescRight">One of the <a class="el" href="a01198.html">adaptors for function pointers</a>. <a href="a00658.html#details">More...</a><br/></dl><li>class <a class="el" href="a00659.html">std::pointer_to_unary_function< _Arg, _Result ></a> <dl class="el"><dd class="mdescRight">One of the <a class="el" href="a01198.html">adaptors for function pointers</a>. <a href="a00659.html#details">More...</a><br/></dl></ul> <h2><a name="func-members"></a> Functions</h2> <ul> <li>template<typename _Arg , typename _Result > pointer_to_unary_function<br class="typebreak"/> < _Arg, _Result > <a class="el" href="a01198.html#gac7139c6dea6421abef136a026f6c071b">std::ptr_fun</a> (_Result(*__x)(_Arg)) <li>template<typename _Arg1 , typename _Arg2 , typename _Result > pointer_to_binary_function<br class="typebreak"/> < _Arg1, _Arg2, _Result > <a class="el" href="a01198.html#ga358aa21a20d3e304bbe878f4940f5742">std::ptr_fun</a> (_Result(*__x)(_Arg1, _Arg2)) </ul> <hr/><a name="details" id="details"></a><h2>Detailed Description</h2> <p>The advantage of function objects over pointers to functions is that the objects in the standard library declare nested typedefs describing their argument and result types with uniform names (e.g., <code>result_type</code> from the base classes <code><a class="el" href="a00723.html">unary_function</a></code> and <code><a class="el" href="a00254.html">binary_function</a></code>). Sometimes those typedefs are required, not just optional.</p> <p>Adaptors are provided to turn pointers to unary (single-argument) and binary (double-argument) functions into function objects. The long-winded functor <code><a class="el" href="a00659.html" title="One of the adaptors for function pointers.">pointer_to_unary_function</a></code> is constructed with a function pointer <code>f</code>, and its <code>operator()</code> called with argument <code>x</code> returns <code>f(x)</code>. The functor <code><a class="el" href="a00658.html" title="One of the adaptors for function pointers.">pointer_to_binary_function</a></code> does the same thing, but with a double-argument <code>f</code> and <code>operator()</code>.</p> <p>The function <code>ptr_fun</code> takes a pointer-to-function <code>f</code> and constructs an instance of the appropriate functor. </p> <hr/><h2>Function Documentation</h2> <a class="anchor" id="gac7139c6dea6421abef136a026f6c071b"></a><!-- doxytag: member="std::ptr_fun" ref="gac7139c6dea6421abef136a026f6c071b" args="(_Result(*__x)(_Arg))" --> <div class="memitem"> <div class="memproto"> <div class="memtemplate"> template<typename _Arg , typename _Result > </div> <table class="memname"> <tr> <td class="memname">pointer_to_unary_function<_Arg, _Result> std::ptr_fun </td> <td>(</td> <td class="paramtype">_Result(*)(_Arg) </td> <td class="paramname"><em>__x</em></td><td>)</td> <td><code> [inline]</code></td> </tr> </table> </div> <div class="memdoc"> <p>One of the <a class="el" href="a01198.html">adaptors for function pointers</a>. </p> <p>Definition at line <a class="el" href="a01050_source.html#l00443">443</a> of file <a class="el" href="a01050_source.html">stl_function.h</a>.</p> </div> </div> <a class="anchor" id="ga358aa21a20d3e304bbe878f4940f5742"></a><!-- doxytag: member="std::ptr_fun" ref="ga358aa21a20d3e304bbe878f4940f5742" args="(_Result(*__x)(_Arg1, _Arg2))" --> <div class="memitem"> <div class="memproto"> <div class="memtemplate"> template<typename _Arg1 , typename _Arg2 , typename _Result > </div> <table class="memname"> <tr> <td class="memname">pointer_to_binary_function<_Arg1, _Arg2, _Result> std::ptr_fun </td> <td>(</td> <td class="paramtype">_Result(*)(_Arg1, _Arg2) </td> <td class="paramname"><em>__x</em></td><td>)</td> <td><code> [inline]</code></td> </tr> </table> </div> <div class="memdoc"> <p>One of the <a class="el" href="a01198.html">adaptors for function pointers</a>. </p> <p>Definition at line <a class="el" href="a01050_source.html#l00469">469</a> of file <a class="el" href="a01050_source.html">stl_function.h</a>.</p> </div> </div> </div> </div> <div id="nav-path" class="navpath"> <ul> <li class="footer">Generated by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </li> </ul> </div> </body> </html>