mirror of
https://github.com/boostorg/functional.git
synced 2025-07-30 04:27:18 +02:00
Updated docs.
[SVN r77899]
This commit is contained in:
@ -186,8 +186,8 @@ BOOST_TYPEOF_REGISTER_TEMPLATE(boost::overloaded_function,
|
|||||||
#else // DOXYGEN
|
#else // DOXYGEN
|
||||||
|
|
||||||
/** @file
|
/** @file
|
||||||
@brief Overload distinct function pointers, function references, and function
|
@brief Overload distinct function pointers, function references, and
|
||||||
objects into a single function object.
|
monomorphic function objects into a single function object.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
@ -196,18 +196,25 @@ namespace boost {
|
|||||||
@brief Function object to overload functions with distinct signatures.
|
@brief Function object to overload functions with distinct signatures.
|
||||||
|
|
||||||
This function object aggregates together calls to functions of all the
|
This function object aggregates together calls to functions of all the
|
||||||
specified function types <c>F1</c>, <c>F2</c>, etc.
|
specified function types <c>F1</c>, <c>F2</c>, etc which must have distinct
|
||||||
The specified function types must have distinct parameters from one another and
|
function signatures from one another.
|
||||||
they must be in the following format (which is the Boost.Function preferred
|
|
||||||
syntax):
|
@Params
|
||||||
|
@Param{F<em>i</em>,
|
||||||
|
Each function type must be specified using the following syntax (which is
|
||||||
|
Boost.Function's preferred syntax):
|
||||||
@code
|
@code
|
||||||
result_type (argument1_type, argumgnet2_type, ...)
|
result_type (argument1_type\, argumgnet2_type\, ...)
|
||||||
@endcode
|
@endcode
|
||||||
|
}
|
||||||
|
@EndParams
|
||||||
|
|
||||||
In some cases, the @RefFunc{make_overloaded_function} function template can be
|
In some cases, the @RefFunc{make_overloaded_function} function template can be
|
||||||
useful to construct the overloaded function object without explicitly
|
useful to construct an overloaded function object without explicitly
|
||||||
specifying the function types.
|
specifying the function types.
|
||||||
|
|
||||||
|
At least two distinct function types must be specified (because there is
|
||||||
|
nothing to overload between one or zero functions).
|
||||||
The maximum number of functions to overload is given by the
|
The maximum number of functions to overload is given by the
|
||||||
@RefMacro{BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX}
|
@RefMacro{BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX}
|
||||||
configuration macro.
|
configuration macro.
|
||||||
@ -232,6 +239,10 @@ public:
|
|||||||
Any function pointer, function reference, and monomorphic function object
|
Any function pointer, function reference, and monomorphic function object
|
||||||
that can be converted to a <c>boost::function</c> function object can be
|
that can be converted to a <c>boost::function</c> function object can be
|
||||||
specified as parameter.
|
specified as parameter.
|
||||||
|
|
||||||
|
@Note Unfortunately, it is not possible to support polymorphic function
|
||||||
|
objects (as explained <a
|
||||||
|
href="http://lists.boost.org/Archives/boost/2012/03/191744.php">here</a>).
|
||||||
*/
|
*/
|
||||||
overloaded_function(const boost::function<F1>&,
|
overloaded_function(const boost::function<F1>&,
|
||||||
const boost::function<F2>&, ...);
|
const boost::function<F2>&, ...);
|
||||||
@ -270,24 +281,24 @@ public:
|
|||||||
function types.
|
function types.
|
||||||
|
|
||||||
This function template creates and returns an @RefClass{overloaded_function}
|
This function template creates and returns an @RefClass{overloaded_function}
|
||||||
function object that overloads all the specified functions <c>f1</c>,
|
object that overloads all the specified functions <c>f1</c>, <c>f2</c>, etc.
|
||||||
<c>f2</c>, etc.
|
|
||||||
|
|
||||||
The function types are internally determined from the template parameter types
|
The function types are internally determined from the template parameter types
|
||||||
so they do not need to be explicitly specified.
|
so they do not need to be explicitly specified.
|
||||||
Therefore, this function template usually has a more concise syntax when
|
Therefore, this function template usually has a more concise syntax when
|
||||||
compared with @RefClass{overloaded_function}.
|
compared with @RefClass{overloaded_function}.
|
||||||
This is especially useful when the explicit type of the returned
|
This is especially useful when the explicit type of the returned
|
||||||
@RefClass{overloaded_function} does not need to be known (e.g., when used with Boost.Typeof's <c>BOOST_AUTO</c> (or C++11 <c>auto</c>) or when the overloaded
|
@RefClass{overloaded_function} object does not need to be known (e.g., when
|
||||||
function object is handled using a function template parameter, see the
|
used with Boost.Typeof's <c>BOOST_AUTO</c>, C++11 <c>auto</c>, or when the
|
||||||
@RefSect{Tutorial} section).
|
overloaded function object is handled using a function template parameter, see
|
||||||
|
the @RefSect{Tutorial} section).
|
||||||
|
|
||||||
The maximum number of functions to overload is given by the
|
The maximum number of functions to overload is given by the
|
||||||
@RefMacro{BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX}
|
@RefMacro{BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX}
|
||||||
configuration macro.
|
configuration macro.
|
||||||
|
|
||||||
@Note In this documentation, <c>__function_type__</c> is a placeholder for a
|
@Note In this documentation, <c>__function_type__</c> is a placeholder for a
|
||||||
symbol that is specific to implementation of this library.
|
symbol that is specific to the implementation of this library.
|
||||||
|
|
||||||
@See
|
@See
|
||||||
@RefSect{Tutorial} section,
|
@RefSect{Tutorial} section,
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
</span>BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX</pre></div>
|
</span>BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX</pre></div>
|
||||||
<div class="refsect1">
|
<div class="refsect1">
|
||||||
<a name="id872024"></a><h2>Description</h2>
|
<a name="id870708"></a><h2>Description</h2>
|
||||||
<p>If this macro is left undefined by the user, it has a default value of 5 (increasing this number might increase compilation time). When specified by the user, this macro must be a non-negative integer number.</p>
|
<p>If this macro is left undefined by the user, it has a default value of 5 (increasing this number might increase compilation time). When specified by the user, this macro must be a non-negative integer number.</p>
|
||||||
<p><span class="bold"><strong>See:</strong></span> <a class="link" href="boost_functional_overloadedfunction/Getting_Started.html" title="Getting Started"> Getting Started</a>, <code class="computeroutput"><a class="link" href="boost/overloaded_function.html" title="Class template overloaded_function">boost::overloaded_function</a></code>. </p>
|
<p><span class="bold"><strong>See:</strong></span> <a class="link" href="boost_functional_overloadedfunction/Getting_Started.html" title="Getting Started"> Getting Started</a>, <code class="computeroutput"><a class="link" href="boost/overloaded_function.html" title="Class template overloaded_function">boost::overloaded_function</a></code>. </p>
|
||||||
</div>
|
</div>
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
</span>BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX</pre></div>
|
</span>BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX</pre></div>
|
||||||
<div class="refsect1">
|
<div class="refsect1">
|
||||||
<a name="id872082"></a><h2>Description</h2>
|
<a name="id870766"></a><h2>Description</h2>
|
||||||
<p>If this macro is left undefined by the user, it has a default value of 5 (increasing this number might increase compilation time). When defined by the user, this macro must be an integer number greater or equal than 2 (because at least two distinct functions need to be specified in order to define an overload).</p>
|
<p>If this macro is left undefined by the user, it has a default value of 5 (increasing this number might increase compilation time). When defined by the user, this macro must be an integer number greater or equal than 2 (because at least two distinct functions need to be specified in order to define an overload).</p>
|
||||||
<p><span class="bold"><strong>See:</strong></span> <a class="link" href="boost_functional_overloadedfunction/Getting_Started.html" title="Getting Started"> Getting Started</a>, <code class="computeroutput"><a class="link" href="boost/overloaded_function.html" title="Class template overloaded_function">boost::overloaded_function</a></code>. </p>
|
<p><span class="bold"><strong>See:</strong></span> <a class="link" href="boost_functional_overloadedfunction/Getting_Started.html" title="Getting Started"> Getting Started</a>, <code class="computeroutput"><a class="link" href="boost/overloaded_function.html" title="Class template overloaded_function">boost::overloaded_function</a></code>. </p>
|
||||||
</div>
|
</div>
|
||||||
|
@ -36,11 +36,11 @@
|
|||||||
<a class="link" href="overloaded_function.html" title="Class template overloaded_function">overloaded_function</a><span class="special"><</span> <span class="identifier">__function_type__</span><span class="special"><</span> <span class="identifier">F1</span> <span class="special">></span><span class="special">,</span> <span class="identifier">__function_type__</span><span class="special"><</span> <span class="identifier">F2</span> <span class="special">></span><span class="special">,</span><span class="special">...</span><span class="special">></span>
|
<a class="link" href="overloaded_function.html" title="Class template overloaded_function">overloaded_function</a><span class="special"><</span> <span class="identifier">__function_type__</span><span class="special"><</span> <span class="identifier">F1</span> <span class="special">></span><span class="special">,</span> <span class="identifier">__function_type__</span><span class="special"><</span> <span class="identifier">F2</span> <span class="special">></span><span class="special">,</span><span class="special">...</span><span class="special">></span>
|
||||||
<span class="identifier">make_overloaded_function</span><span class="special">(</span><span class="identifier">F1</span> f1<span class="special">,</span> <span class="identifier">F2</span> f2<span class="special">,</span> <span class="special">...</span><span class="special">)</span><span class="special">;</span></pre></div>
|
<span class="identifier">make_overloaded_function</span><span class="special">(</span><span class="identifier">F1</span> f1<span class="special">,</span> <span class="identifier">F2</span> f2<span class="special">,</span> <span class="special">...</span><span class="special">)</span><span class="special">;</span></pre></div>
|
||||||
<div class="refsect1">
|
<div class="refsect1">
|
||||||
<a name="id871843"></a><h2>Description</h2>
|
<a name="id870528"></a><h2>Description</h2>
|
||||||
<p>This function template creates and returns an <code class="computeroutput"><code class="computeroutput"><a class="link" href="overloaded_function.html" title="Class template overloaded_function">overloaded_function</a></code></code> function object that overloads all the specified functions <code class="computeroutput">f1</code>, <code class="computeroutput">f2</code>, etc.</p>
|
<p>This function template creates and returns an <code class="computeroutput"><code class="computeroutput"><a class="link" href="overloaded_function.html" title="Class template overloaded_function">overloaded_function</a></code></code> object that overloads all the specified functions <code class="computeroutput">f1</code>, <code class="computeroutput">f2</code>, etc.</p>
|
||||||
<p>The function types are internally determined from the template parameter types so they do not need to be explicitly specified. Therefore, this function template usually has a more concise syntax when compared with <code class="computeroutput"><code class="computeroutput"><a class="link" href="overloaded_function.html" title="Class template overloaded_function">overloaded_function</a></code></code>. This is especially useful when the explicit type of the returned <code class="computeroutput"><code class="computeroutput"><a class="link" href="overloaded_function.html" title="Class template overloaded_function">overloaded_function</a></code></code> does not need to be known (e.g., when used with Boost.Typeof's <code class="computeroutput">BOOST_AUTO</code> (or C++11 <code class="computeroutput">auto</code>) or when the overloaded function object is handled using a function template parameter, see the <a class="link" href="../boost_functional_overloadedfunction/Tutorial.html" title="Tutorial">Tutorial</a> section).</p>
|
<p>The function types are internally determined from the template parameter types so they do not need to be explicitly specified. Therefore, this function template usually has a more concise syntax when compared with <code class="computeroutput"><code class="computeroutput"><a class="link" href="overloaded_function.html" title="Class template overloaded_function">overloaded_function</a></code></code>. This is especially useful when the explicit type of the returned <code class="computeroutput"><code class="computeroutput"><a class="link" href="overloaded_function.html" title="Class template overloaded_function">overloaded_function</a></code></code> object does not need to be known (e.g., when used with Boost.Typeof's <code class="computeroutput">BOOST_AUTO</code>, C++11 <code class="computeroutput">auto</code>, or when the overloaded function object is handled using a function template parameter, see the <a class="link" href="../boost_functional_overloadedfunction/Tutorial.html" title="Tutorial">Tutorial</a> section).</p>
|
||||||
<p>The maximum number of functions to overload is given by the <code class="computeroutput"><code class="computeroutput"><a class="link" href="../BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html" title="Macro BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX">BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX</a></code></code> configuration macro.</p>
|
<p>The maximum number of functions to overload is given by the <code class="computeroutput"><code class="computeroutput"><a class="link" href="../BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html" title="Macro BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX">BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX</a></code></code> configuration macro.</p>
|
||||||
<p><span class="bold"><strong>Note:</strong></span> In this documentation, <code class="computeroutput">__function_type__</code> is a placeholder for a symbol that is specific to implementation of this library.</p>
|
<p><span class="bold"><strong>Note:</strong></span> In this documentation, <code class="computeroutput">__function_type__</code> is a placeholder for a symbol that is specific to the implementation of this library.</p>
|
||||||
<p><span class="bold"><strong>See:</strong></span> <a class="link" href="../boost_functional_overloadedfunction/Tutorial.html" title="Tutorial">Tutorial</a> section, <code class="computeroutput"><code class="computeroutput"><a class="link" href="overloaded_function.html" title="Class template overloaded_function">overloaded_function</a></code></code>, <code class="computeroutput"><code class="computeroutput"><a class="link" href="../BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html" title="Macro BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX">BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX</a></code></code>. </p>
|
<p><span class="bold"><strong>See:</strong></span> <a class="link" href="../boost_functional_overloadedfunction/Tutorial.html" title="Tutorial">Tutorial</a> section, <code class="computeroutput"><code class="computeroutput"><a class="link" href="overloaded_function.html" title="Class template overloaded_function">overloaded_function</a></code></code>, <code class="computeroutput"><code class="computeroutput"><a class="link" href="../BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html" title="Macro BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX">BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX</a></code></code>. </p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -35,47 +35,60 @@
|
|||||||
<span class="keyword">class</span> <a class="link" href="overloaded_function.html" title="Class template overloaded_function">overloaded_function</a> <span class="special">{</span>
|
<span class="keyword">class</span> <a class="link" href="overloaded_function.html" title="Class template overloaded_function">overloaded_function</a> <span class="special">{</span>
|
||||||
<span class="keyword">public</span><span class="special">:</span>
|
<span class="keyword">public</span><span class="special">:</span>
|
||||||
<span class="comment">// <a class="link" href="overloaded_function.html#boost.overloaded_functionconstruct-copy-destruct">construct/copy/destruct</a></span>
|
<span class="comment">// <a class="link" href="overloaded_function.html#boost.overloaded_functionconstruct-copy-destruct">construct/copy/destruct</a></span>
|
||||||
<a class="link" href="overloaded_function.html#id299641-bb"><span class="identifier">overloaded_function</span></a><span class="special">(</span><span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">function</span><span class="special"><</span> <span class="identifier">F1</span> <span class="special">></span> <span class="special">&</span><span class="special">,</span>
|
<a class="link" href="overloaded_function.html#id315888-bb"><span class="identifier">overloaded_function</span></a><span class="special">(</span><span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">function</span><span class="special"><</span> <span class="identifier">F1</span> <span class="special">></span> <span class="special">&</span><span class="special">,</span>
|
||||||
<span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">function</span><span class="special"><</span> <span class="identifier">F2</span> <span class="special">></span> <span class="special">&</span><span class="special">,</span> <span class="special">...</span><span class="special">)</span><span class="special">;</span>
|
<span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">function</span><span class="special"><</span> <span class="identifier">F2</span> <span class="special">></span> <span class="special">&</span><span class="special">,</span> <span class="special">...</span><span class="special">)</span><span class="special">;</span>
|
||||||
|
|
||||||
<span class="comment">// <a class="link" href="overloaded_function.html#id299571-bb">public member functions</a></span>
|
<span class="comment">// <a class="link" href="overloaded_function.html#id315818-bb">public member functions</a></span>
|
||||||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">function_traits</span><span class="special"><</span> <span class="identifier">F1</span> <span class="special">></span><span class="special">::</span><span class="identifier">result_type</span>
|
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">function_traits</span><span class="special"><</span> <span class="identifier">F1</span> <span class="special">></span><span class="special">::</span><span class="identifier">result_type</span>
|
||||||
<a class="link" href="overloaded_function.html#id299574-bb"><span class="keyword">operator</span><span class="special">(</span><span class="special">)</span></a><span class="special">(</span><span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">function_traits</span><span class="special"><</span> <span class="identifier">F1</span> <span class="special">></span><span class="special">::</span><span class="identifier">arg1_type</span><span class="special">,</span>
|
<a class="link" href="overloaded_function.html#id315821-bb"><span class="keyword">operator</span><span class="special">(</span><span class="special">)</span></a><span class="special">(</span><span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">function_traits</span><span class="special"><</span> <span class="identifier">F1</span> <span class="special">></span><span class="special">::</span><span class="identifier">arg1_type</span><span class="special">,</span>
|
||||||
<span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">function_traits</span><span class="special"><</span> <span class="identifier">F1</span> <span class="special">></span><span class="special">::</span><span class="identifier">arg2_type</span><span class="special">,</span> <span class="special">...</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
|
<span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">function_traits</span><span class="special"><</span> <span class="identifier">F1</span> <span class="special">></span><span class="special">::</span><span class="identifier">arg2_type</span><span class="special">,</span> <span class="special">...</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
|
||||||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">function_traits</span><span class="special"><</span> <span class="identifier">F2</span> <span class="special">></span><span class="special">::</span><span class="identifier">result_type</span>
|
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">function_traits</span><span class="special"><</span> <span class="identifier">F2</span> <span class="special">></span><span class="special">::</span><span class="identifier">result_type</span>
|
||||||
<a class="link" href="overloaded_function.html#id299600-bb"><span class="keyword">operator</span><span class="special">(</span><span class="special">)</span></a><span class="special">(</span><span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">function_traits</span><span class="special"><</span> <span class="identifier">F2</span> <span class="special">></span><span class="special">::</span><span class="identifier">arg1_type</span><span class="special">,</span>
|
<a class="link" href="overloaded_function.html#id315847-bb"><span class="keyword">operator</span><span class="special">(</span><span class="special">)</span></a><span class="special">(</span><span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">function_traits</span><span class="special"><</span> <span class="identifier">F2</span> <span class="special">></span><span class="special">::</span><span class="identifier">arg1_type</span><span class="special">,</span>
|
||||||
<span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">function_traits</span><span class="special"><</span> <span class="identifier">F2</span> <span class="special">></span><span class="special">::</span><span class="identifier">arg2_type</span><span class="special">,</span> <span class="special">...</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
|
<span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">function_traits</span><span class="special"><</span> <span class="identifier">F2</span> <span class="special">></span><span class="special">::</span><span class="identifier">arg2_type</span><span class="special">,</span> <span class="special">...</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
|
||||||
<span class="special">}</span><span class="special">;</span></pre></div>
|
<span class="special">}</span><span class="special">;</span></pre></div>
|
||||||
<div class="refsect1">
|
<div class="refsect1">
|
||||||
<a name="id870004"></a><h2>Description</h2>
|
<a name="id869742"></a><h2>Description</h2>
|
||||||
<p>This function object aggregates together calls to functions of all the specified function types <code class="computeroutput">F1</code>, <code class="computeroutput">F2</code>, etc. The specified function types must have distinct parameters from one another and they must be in the following format (which is the Boost.Function preferred syntax): </p>
|
<p>This function object aggregates together calls to functions of all the specified function types <code class="computeroutput">F1</code>, <code class="computeroutput">F2</code>, etc which must have distinct function signatures from one another.</p>
|
||||||
<pre class="programlisting"> <span class="identifier">result_type</span> <span class="special">(</span><span class="identifier">argument1_type</span><span class="special">,</span> <span class="identifier">argumgnet2_type</span><span class="special">,</span> <span class="special">...</span><span class="special">)</span>
|
<p><span class="bold"><strong>Parameters:</strong></span> </p>
|
||||||
</pre>
|
<div class="informaltable"><table class="table">
|
||||||
<p>In some cases, the <code class="computeroutput"><a class="link" href="make_overloaded_function.html" title="Function template make_overloaded_function">make_overloaded_function</a></code> function template can be useful to construct the overloaded function object without explicitly specifying the function types.</p>
|
<colgroup>
|
||||||
<p>The maximum number of functions to overload is given by the <code class="computeroutput"><a class="link" href="../BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html" title="Macro BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX">BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX</a></code> configuration macro. The maximum number of function parameters for each of the specified function types is given by the <code class="computeroutput"><a class="link" href="../BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html" title="Macro BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX">BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX</a></code> configuration macro.</p>
|
<col>
|
||||||
|
<col>
|
||||||
|
</colgroup>
|
||||||
|
<tbody><tr>
|
||||||
|
<td><span class="bold"><strong><code class="computeroutput">F<span class="emphasis"><em>i</em></span></code></strong></span></td>
|
||||||
|
<td>Each function type must be specified using the following syntax (which is Boost.Function's preferred syntax): <pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"> <span class="identifier">result_type</span> <span class="special">(</span><span class="identifier">argument1_type</span><span class="special">,</span> <span class="identifier">argumgnet2_type</span><span class="special">,</span> <span class="special">...</span><span class="special">)</span>
|
||||||
|
</pre> </td>
|
||||||
|
</tr></tbody>
|
||||||
|
</table></div>
|
||||||
|
<p>
|
||||||
|
</p>
|
||||||
|
<p>In some cases, the <code class="computeroutput"><a class="link" href="make_overloaded_function.html" title="Function template make_overloaded_function">make_overloaded_function</a></code> function template can be useful to construct an overloaded function object without explicitly specifying the function types.</p>
|
||||||
|
<p>At least two distinct function types must be specified (because there is nothing to overload between one or zero functions). The maximum number of functions to overload is given by the <code class="computeroutput"><a class="link" href="../BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html" title="Macro BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX">BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX</a></code> configuration macro. The maximum number of function parameters for each of the specified function types is given by the <code class="computeroutput"><a class="link" href="../BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html" title="Macro BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX">BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX</a></code> configuration macro.</p>
|
||||||
<p><span class="bold"><strong>See:</strong></span> <a class="link" href="../boost_functional_overloadedfunction/Tutorial.html" title="Tutorial">Tutorial</a> section, <code class="computeroutput"><a class="link" href="make_overloaded_function.html" title="Function template make_overloaded_function">make_overloaded_function</a></code>, <code class="computeroutput"><a class="link" href="../BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html" title="Macro BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX">BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX</a></code>, <code class="computeroutput"><a class="link" href="../BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html" title="Macro BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX">BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX</a></code>, Boost.Function. </p>
|
<p><span class="bold"><strong>See:</strong></span> <a class="link" href="../boost_functional_overloadedfunction/Tutorial.html" title="Tutorial">Tutorial</a> section, <code class="computeroutput"><a class="link" href="make_overloaded_function.html" title="Function template make_overloaded_function">make_overloaded_function</a></code>, <code class="computeroutput"><a class="link" href="../BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html" title="Macro BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX">BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX</a></code>, <code class="computeroutput"><a class="link" href="../BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html" title="Macro BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX">BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX</a></code>, Boost.Function. </p>
|
||||||
<div class="refsect2">
|
<div class="refsect2">
|
||||||
<a name="id871216"></a><h3>
|
<a name="id869890"></a><h3>
|
||||||
<a name="boost.overloaded_functionconstruct-copy-destruct"></a><code class="computeroutput">overloaded_function</code>
|
<a name="boost.overloaded_functionconstruct-copy-destruct"></a><code class="computeroutput">overloaded_function</code>
|
||||||
public
|
public
|
||||||
construct/copy/destruct</h3>
|
construct/copy/destruct</h3>
|
||||||
<div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
|
<div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
|
||||||
<pre class="literallayout"><a name="id299641-bb"></a><span class="identifier">overloaded_function</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">function</span><span class="special"><</span> <span class="identifier">F1</span> <span class="special">></span> <span class="special">&</span><span class="special">,</span>
|
<pre class="literallayout"><a name="id315888-bb"></a><span class="identifier">overloaded_function</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">function</span><span class="special"><</span> <span class="identifier">F1</span> <span class="special">></span> <span class="special">&</span><span class="special">,</span>
|
||||||
<span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">function</span><span class="special"><</span> <span class="identifier">F2</span> <span class="special">></span> <span class="special">&</span><span class="special">,</span> <span class="special">...</span><span class="special">)</span><span class="special">;</span></pre>Construct the overloaded function object. <p>Any function pointer, function reference, and monomorphic function object that can be converted to a <code class="computeroutput">boost::function</code> function object can be specified as parameter. </p>
|
<span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">function</span><span class="special"><</span> <span class="identifier">F2</span> <span class="special">></span> <span class="special">&</span><span class="special">,</span> <span class="special">...</span><span class="special">)</span><span class="special">;</span></pre>Construct the overloaded function object. <p>Any function pointer, function reference, and monomorphic function object that can be converted to a <code class="computeroutput">boost::function</code> function object can be specified as parameter.</p>
|
||||||
|
<p><span class="bold"><strong>Note:</strong></span> Unfortunately, it is not possible to support polymorphic function objects (as explained <a href="http://lists.boost.org/Archives/boost/2012/03/191744.php" target="_top">here</a>). </p>
|
||||||
</li></ol></div>
|
</li></ol></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="refsect2">
|
<div class="refsect2">
|
||||||
<a name="id871341"></a><h3>
|
<a name="id870026"></a><h3>
|
||||||
<a name="id299571-bb"></a><code class="computeroutput">overloaded_function</code> public member functions</h3>
|
<a name="id315818-bb"></a><code class="computeroutput">overloaded_function</code> public member functions</h3>
|
||||||
<div class="orderedlist"><ol class="orderedlist" type="1">
|
<div class="orderedlist"><ol class="orderedlist" type="1">
|
||||||
<li class="listitem">
|
<li class="listitem">
|
||||||
<pre class="literallayout"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">function_traits</span><span class="special"><</span> <span class="identifier">F1</span> <span class="special">></span><span class="special">::</span><span class="identifier">result_type</span>
|
<pre class="literallayout"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">function_traits</span><span class="special"><</span> <span class="identifier">F1</span> <span class="special">></span><span class="special">::</span><span class="identifier">result_type</span>
|
||||||
<a name="id299574-bb"></a><span class="keyword">operator</span><span class="special">(</span><span class="special">)</span><span class="special">(</span><span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">function_traits</span><span class="special"><</span> <span class="identifier">F1</span> <span class="special">></span><span class="special">::</span><span class="identifier">arg1_type</span><span class="special">,</span>
|
<a name="id315821-bb"></a><span class="keyword">operator</span><span class="special">(</span><span class="special">)</span><span class="special">(</span><span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">function_traits</span><span class="special"><</span> <span class="identifier">F1</span> <span class="special">></span><span class="special">::</span><span class="identifier">arg1_type</span><span class="special">,</span>
|
||||||
<span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">function_traits</span><span class="special"><</span> <span class="identifier">F1</span> <span class="special">></span><span class="special">::</span><span class="identifier">arg2_type</span><span class="special">,</span> <span class="special">...</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>Call operator matching the signature of the function type specified as 1st template parameter. <p>This will in turn invoke the call operator of the 1st function passed to the constructor. </p>
|
<span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">function_traits</span><span class="special"><</span> <span class="identifier">F1</span> <span class="special">></span><span class="special">::</span><span class="identifier">arg2_type</span><span class="special">,</span> <span class="special">...</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>Call operator matching the signature of the function type specified as 1st template parameter. <p>This will in turn invoke the call operator of the 1st function passed to the constructor. </p>
|
||||||
</li>
|
</li>
|
||||||
<li class="listitem">
|
<li class="listitem">
|
||||||
<pre class="literallayout"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">function_traits</span><span class="special"><</span> <span class="identifier">F2</span> <span class="special">></span><span class="special">::</span><span class="identifier">result_type</span>
|
<pre class="literallayout"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">function_traits</span><span class="special"><</span> <span class="identifier">F2</span> <span class="special">></span><span class="special">::</span><span class="identifier">result_type</span>
|
||||||
<a name="id299600-bb"></a><span class="keyword">operator</span><span class="special">(</span><span class="special">)</span><span class="special">(</span><span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">function_traits</span><span class="special"><</span> <span class="identifier">F2</span> <span class="special">></span><span class="special">::</span><span class="identifier">arg1_type</span><span class="special">,</span>
|
<a name="id315847-bb"></a><span class="keyword">operator</span><span class="special">(</span><span class="special">)</span><span class="special">(</span><span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">function_traits</span><span class="special"><</span> <span class="identifier">F2</span> <span class="special">></span><span class="special">::</span><span class="identifier">arg1_type</span><span class="special">,</span>
|
||||||
<span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">function_traits</span><span class="special"><</span> <span class="identifier">F2</span> <span class="special">></span><span class="special">::</span><span class="identifier">arg2_type</span><span class="special">,</span> <span class="special">...</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>Call operator matching the signature of the function type specified as 2nd template parameter. <p>This will in turn invoke the call operator of the 2nd function passed to the constructor.</p>
|
<span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">function_traits</span><span class="special"><</span> <span class="identifier">F2</span> <span class="special">></span><span class="special">::</span><span class="identifier">arg2_type</span><span class="special">,</span> <span class="special">...</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>Call operator matching the signature of the function type specified as 2nd template parameter. <p>This will in turn invoke the call operator of the 2nd function passed to the constructor.</p>
|
||||||
<p><span class="bold"><strong>Note:</strong></span> Similar call operators are present for all specified function types <code class="computeroutput">F1</code>, <code class="computeroutput">F2</code>, etc (even if not exhaustively listed by this documentation). </p>
|
<p><span class="bold"><strong>Note:</strong></span> Similar call operators are present for all specified function types <code class="computeroutput">F1</code>, <code class="computeroutput">F2</code>, etc (even if not exhaustively listed by this documentation). </p>
|
||||||
</li>
|
</li>
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
and Platforms</a>
|
and Platforms</a>
|
||||||
</h3></div></div></div>
|
</h3></div></div></div>
|
||||||
<p>
|
<p>
|
||||||
The authors originally developed and tested the library on:
|
The authors originally developed and tested this library on:
|
||||||
</p>
|
</p>
|
||||||
<div class="orderedlist"><ol class="orderedlist" type="1">
|
<div class="orderedlist"><ol class="orderedlist" type="1">
|
||||||
<li class="listitem">
|
<li class="listitem">
|
||||||
@ -56,7 +56,8 @@
|
|||||||
<p>
|
<p>
|
||||||
See the library <a href="http://www.boost.org/development/tests/release/developer/functional-overloaded_function.html" target="_top">regressions
|
See the library <a href="http://www.boost.org/development/tests/release/developer/functional-overloaded_function.html" target="_top">regressions
|
||||||
test results</a> for detailed information on supported compilers and
|
test results</a> for detailed information on supported compilers and
|
||||||
platforms.
|
platforms. Check the library regression test <a href="../../../test/Jamfile.v2" target="_top"><code class="literal">Jamfile.v2</code></a>
|
||||||
|
for any special configuration that might be required for a specific compiler.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="section boost_functional_overloadedfunction_Getting_Started_installation">
|
<div class="section boost_functional_overloadedfunction_Getting_Started_installation">
|
||||||
@ -72,9 +73,9 @@
|
|||||||
<p>
|
<p>
|
||||||
The maximum number of functions to overload is given by the <code class="computeroutput"><a class="link" href="../BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html" title="Macro BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX">BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX</a></code>
|
The maximum number of functions to overload is given by the <code class="computeroutput"><a class="link" href="../BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html" title="Macro BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX">BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX</a></code>
|
||||||
configuration macro. The maximum number of function parameters for each of
|
configuration macro. The maximum number of function parameters for each of
|
||||||
the specified function types is given by the <code class="computeroutput"><a class="link" href="../BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html" title="Macro BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX">BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX</a></code>
|
the specified function type is given by the <code class="computeroutput"><a class="link" href="../BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html" title="Macro BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX">BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX</a></code>
|
||||||
configuration macro. All configuration macros have appropriate default values
|
configuration macro. All configuration macros have appropriate default values
|
||||||
when they are left undefined by the user.
|
when they are left undefined.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -39,10 +39,20 @@
|
|||||||
<a name="boost_functional_overloadedfunction.Tutorial.overloading"></a><a class="link" href="Tutorial.html#boost_functional_overloadedfunction.Tutorial.overloading" title="Overloading">Overloading</a>
|
<a name="boost_functional_overloadedfunction.Tutorial.overloading"></a><a class="link" href="Tutorial.html#boost_functional_overloadedfunction.Tutorial.overloading" title="Overloading">Overloading</a>
|
||||||
</h3></div></div></div>
|
</h3></div></div></div>
|
||||||
<p>
|
<p>
|
||||||
Consider the following functions with distinct signatures:
|
Consider the following functions which have distinct signatures:
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
[identity_decls]
|
</p>
|
||||||
|
<pre class="programlisting"><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&</span> <span class="identifier">identity_s</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&</span> <span class="identifier">x</span><span class="special">)</span> <span class="comment">// Function (as pointer).</span>
|
||||||
|
<span class="special">{</span> <span class="keyword">return</span> <span class="identifier">x</span><span class="special">;</span> <span class="special">}</span>
|
||||||
|
|
||||||
|
<span class="keyword">int</span> <span class="identifier">identity_i_impl</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">x</span><span class="special">;</span> <span class="special">}</span>
|
||||||
|
<span class="keyword">int</span> <span class="special">(&</span><span class="identifier">identity_i</span><span class="special">)(</span><span class="keyword">int</span><span class="special">)</span> <span class="special">=</span> <span class="identifier">identity_i_impl</span><span class="special">;</span> <span class="comment">// Function reference.</span>
|
||||||
|
|
||||||
|
<span class="keyword">double</span> <span class="identifier">identity_d_impl</span><span class="special">(</span><span class="keyword">double</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">x</span><span class="special">;</span> <span class="special">}</span>
|
||||||
|
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">function</span><span class="special"><</span><span class="keyword">double</span> <span class="special">(</span><span class="keyword">double</span><span class="special">)></span> <span class="identifier">identity_d</span> <span class="special">=</span> <span class="identifier">identity_d_impl</span><span class="special">;</span> <span class="comment">// Functor.</span>
|
||||||
|
</pre>
|
||||||
|
<p>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
This library header <code class="computeroutput"><a class="link" href="../reference.html#header.boost.functional.overloaded_function_hpp" title="Header <boost/functional/overloaded_function.hpp>">boost/functional/overloaded_function.hpp</a></code>
|
This library header <code class="computeroutput"><a class="link" href="../reference.html#header.boost.functional.overloaded_function_hpp" title="Header <boost/functional/overloaded_function.hpp>">boost/functional/overloaded_function.hpp</a></code>
|
||||||
@ -61,16 +71,15 @@
|
|||||||
<span class="special">></span> <span class="identifier">identity</span><span class="special">(</span><span class="identifier">identity_s</span><span class="special">,</span> <span class="identifier">identity_i</span><span class="special">,</span> <span class="identifier">identity_d</span><span class="special">);</span>
|
<span class="special">></span> <span class="identifier">identity</span><span class="special">(</span><span class="identifier">identity_s</span><span class="special">,</span> <span class="identifier">identity_i</span><span class="special">,</span> <span class="identifier">identity_d</span><span class="special">);</span>
|
||||||
|
|
||||||
<span class="comment">// All calls via single `identity` function.</span>
|
<span class="comment">// All calls via single `identity` function.</span>
|
||||||
<span class="identifier">BOOST_CHECK</span><span class="special">(</span><span class="identifier">identity</span><span class="special">(</span><span class="string">"abc"</span><span class="special">)</span> <span class="special">==</span> <span class="string">"abc"</span><span class="special">);</span>
|
<span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">identity</span><span class="special">(</span><span class="string">"abc"</span><span class="special">)</span> <span class="special">==</span> <span class="string">"abc"</span><span class="special">);</span>
|
||||||
<span class="identifier">BOOST_CHECK</span><span class="special">(</span><span class="identifier">identity</span><span class="special">(</span><span class="number">123</span><span class="special">)</span> <span class="special">==</span> <span class="number">123</span><span class="special">);</span>
|
<span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">identity</span><span class="special">(</span><span class="number">123</span><span class="special">)</span> <span class="special">==</span> <span class="number">123</span><span class="special">);</span>
|
||||||
<span class="identifier">BOOST_CHECK</span><span class="special">(</span><span class="identifier">identity</span><span class="special">(</span><span class="number">1.23</span><span class="special">)</span> <span class="special">==</span> <span class="number">1.23</span><span class="special">);</span>
|
<span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">identity</span><span class="special">(</span><span class="number">1.23</span><span class="special">)</span> <span class="special">==</span> <span class="number">1.23</span><span class="special">);</span>
|
||||||
</pre>
|
</pre>
|
||||||
<p>
|
<p>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Note how function types in the following format are passed as template parameters
|
Note how each function type is passed as a template parameter of <code class="computeroutput"><a class="link" href="../boost/overloaded_function.html" title="Class template overloaded_function">boost::overloaded_function</a></code> using
|
||||||
to <code class="computeroutput"><a class="link" href="../boost/overloaded_function.html" title="Class template overloaded_function">boost::overloaded_function</a></code>
|
the following syntax (this is <a href="http://www.boost.org/libs/function" target="_top">Boost.Function</a>'s
|
||||||
(this is the format of <a href="http://www.boost.org/libs/function" target="_top">Boost.Function</a>'s
|
|
||||||
preferred syntax):
|
preferred syntax):
|
||||||
</p>
|
</p>
|
||||||
<pre class="programlisting"><span class="emphasis"><em>result-type</em></span> <span class="special">(</span><span class="emphasis"><em>argument1-type</em></span><span class="special">,</span> <span class="emphasis"><em>argument2-type</em></span><span class="special">,</span> <span class="special">...)</span>
|
<pre class="programlisting"><span class="emphasis"><em>result-type</em></span> <span class="special">(</span><span class="emphasis"><em>argument1-type</em></span><span class="special">,</span> <span class="emphasis"><em>argument2-type</em></span><span class="special">,</span> <span class="special">...)</span>
|
||||||
@ -79,10 +88,10 @@
|
|||||||
Then the relative function pointers, function references, or <a href="http://en.wikipedia.org/wiki/Polymorphism_(computer_science)" target="_top">monomorphic
|
Then the relative function pointers, function references, or <a href="http://en.wikipedia.org/wiki/Polymorphism_(computer_science)" target="_top">monomorphic
|
||||||
function</a> objects are passed to the <code class="computeroutput"><a class="link" href="../boost/overloaded_function.html" title="Class template overloaded_function">boost::overloaded_function</a></code>
|
function</a> objects are passed to the <code class="computeroutput"><a class="link" href="../boost/overloaded_function.html" title="Class template overloaded_function">boost::overloaded_function</a></code>
|
||||||
constructor matching the order of the specified template parameters. <sup>[<a name="boost_functional_overloadedfunction.Tutorial.overloading.f0" href="#ftn.boost_functional_overloadedfunction.Tutorial.overloading.f0" class="footnote">2</a>]</sup> In the above example, <code class="computeroutput"><span class="identifier">identity_s</span></code>
|
constructor matching the order of the specified template parameters. <sup>[<a name="boost_functional_overloadedfunction.Tutorial.overloading.f0" href="#ftn.boost_functional_overloadedfunction.Tutorial.overloading.f0" class="footnote">2</a>]</sup> In the above example, <code class="computeroutput"><span class="identifier">identity_s</span></code>
|
||||||
is passed as function pointer (the function address is automatically taken
|
is passed as a function pointer (the function address is automatically taken
|
||||||
from the function name by compiler), <code class="computeroutput"><span class="identifier">identity_i</span></code>
|
from the function name by the compiler), <code class="computeroutput"><span class="identifier">identity_i</span></code>
|
||||||
as function reference, and <code class="computeroutput"><span class="identifier">identity_d</span></code>
|
as a function reference, and <code class="computeroutput"><span class="identifier">identity_d</span></code>
|
||||||
as function object.
|
as a function object.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
All specified function types must have distinct parameters from one another
|
All specified function types must have distinct parameters from one another
|
||||||
@ -114,9 +123,9 @@
|
|||||||
<pre class="programlisting"><span class="identifier">BOOST_AUTO</span><span class="special">(</span><span class="identifier">identity</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">make_overloaded_function</span><span class="special">(</span>
|
<pre class="programlisting"><span class="identifier">BOOST_AUTO</span><span class="special">(</span><span class="identifier">identity</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">make_overloaded_function</span><span class="special">(</span>
|
||||||
<span class="identifier">identity_s</span><span class="special">,</span> <span class="identifier">identity_i</span><span class="special">,</span> <span class="identifier">identity_d</span><span class="special">));</span>
|
<span class="identifier">identity_s</span><span class="special">,</span> <span class="identifier">identity_i</span><span class="special">,</span> <span class="identifier">identity_d</span><span class="special">));</span>
|
||||||
|
|
||||||
<span class="identifier">BOOST_CHECK</span><span class="special">(</span><span class="identifier">identity</span><span class="special">(</span><span class="string">"abc"</span><span class="special">)</span> <span class="special">==</span> <span class="string">"abc"</span><span class="special">);</span>
|
<span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">identity</span><span class="special">(</span><span class="string">"abc"</span><span class="special">)</span> <span class="special">==</span> <span class="string">"abc"</span><span class="special">);</span>
|
||||||
<span class="identifier">BOOST_CHECK</span><span class="special">(</span><span class="identifier">identity</span><span class="special">(</span><span class="number">123</span><span class="special">)</span> <span class="special">==</span> <span class="number">123</span><span class="special">);</span>
|
<span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">identity</span><span class="special">(</span><span class="number">123</span><span class="special">)</span> <span class="special">==</span> <span class="number">123</span><span class="special">);</span>
|
||||||
<span class="identifier">BOOST_CHECK</span><span class="special">(</span><span class="identifier">identity</span><span class="special">(</span><span class="number">1.23</span><span class="special">)</span> <span class="special">==</span> <span class="number">1.23</span><span class="special">);</span>
|
<span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">identity</span><span class="special">(</span><span class="number">1.23</span><span class="special">)</span> <span class="special">==</span> <span class="number">1.23</span><span class="special">);</span>
|
||||||
</pre>
|
</pre>
|
||||||
<p>
|
<p>
|
||||||
</p>
|
</p>
|
||||||
@ -135,7 +144,7 @@
|
|||||||
<p>
|
<p>
|
||||||
Another case where <code class="computeroutput"><a class="link" href="../boost/make_overloaded_function.html" title="Function template make_overloaded_function">boost::make_overloaded_function</a></code>
|
Another case where <code class="computeroutput"><a class="link" href="../boost/make_overloaded_function.html" title="Function template make_overloaded_function">boost::make_overloaded_function</a></code>
|
||||||
can be useful is when the overloaded function object is passed to a function
|
can be useful is when the overloaded function object is passed to a function
|
||||||
template which can hide the specific <code class="computeroutput"><a class="link" href="../boost/overloaded_function.html" title="Class template overloaded_function">boost::overloaded_function</a></code>
|
template which can hold the specific <code class="computeroutput"><a class="link" href="../boost/overloaded_function.html" title="Class template overloaded_function">boost::overloaded_function</a></code>
|
||||||
type using a template parameter. For example (see also <a href="../../../test/make_call.cpp" target="_top"><code class="literal">make_call.cpp</code></a>
|
type using a template parameter. For example (see also <a href="../../../test/make_call.cpp" target="_top"><code class="literal">make_call.cpp</code></a>
|
||||||
and <a href="../../../test/identity.hpp" target="_top"><code class="literal">identity.hpp</code></a>):
|
and <a href="../../../test/identity.hpp" target="_top"><code class="literal">identity.hpp</code></a>):
|
||||||
</p>
|
</p>
|
||||||
@ -143,9 +152,9 @@
|
|||||||
</p>
|
</p>
|
||||||
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">F</span><span class="special">></span>
|
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">F</span><span class="special">></span>
|
||||||
<span class="keyword">void</span> <span class="identifier">check</span><span class="special">(</span><span class="identifier">F</span> <span class="identifier">identity</span><span class="special">)</span> <span class="special">{</span>
|
<span class="keyword">void</span> <span class="identifier">check</span><span class="special">(</span><span class="identifier">F</span> <span class="identifier">identity</span><span class="special">)</span> <span class="special">{</span>
|
||||||
<span class="identifier">BOOST_CHECK</span><span class="special">(</span><span class="identifier">identity</span><span class="special">(</span><span class="string">"abc"</span><span class="special">)</span> <span class="special">==</span> <span class="string">"abc"</span><span class="special">);</span>
|
<span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">identity</span><span class="special">(</span><span class="string">"abc"</span><span class="special">)</span> <span class="special">==</span> <span class="string">"abc"</span><span class="special">);</span>
|
||||||
<span class="identifier">BOOST_CHECK</span><span class="special">(</span><span class="identifier">identity</span><span class="special">(</span><span class="number">123</span><span class="special">)</span> <span class="special">==</span> <span class="number">123</span><span class="special">);</span>
|
<span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">identity</span><span class="special">(</span><span class="number">123</span><span class="special">)</span> <span class="special">==</span> <span class="number">123</span><span class="special">);</span>
|
||||||
<span class="identifier">BOOST_CHECK</span><span class="special">(</span><span class="identifier">identity</span><span class="special">(</span><span class="number">1.23</span><span class="special">)</span> <span class="special">==</span> <span class="number">1.23</span><span class="special">);</span>
|
<span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">identity</span><span class="special">(</span><span class="number">1.23</span><span class="special">)</span> <span class="special">==</span> <span class="number">1.23</span><span class="special">);</span>
|
||||||
<span class="special">}</span>
|
<span class="special">}</span>
|
||||||
</pre>
|
</pre>
|
||||||
<p>
|
<p>
|
||||||
@ -154,6 +163,27 @@
|
|||||||
</p>
|
</p>
|
||||||
<pre class="programlisting"><span class="identifier">check</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">make_overloaded_function</span><span class="special">(</span><span class="identifier">identity_s</span><span class="special">,</span> <span class="identifier">identity_i</span><span class="special">,</span> <span class="identifier">identity_d</span><span class="special">));</span>
|
<pre class="programlisting"><span class="identifier">check</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">make_overloaded_function</span><span class="special">(</span><span class="identifier">identity_s</span><span class="special">,</span> <span class="identifier">identity_i</span><span class="special">,</span> <span class="identifier">identity_d</span><span class="special">));</span>
|
||||||
</pre>
|
</pre>
|
||||||
|
<p>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
The library implementation of <code class="computeroutput"><a class="link" href="../boost/make_overloaded_function.html" title="Function template make_overloaded_function">boost::make_overloaded_function</a></code>
|
||||||
|
uses <a href="http://www.boost.org/doc/libs/typeof" target="_top">Boost.Typeof</a>
|
||||||
|
to automatically deduce some of the function types. In order to compile code
|
||||||
|
in <a href="http://www.boost.org/doc/libs/typeof" target="_top">Boost.Typeof</a>
|
||||||
|
emulation mode, all types should be properly registered using <code class="computeroutput"><span class="identifier">BOOST_TYPEOF_REGISTER_TYPE</span></code> and <code class="computeroutput"><span class="identifier">BOOST_TYPEOF_REGISTER_TEMPLATE</span></code>, or appropriate
|
||||||
|
<a href="http://www.boost.org/doc/libs/typeof" target="_top">Boost.Typeof</a> headers
|
||||||
|
should be included (see <a href="http://www.boost.org/doc/libs/typeof" target="_top">Boost.Typeof</a>
|
||||||
|
for more information). For the above examples, it is sufficient to include
|
||||||
|
the <a href="http://www.boost.org/doc/libs/typeof" target="_top">Boost.Typeof</a>
|
||||||
|
header that registers <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span></code>
|
||||||
|
(this library does not require to register <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">function</span></code>
|
||||||
|
for <a href="http://www.boost.org/doc/libs/typeof" target="_top">Boost.Typeof</a>
|
||||||
|
emulation):
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
</p>
|
||||||
|
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">typeof</span><span class="special">/</span><span class="identifier">std</span><span class="special">/</span><span class="identifier">string</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> <span class="comment">// No need to register `boost::function`.</span>
|
||||||
|
</pre>
|
||||||
<p>
|
<p>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
@ -171,6 +201,8 @@
|
|||||||
pointers and function references). Finally, monomorphic function objects
|
pointers and function references). Finally, monomorphic function objects
|
||||||
are instances of classes with a non-template call operator of the form
|
are instances of classes with a non-template call operator of the form
|
||||||
<code class="literal"><span class="emphasis"><em>result-type </em></span></code><code class="computeroutput"><span class="keyword">operator</span><span class="special">()(</span></code><code class="literal"><span class="emphasis"><em>argument1-type</em></span></code><code class="computeroutput"><span class="special">,</span> <span class="special">...)</span></code>.
|
<code class="literal"><span class="emphasis"><em>result-type </em></span></code><code class="computeroutput"><span class="keyword">operator</span><span class="special">()(</span></code><code class="literal"><span class="emphasis"><em>argument1-type</em></span></code><code class="computeroutput"><span class="special">,</span> <span class="special">...)</span></code>.
|
||||||
|
Unfortunately, it is not possible to support polymorphic function objects
|
||||||
|
(see <a href="http://lists.boost.org/Archives/boost/2012/03/191744.php" target="_top">http://lists.boost.org/Archives/boost/2012/03/191744.php</a>).
|
||||||
</p></div>
|
</p></div>
|
||||||
<div class="footnote"><p><sup>[<a id="ftn.boost_functional_overloadedfunction.Tutorial.overloading.f1" href="#boost_functional_overloadedfunction.Tutorial.overloading.f1" class="para">3</a>] </sup>
|
<div class="footnote"><p><sup>[<a id="ftn.boost_functional_overloadedfunction.Tutorial.overloading.f1" href="#boost_functional_overloadedfunction.Tutorial.overloading.f1" class="para">3</a>] </sup>
|
||||||
Note that in C++ the function result type is not used for overload resolution
|
Note that in C++ the function result type is not used for overload resolution
|
||||||
|
@ -66,21 +66,31 @@
|
|||||||
<a name="boost_functional_overloadedfunction.Introduction"></a><a class="link" href="index.html#boost_functional_overloadedfunction.Introduction" title="Introduction">Introduction</a>
|
<a name="boost_functional_overloadedfunction.Introduction"></a><a class="link" href="index.html#boost_functional_overloadedfunction.Introduction" title="Introduction">Introduction</a>
|
||||||
</h2></div></div></div>
|
</h2></div></div></div>
|
||||||
<p>
|
<p>
|
||||||
Consider the following functions with distinct signatures:
|
Consider the following functions which have distinct signatures:
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
[identity_decls]
|
</p>
|
||||||
|
<pre class="programlisting"><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&</span> <span class="identifier">identity_s</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&</span> <span class="identifier">x</span><span class="special">)</span> <span class="comment">// Function (as pointer).</span>
|
||||||
|
<span class="special">{</span> <span class="keyword">return</span> <span class="identifier">x</span><span class="special">;</span> <span class="special">}</span>
|
||||||
|
|
||||||
|
<span class="keyword">int</span> <span class="identifier">identity_i_impl</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">x</span><span class="special">;</span> <span class="special">}</span>
|
||||||
|
<span class="keyword">int</span> <span class="special">(&</span><span class="identifier">identity_i</span><span class="special">)(</span><span class="keyword">int</span><span class="special">)</span> <span class="special">=</span> <span class="identifier">identity_i_impl</span><span class="special">;</span> <span class="comment">// Function reference.</span>
|
||||||
|
|
||||||
|
<span class="keyword">double</span> <span class="identifier">identity_d_impl</span><span class="special">(</span><span class="keyword">double</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">x</span><span class="special">;</span> <span class="special">}</span>
|
||||||
|
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">function</span><span class="special"><</span><span class="keyword">double</span> <span class="special">(</span><span class="keyword">double</span><span class="special">)></span> <span class="identifier">identity_d</span> <span class="special">=</span> <span class="identifier">identity_d_impl</span><span class="special">;</span> <span class="comment">// Functor.</span>
|
||||||
|
</pre>
|
||||||
|
<p>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Instead of calling them using their separate names (here <code class="computeroutput"><span class="identifier">BOOST_CHECK</span></code>
|
Instead of calling them using their separate names (here <code class="computeroutput"><span class="identifier">BOOST_TEST</span></code>
|
||||||
is equivalent to <code class="computeroutput"><span class="identifier">assert</span></code>):
|
is equivalent to <code class="computeroutput"><span class="identifier">assert</span></code>):
|
||||||
<sup>[<a name="boost_functional_overloadedfunction.Introduction.f0" href="#ftn.boost_functional_overloadedfunction.Introduction.f0" class="footnote">1</a>]</sup>
|
<sup>[<a name="boost_functional_overloadedfunction.Introduction.f0" href="#ftn.boost_functional_overloadedfunction.Introduction.f0" class="footnote">1</a>]</sup>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
</p>
|
</p>
|
||||||
<pre class="programlisting"><span class="identifier">BOOST_CHECK</span><span class="special">(</span><span class="identifier">identity_s</span><span class="special">(</span><span class="string">"abc"</span><span class="special">)</span> <span class="special">==</span> <span class="string">"abc"</span><span class="special">);</span>
|
<pre class="programlisting"><span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">identity_s</span><span class="special">(</span><span class="string">"abc"</span><span class="special">)</span> <span class="special">==</span> <span class="string">"abc"</span><span class="special">);</span>
|
||||||
<span class="identifier">BOOST_CHECK</span><span class="special">(</span><span class="identifier">identity_i</span><span class="special">(</span><span class="number">123</span><span class="special">)</span> <span class="special">==</span> <span class="number">123</span><span class="special">);</span>
|
<span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">identity_i</span><span class="special">(</span><span class="number">123</span><span class="special">)</span> <span class="special">==</span> <span class="number">123</span><span class="special">);</span>
|
||||||
<span class="identifier">BOOST_CHECK</span><span class="special">(</span><span class="identifier">identity_d</span><span class="special">(</span><span class="number">1.23</span><span class="special">)</span> <span class="special">==</span> <span class="number">1.23</span><span class="special">);</span>
|
<span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">identity_d</span><span class="special">(</span><span class="number">1.23</span><span class="special">)</span> <span class="special">==</span> <span class="number">1.23</span><span class="special">);</span>
|
||||||
</pre>
|
</pre>
|
||||||
<p>
|
<p>
|
||||||
</p>
|
</p>
|
||||||
@ -100,9 +110,9 @@
|
|||||||
<span class="special">></span> <span class="identifier">identity</span><span class="special">(</span><span class="identifier">identity_s</span><span class="special">,</span> <span class="identifier">identity_i</span><span class="special">,</span> <span class="identifier">identity_d</span><span class="special">);</span>
|
<span class="special">></span> <span class="identifier">identity</span><span class="special">(</span><span class="identifier">identity_s</span><span class="special">,</span> <span class="identifier">identity_i</span><span class="special">,</span> <span class="identifier">identity_d</span><span class="special">);</span>
|
||||||
|
|
||||||
<span class="comment">// All calls via single `identity` function.</span>
|
<span class="comment">// All calls via single `identity` function.</span>
|
||||||
<span class="identifier">BOOST_CHECK</span><span class="special">(</span><span class="identifier">identity</span><span class="special">(</span><span class="string">"abc"</span><span class="special">)</span> <span class="special">==</span> <span class="string">"abc"</span><span class="special">);</span>
|
<span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">identity</span><span class="special">(</span><span class="string">"abc"</span><span class="special">)</span> <span class="special">==</span> <span class="string">"abc"</span><span class="special">);</span>
|
||||||
<span class="identifier">BOOST_CHECK</span><span class="special">(</span><span class="identifier">identity</span><span class="special">(</span><span class="number">123</span><span class="special">)</span> <span class="special">==</span> <span class="number">123</span><span class="special">);</span>
|
<span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">identity</span><span class="special">(</span><span class="number">123</span><span class="special">)</span> <span class="special">==</span> <span class="number">123</span><span class="special">);</span>
|
||||||
<span class="identifier">BOOST_CHECK</span><span class="special">(</span><span class="identifier">identity</span><span class="special">(</span><span class="number">1.23</span><span class="special">)</span> <span class="special">==</span> <span class="number">1.23</span><span class="special">);</span>
|
<span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">identity</span><span class="special">(</span><span class="number">1.23</span><span class="special">)</span> <span class="special">==</span> <span class="number">1.23</span><span class="special">);</span>
|
||||||
</pre>
|
</pre>
|
||||||
<p>
|
<p>
|
||||||
</p>
|
</p>
|
||||||
@ -116,16 +126,19 @@
|
|||||||
<div class="footnotes">
|
<div class="footnotes">
|
||||||
<br><hr width="100" align="left">
|
<br><hr width="100" align="left">
|
||||||
<div class="footnote"><p><sup>[<a id="ftn.boost_functional_overloadedfunction.Introduction.f0" href="#boost_functional_overloadedfunction.Introduction.f0" class="para">1</a>] </sup>
|
<div class="footnote"><p><sup>[<a id="ftn.boost_functional_overloadedfunction.Introduction.f0" href="#boost_functional_overloadedfunction.Introduction.f0" class="para">1</a>] </sup>
|
||||||
In the examples presented in this documentation, <code class="computeroutput"><span class="identifier">BOOST_CHECK</span></code>
|
In most of the examples presented in this documentation, the Boost.Detail/LightweightTest
|
||||||
is used instead of <code class="computeroutput"><span class="identifier">assert</span></code>
|
(<code class="literal">boost/detail/lightweight_test.hpp</code>) macro <code class="computeroutput"><span class="identifier">BOOST_TEST</span></code> is used to check correctness
|
||||||
because it allows to write regression tests using <a href="http://www.boost.org/libs/test" target="_top">Boost.Test</a>.
|
conditions (conceptually similar to <code class="computeroutput"><span class="identifier">assert</span></code>).
|
||||||
The examples of this documentation are executed as part of the library test
|
A failure of the checked condition does not abort the execution of the program,
|
||||||
suite to verify that they always compile and run correctly.
|
it will instead make <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">report_errors</span></code>
|
||||||
|
return a non-zero program exit code. Using Boost.Detail/LightweightTest allows
|
||||||
|
to add the examples to the library regression tests so to make sure that
|
||||||
|
they always compile and run correctly.
|
||||||
</p></div>
|
</p></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||||
<td align="left"><p><small>Last revised: March 22, 2012 at 20:51:03 GMT</small></p></td>
|
<td align="left"><p><small>Last revised: April 10, 2012 at 20:37:20 GMT</small></p></td>
|
||||||
<td align="right"><div class="copyright-footer"></div></td>
|
<td align="right"><div class="copyright-footer"></div></td>
|
||||||
</tr></table>
|
</tr></table>
|
||||||
<hr>
|
<hr>
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
<div class="section header_boost_functional_overloaded_function_hpp">
|
<div class="section header_boost_functional_overloaded_function_hpp">
|
||||||
<div class="titlepage"><div><div><h3 class="title">
|
<div class="titlepage"><div><div><h3 class="title">
|
||||||
<a name="header.boost.functional.overloaded_function_hpp"></a>Header <<a href="../../../../../boost/functional/overloaded_function.hpp" target="_top">boost/functional/overloaded_function.hpp</a>></h3></div></div></div>
|
<a name="header.boost.functional.overloaded_function_hpp"></a>Header <<a href="../../../../../boost/functional/overloaded_function.hpp" target="_top">boost/functional/overloaded_function.hpp</a>></h3></div></div></div>
|
||||||
<p>Overload distinct function pointers, function references, and function objects into a single function object. </p>
|
<p>Overload distinct function pointers, function references, and monomorphic function objects into a single function object. </p>
|
||||||
<pre class="synopsis"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span>
|
<pre class="synopsis"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span>
|
||||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> F1<span class="special">,</span> <span class="keyword">typename</span> F2<span class="special">,</span> <span class="special">...</span> <span class="special">></span> <span class="keyword">class</span> <a class="link" href="boost/overloaded_function.html" title="Class template overloaded_function">overloaded_function</a><span class="special">;</span>
|
<span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> F1<span class="special">,</span> <span class="keyword">typename</span> F2<span class="special">,</span> <span class="special">...</span> <span class="special">></span> <span class="keyword">class</span> <a class="link" href="boost/overloaded_function.html" title="Class template overloaded_function">overloaded_function</a><span class="special">;</span>
|
||||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> F1<span class="special">,</span> <span class="keyword">typename</span> F2<span class="special">,</span> <span class="special">...</span> <span class="special">></span>
|
<span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> F1<span class="special">,</span> <span class="keyword">typename</span> F2<span class="special">,</span> <span class="special">...</span> <span class="special">></span>
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
[def __Boost_Function__ [@http://www.boost.org/libs/function Boost.Function]]
|
[def __Boost_Function__ [@http://www.boost.org/libs/function Boost.Function]]
|
||||||
[def __Boost_Typeof__ [@http://www.boost.org/doc/libs/typeof Boost.Typeof]]
|
[def __Boost_Typeof__ [@http://www.boost.org/doc/libs/typeof Boost.Typeof]]
|
||||||
|
|
||||||
|
[import ../test/identity.hpp]
|
||||||
[import ../test/functor.cpp]
|
[import ../test/functor.cpp]
|
||||||
[import ../test/make_decl.cpp]
|
[import ../test/make_decl.cpp]
|
||||||
[import ../test/make_call.cpp]
|
[import ../test/make_call.cpp]
|
||||||
@ -35,14 +36,15 @@ This library allows to overload different functions into a single function objec
|
|||||||
|
|
||||||
[section:Introduction Introduction]
|
[section:Introduction Introduction]
|
||||||
|
|
||||||
Consider the following functions with distinct signatures:
|
Consider the following functions which have distinct signatures:
|
||||||
|
|
||||||
[identity_decls]
|
[identity_decls]
|
||||||
|
|
||||||
Instead of calling them using their separate names (here `BOOST_CHECK` is equivalent to `assert`):
|
Instead of calling them using their separate names (here `BOOST_TEST` is equivalent to `assert`):
|
||||||
[footnote
|
[footnote
|
||||||
In the examples presented in this documentation, `BOOST_CHECK` is used instead of `assert` because it allows to write regression tests using __Boost_Test__.
|
In most of the examples presented in this documentation, the Boost.Detail/LightweightTest (=boost/detail/lightweight_test.hpp=) macro `BOOST_TEST` is used to check correctness conditions (conceptually similar to `assert`).
|
||||||
The examples of this documentation are executed as part of the library test suite to verify that they always compile and run correctly.
|
A failure of the checked condition does not abort the execution of the program, it will instead make `boost::report_errors` return a non-zero program exit code.
|
||||||
|
Using Boost.Detail/LightweightTest allows to add the examples to the library regression tests so to make sure that they always compile and run correctly.
|
||||||
]
|
]
|
||||||
|
|
||||||
[identity_calls]
|
[identity_calls]
|
||||||
@ -61,12 +63,13 @@ This section explains how to setup a system to use this library.
|
|||||||
|
|
||||||
[section Compilers and Platforms]
|
[section Compilers and Platforms]
|
||||||
|
|
||||||
The authors originally developed and tested the library on:
|
The authors originally developed and tested this library on:
|
||||||
|
|
||||||
# GNU Compiler Collection (GCC) C++ 4.5.3 (with and without C++11 features enabled `-std=c++0x`) on Cygwin.
|
# GNU Compiler Collection (GCC) C++ 4.5.3 (with and without C++11 features enabled `-std=c++0x`) on Cygwin.
|
||||||
# Miscrosoft Visual C++ (MSVC) 8.0 on Windows 7.
|
# Miscrosoft Visual C++ (MSVC) 8.0 on Windows 7.
|
||||||
|
|
||||||
See the library [@http://www.boost.org/development/tests/release/developer/functional-overloaded_function.html regressions test results] for detailed information on supported compilers and platforms.
|
See the library [@http://www.boost.org/development/tests/release/developer/functional-overloaded_function.html regressions test results] for detailed information on supported compilers and platforms.
|
||||||
|
Check the library regression test [@../../test/Jamfile.v2 =Jamfile.v2=] for any special configuration that might be required for a specific compiler.
|
||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
@ -77,8 +80,8 @@ Therefore there is no pre-compiled object file which needs to be installed.
|
|||||||
Programmers can simply instruct the compiler where to find the library header files (`-I` option on GCC, `/I` option on MSVC, etc) and compile code using the library.
|
Programmers can simply instruct the compiler where to find the library header files (`-I` option on GCC, `/I` option on MSVC, etc) and compile code using the library.
|
||||||
|
|
||||||
The maximum number of functions to overload is given by the [macroref BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX] configuration macro.
|
The maximum number of functions to overload is given by the [macroref BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX] configuration macro.
|
||||||
The maximum number of function parameters for each of the specified function types is given by the [macroref BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX] configuration macro.
|
The maximum number of function parameters for each of the specified function type is given by the [macroref BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX] configuration macro.
|
||||||
All configuration macros have appropriate default values when they are left undefined by the user.
|
All configuration macros have appropriate default values when they are left undefined.
|
||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
@ -90,7 +93,7 @@ This section explains how to use this library.
|
|||||||
|
|
||||||
[section Overloading]
|
[section Overloading]
|
||||||
|
|
||||||
Consider the following functions with distinct signatures:
|
Consider the following functions which have distinct signatures:
|
||||||
|
|
||||||
[identity_decls]
|
[identity_decls]
|
||||||
|
|
||||||
@ -98,7 +101,7 @@ This library header [headerref boost/functional/overloaded_function.hpp] provide
|
|||||||
|
|
||||||
[identity_functor]
|
[identity_functor]
|
||||||
|
|
||||||
Note how function types in the following format are passed as template parameters to [classref boost::overloaded_function] (this is the format of __Boost_Function__'s preferred syntax):
|
Note how each function type is passed as a template parameter of [classref boost::overloaded_function] using the following syntax (this is __Boost_Function__'s preferred syntax):
|
||||||
|
|
||||||
``/result-type/`` (``/argument1-type/``, ``/argument2-type/``, ...)
|
``/result-type/`` (``/argument1-type/``, ``/argument2-type/``, ...)
|
||||||
|
|
||||||
@ -108,8 +111,9 @@ Function pointers are of the form [^['result-type ]]`(*)(`[^['argument1-type]]`,
|
|||||||
Function references are of the form [^['result-type ]]`(&)(`[^['argument1-type]]`, ...)`.
|
Function references are of the form [^['result-type ]]`(&)(`[^['argument1-type]]`, ...)`.
|
||||||
Function types are of the form [^['result-type ]]`(`[^['argument1-type]]`, ...)` (note how they lack of both `*` and `&` when compared to function pointers and function references).
|
Function types are of the form [^['result-type ]]`(`[^['argument1-type]]`, ...)` (note how they lack of both `*` and `&` when compared to function pointers and function references).
|
||||||
Finally, monomorphic function objects are instances of classes with a non-template call operator of the form [^['result-type ]]`operator()(`[^['argument1-type]]`, ...)`.
|
Finally, monomorphic function objects are instances of classes with a non-template call operator of the form [^['result-type ]]`operator()(`[^['argument1-type]]`, ...)`.
|
||||||
|
Unfortunately, it is not possible to support polymorphic function objects (see [@http://lists.boost.org/Archives/boost/2012/03/191744.php]).
|
||||||
]
|
]
|
||||||
In the above example, `identity_s` is passed as function pointer (the function address is automatically taken from the function name by compiler), `identity_i` as function reference, and `identity_d` as function object.
|
In the above example, `identity_s` is passed as a function pointer (the function address is automatically taken from the function name by the compiler), `identity_i` as a function reference, and `identity_d` as a function object.
|
||||||
|
|
||||||
All specified function types must have distinct parameters from one another (so the overloaded calls can be resolved by this library).
|
All specified function types must have distinct parameters from one another (so the overloaded calls can be resolved by this library).
|
||||||
[footnote
|
[footnote
|
||||||
@ -128,17 +132,23 @@ The function types are automatically deduced from the specified functions and th
|
|||||||
The [funcref boost::make_overloaded_function] function template can be useful when used together with __Boost_Typeof__'s `BOOST_AUTO` (or C++11 `auto`).
|
The [funcref boost::make_overloaded_function] function template can be useful when used together with __Boost_Typeof__'s `BOOST_AUTO` (or C++11 `auto`).
|
||||||
For example (see also [@../../test/make_decl.cpp =make_decl.cpp=] and [@../../test/identity.hpp =identity.hpp=]):
|
For example (see also [@../../test/make_decl.cpp =make_decl.cpp=] and [@../../test/identity.hpp =identity.hpp=]):
|
||||||
|
|
||||||
[identity_make]
|
[identity_make_decl]
|
||||||
|
|
||||||
Note how the overloaded function object `identity` has been created specifying only the functions `identity_s`, `identity_i`, `identity_d` and without specifying the function types `const std::string& (const std::string&)`, `int (int)`, and `double (double)` as required instead by [classref boost::overloaded_function].
|
Note how the overloaded function object `identity` has been created specifying only the functions `identity_s`, `identity_i`, `identity_d` and without specifying the function types `const std::string& (const std::string&)`, `int (int)`, and `double (double)` as required instead by [classref boost::overloaded_function].
|
||||||
Therefore, [funcref boost::make_overloaded_function] provides a more concise syntax in this context when compared with [classref boost::overloaded_function].
|
Therefore, [funcref boost::make_overloaded_function] provides a more concise syntax in this context when compared with [classref boost::overloaded_function].
|
||||||
|
|
||||||
Another case where [funcref boost::make_overloaded_function] can be useful is when the overloaded function object is passed to a function template which can hide the specific [classref boost::overloaded_function] type using a template parameter.
|
Another case where [funcref boost::make_overloaded_function] can be useful is when the overloaded function object is passed to a function template which can hold the specific [classref boost::overloaded_function] type using a template parameter.
|
||||||
For example (see also [@../../test/make_call.cpp =make_call.cpp=] and [@../../test/identity.hpp =identity.hpp=]):
|
For example (see also [@../../test/make_call.cpp =make_call.cpp=] and [@../../test/identity.hpp =identity.hpp=]):
|
||||||
|
|
||||||
[identity_make_checks]
|
[identity_make_checks]
|
||||||
[identity_make_call]
|
[identity_make_call]
|
||||||
|
|
||||||
|
The library implementation of [funcref boost::make_overloaded_function] uses __Boost_Typeof__ to automatically deduce some of the function types.
|
||||||
|
In order to compile code in __Boost_Typeof__ emulation mode, all types should be properly registered using `BOOST_TYPEOF_REGISTER_TYPE` and `BOOST_TYPEOF_REGISTER_TEMPLATE`, or appropriate __Boost_Typeof__ headers should be included (see __Boost_Typeof__ for more information).
|
||||||
|
For the above examples, it is sufficient to include the __Boost_Typeof__ header that registers `std::string` (this library does not require to register `boost::function` for __Boost_Typeof__ emulation):
|
||||||
|
|
||||||
|
[identity_typeof]
|
||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
@ -9,10 +9,14 @@
|
|||||||
#define IDENTITY_HPP_
|
#define IDENTITY_HPP_
|
||||||
|
|
||||||
#include <boost/function.hpp>
|
#include <boost/function.hpp>
|
||||||
|
//[identity_typeof
|
||||||
|
#include <boost/typeof/std/string.hpp> // No need to register `boost::function`.
|
||||||
|
//]
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
//[identity_decls
|
//[identity_decls
|
||||||
const std::string& identity_s(const std::string& x) { return x; } // As pointer.
|
const std::string& identity_s(const std::string& x) // Function (as pointer).
|
||||||
|
{ return x; }
|
||||||
|
|
||||||
int identity_i_impl(int x) { return x; }
|
int identity_i_impl(int x) { return x; }
|
||||||
int (&identity_i)(int) = identity_i_impl; // Function reference.
|
int (&identity_i)(int) = identity_i_impl; // Function reference.
|
||||||
|
@ -7,12 +7,11 @@
|
|||||||
|
|
||||||
#include "identity.hpp"
|
#include "identity.hpp"
|
||||||
#include <boost/functional/overloaded_function.hpp>
|
#include <boost/functional/overloaded_function.hpp>
|
||||||
#include <boost/typeof/typeof.hpp> // For `BOOST_AUTO`.
|
#include <boost/typeof/typeof.hpp>
|
||||||
#include <boost/typeof/std/string.hpp> // No need to register `boost::function`.
|
|
||||||
#include <boost/detail/lightweight_test.hpp>
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
//[identity_make
|
//[identity_make_decl
|
||||||
BOOST_AUTO(identity, boost::make_overloaded_function(
|
BOOST_AUTO(identity, boost::make_overloaded_function(
|
||||||
identity_s, identity_i, identity_d));
|
identity_s, identity_i, identity_d));
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user