1553 lines
171 KiB
HTML
1553 lines
171 KiB
HTML
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
|
<title>Chapter 1. Boost.Bind</title>
|
|
<link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css">
|
|
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
|
|
<link rel="home" href="bind.html" title="Chapter 1. Boost.Bind">
|
|
</head>
|
|
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
|
<table cellpadding="2" width="100%"><tr>
|
|
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td>
|
|
<td align="center"><a href="../../../../index.html">Home</a></td>
|
|
<td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td>
|
|
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
|
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
|
<td align="center"><a href="../../../../more/index.htm">More</a></td>
|
|
</tr></table>
|
|
<hr>
|
|
<div class="spirit-nav"></div>
|
|
<div class="chapter">
|
|
<div class="titlepage"><div>
|
|
<div><h2 class="title">
|
|
<a name="bind"></a>Chapter 1. Boost.Bind</h2></div>
|
|
<div><p class="copyright">Copyright © 2001, 2002 Peter Dimov and Multi Media Ltd.</p></div>
|
|
<div><p class="copyright">Copyright © 2003-2008 Peter Dimov</p></div>
|
|
<div><div class="legalnotice">
|
|
<a name="bind.legal"></a><p>
|
|
Distributed under the <a href="http://boost.org/LICENSE_1_0.txt" target="_top">Boost
|
|
Software License, Version 1.0</a>.
|
|
</p>
|
|
</div></div>
|
|
</div></div>
|
|
<div class="toc">
|
|
<p><b>Table of Contents</b></p>
|
|
<dl class="toc">
|
|
<dt><span class="section"><a href="bind.html#bind.purpose">Purpose</a></span></dt>
|
|
<dd><dl>
|
|
<dt><span class="section"><a href="bind.html#bind.purpose.using_bind_with_functions_and_fu">Using
|
|
bind with functions and function pointers</a></span></dt>
|
|
<dt><span class="section"><a href="bind.html#bind.purpose.with_function_objects">Using bind with function
|
|
objects</a></span></dt>
|
|
<dt><span class="section"><a href="bind.html#bind.purpose.using_bind_with_pointers_to_memb">Using
|
|
bind with pointers to members</a></span></dt>
|
|
<dt><span class="section"><a href="bind.html#bind.purpose.using_nested_binds_for_function_">Using
|
|
nested binds for function composition</a></span></dt>
|
|
<dt><span class="section"><a href="bind.html#bind.purpose.overloaded_operators_new_in_boos">Overloaded
|
|
operators (new in Boost 1.33)</a></span></dt>
|
|
</dl></dd>
|
|
<dt><span class="section"><a href="bind.html#bind.examples">Examples</a></span></dt>
|
|
<dd><dl>
|
|
<dt><span class="section"><a href="bind.html#bind.examples.using_bind_with_standard_algorit">Using
|
|
bind with standard algorithms</a></span></dt>
|
|
<dt><span class="section"><a href="bind.html#bind.examples.using_bind_with_boost_function">Using bind
|
|
with Boost.Function</a></span></dt>
|
|
</dl></dd>
|
|
<dt><span class="section"><a href="bind.html#bind.limitations">Limitations</a></span></dt>
|
|
<dt><span class="section"><a href="bind.html#bind.faq">Frequently Asked Questions</a></span></dt>
|
|
<dd><dl>
|
|
<dt><span class="section"><a href="bind.html#bind.faq.why_doesn_t_this_compile">Why doesn't this compile?</a></span></dt>
|
|
<dt><span class="section"><a href="bind.html#bind.faq.why_does_this_compile_it_should_">Why does this
|
|
compile? It should not.</a></span></dt>
|
|
<dt><span class="section"><a href="bind.html#bind.faq.Q_forms">What is the difference between <code class="computeroutput"><span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="special">...)</span></code> and
|
|
<code class="computeroutput"><span class="identifier">bind</span><span class="special"><</span><span class="identifier">R</span><span class="special">>(</span><span class="identifier">f</span><span class="special">,</span> <span class="special">...)</span></code>?</a></span></dt>
|
|
<dt><span class="section"><a href="bind.html#bind.faq.does_bind_work_with_windows_api_">Does bind
|
|
work with Windows API functions?</a></span></dt>
|
|
<dt><span class="section"><a href="bind.html#bind.faq.does_bind_work_with_com_methods">Does bind work
|
|
with COM methods?</a></span></dt>
|
|
<dt><span class="section"><a href="bind.html#bind.faq.does_bind_work_with_mac_toolbox_">Does bind
|
|
work with Mac toolbox functions?</a></span></dt>
|
|
<dt><span class="section"><a href="bind.html#bind.faq.does_bind_work_with_extern_c_fun">Does bind
|
|
work with extern "C" functions?</a></span></dt>
|
|
<dt><span class="section"><a href="bind.html#bind.faq.why_doesn_t_bind_automatically_r">Why doesn't
|
|
bind automatically recognize nonstandard functions?</a></span></dt>
|
|
</dl></dd>
|
|
<dt><span class="section"><a href="bind.html#bind.troubleshooting">Troubleshooting</a></span></dt>
|
|
<dd><dl>
|
|
<dt><span class="section"><a href="bind.html#bind.troubleshooting.incorrect_number_of_arguments">Incorrect
|
|
number of arguments</a></span></dt>
|
|
<dt><span class="section"><a href="bind.html#bind.troubleshooting.the_function_object_cannot_be_ca">The
|
|
function object cannot be called with the specified arguments</a></span></dt>
|
|
<dt><span class="section"><a href="bind.html#bind.troubleshooting.accessing_an_argument_that_does_">Accessing
|
|
an argument that does not exist</a></span></dt>
|
|
<dt><span class="section"><a href="bind.html#bind.troubleshooting.inappropriate_use_of_bind_f">Inappropriate
|
|
use of <code class="computeroutput"><span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="special">...)</span></code></a></span></dt>
|
|
<dt><span class="section"><a href="bind.html#bind.troubleshooting.inappropriate_use_of_bind_r_f">Inappropriate
|
|
use of <code class="computeroutput"><span class="identifier">bind</span><span class="special"><</span><span class="identifier">R</span><span class="special">>(</span><span class="identifier">f</span><span class="special">,</span> <span class="special">...)</span></code></a></span></dt>
|
|
<dt><span class="section"><a href="bind.html#bind.troubleshooting.binding_a_nonstandard_function">Binding
|
|
a nonstandard function</a></span></dt>
|
|
<dt><span class="section"><a href="bind.html#bind.troubleshooting.binding_an_overloaded_function">Binding
|
|
an overloaded function</a></span></dt>
|
|
<dt><span class="section"><a href="bind.html#bind.troubleshooting.modeling_stl_function_object_con">Modeling
|
|
STL function object concepts</a></span></dt>
|
|
<dt><span class="section"><a href="bind.html#bind.troubleshooting.const_in_signatures"><code class="computeroutput"><span class="keyword">const</span></code> in signatures</a></span></dt>
|
|
<dt><span class="section"><a href="bind.html#bind.troubleshooting.msvc_specific_using_boost_bind">MSVC
|
|
specific: <code class="computeroutput"><span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">;</span></code></a></span></dt>
|
|
<dt><span class="section"><a href="bind.html#bind.troubleshooting.msvc_specific_class_templates_sh">MSVC
|
|
specific: class templates shadow function templates</a></span></dt>
|
|
<dt><span class="section"><a href="bind.html#bind.troubleshooting.msvc_specific_in_signatures_trea">MSVC
|
|
specific: <code class="computeroutput"><span class="special">...</span></code> in signatures treated
|
|
as type</a></span></dt>
|
|
</dl></dd>
|
|
<dt><span class="section"><a href="bind.html#bind.interface">Interface</a></span></dt>
|
|
<dd><dl>
|
|
<dt><span class="section"><a href="bind.html#bind.interface.synopsys">Synopsis</a></span></dt>
|
|
<dt><span class="section"><a href="bind.html#bind.interface.common_requirements">Common requirements</a></span></dt>
|
|
<dt><span class="section"><a href="bind.html#bind.interface.common_definitions">Common definitions</a></span></dt>
|
|
<dt><span class="section"><a href="bind.html#bind.interface.bind"><code class="computeroutput"><span class="identifier">bind</span></code></a></span></dt>
|
|
<dt><span class="section"><a href="bind.html#bind.interface.additional_overloads">Additional overloads</a></span></dt>
|
|
</dl></dd>
|
|
<dt><span class="section"><a href="bind.html#bind.implementation">Implementation</a></span></dt>
|
|
<dd><dl>
|
|
<dt><span class="section"><a href="bind.html#bind.implementation.files">Files</a></span></dt>
|
|
<dt><span class="section"><a href="bind.html#bind.implementation.dependencies">Dependencies</a></span></dt>
|
|
<dt><span class="section"><a href="bind.html#bind.implementation.number_of_arguments">Number of Arguments</a></span></dt>
|
|
<dt><span class="section"><a href="bind.html#bind.implementation.stdcall"><code class="computeroutput"><span class="identifier">__stdcall</span></code>,
|
|
<code class="computeroutput"><span class="identifier">__cdecl</span></code>, <code class="computeroutput"><span class="identifier">__fastcall</span></code>,
|
|
and <code class="computeroutput"><span class="identifier">pascal</span></code> Support</a></span></dt>
|
|
<dt><span class="section"><a href="bind.html#bind.implementation.visit_each_support"><code class="computeroutput"><span class="identifier">visit_each</span></code> support</a></span></dt>
|
|
</dl></dd>
|
|
<dt><span class="section"><a href="bind.html#bind.acknowledgements">Acknowledgements</a></span></dt>
|
|
</dl>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
|
<a name="bind.purpose"></a><a class="link" href="bind.html#bind.purpose" title="Purpose">Purpose</a>
|
|
</h2></div></div></div>
|
|
<p>
|
|
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span></code> is a generalization of the standard
|
|
functions <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">bind1st</span></code> and <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">bind2nd</span></code>.
|
|
It supports arbitrary function objects, functions, function pointers, and member
|
|
function pointers, and is able to bind any argument to a specific value or
|
|
route input arguments into arbitrary positions. <code class="computeroutput"><span class="identifier">bind</span></code>
|
|
does not place any requirements on the function object; in particular, it does
|
|
not need the <code class="computeroutput"><span class="identifier">result_type</span></code>,
|
|
<code class="computeroutput"><span class="identifier">first_argument_type</span></code> and <code class="computeroutput"><span class="identifier">second_argument_type</span></code> standard typedefs.
|
|
</p>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.purpose.using_bind_with_functions_and_fu"></a><a class="link" href="bind.html#bind.purpose.using_bind_with_functions_and_fu" title="Using bind with functions and function pointers">Using
|
|
bind with functions and function pointers</a>
|
|
</h3></div></div></div>
|
|
<p>
|
|
Given these definitions:
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">f</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">b</span><span class="special">)</span>
|
|
<span class="special">{</span>
|
|
<span class="keyword">return</span> <span class="identifier">a</span> <span class="special">+</span> <span class="identifier">b</span><span class="special">;</span>
|
|
<span class="special">}</span>
|
|
|
|
<span class="keyword">int</span> <span class="identifier">g</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">b</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">c</span><span class="special">)</span>
|
|
<span class="special">{</span>
|
|
<span class="keyword">return</span> <span class="identifier">a</span> <span class="special">+</span> <span class="identifier">b</span> <span class="special">+</span> <span class="identifier">c</span><span class="special">;</span>
|
|
<span class="special">}</span>
|
|
</pre>
|
|
<p>
|
|
<code class="computeroutput"><span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="number">1</span><span class="special">,</span> <span class="number">2</span><span class="special">)</span></code>
|
|
will produce a "nullary" function object that takes no arguments
|
|
and returns <code class="computeroutput"><span class="identifier">f</span><span class="special">(</span><span class="number">1</span><span class="special">,</span> <span class="number">2</span><span class="special">)</span></code>. Similarly, <code class="computeroutput"><span class="identifier">bind</span><span class="special">(</span><span class="identifier">g</span><span class="special">,</span>
|
|
<span class="number">1</span><span class="special">,</span> <span class="number">2</span><span class="special">,</span> <span class="number">3</span><span class="special">)()</span></code> is equivalent <code class="computeroutput"><span class="identifier">to</span>
|
|
<span class="identifier">g</span><span class="special">(</span><span class="number">1</span><span class="special">,</span> <span class="number">2</span><span class="special">,</span> <span class="number">3</span><span class="special">)</span></code>.
|
|
</p>
|
|
<p>
|
|
It is possible to selectively bind only some of the arguments. <code class="computeroutput"><span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">,</span>
|
|
<span class="number">5</span><span class="special">)(</span><span class="identifier">x</span><span class="special">)</span></code> is equivalent
|
|
to <code class="computeroutput"><span class="identifier">f</span><span class="special">(</span><span class="identifier">x</span><span class="special">,</span> <span class="number">5</span><span class="special">)</span></code>; here <code class="computeroutput"><span class="identifier">_1</span></code>
|
|
is a <span class="emphasis"><em>placeholder</em></span> argument that means "substitute
|
|
with the first input argument."
|
|
</p>
|
|
<p>
|
|
For comparison, here is the same operation expressed with the standard library
|
|
primitives:
|
|
</p>
|
|
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">bind2nd</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">ptr_fun</span><span class="special">(</span><span class="identifier">f</span><span class="special">),</span> <span class="number">5</span><span class="special">)(</span><span class="identifier">x</span><span class="special">);</span>
|
|
</pre>
|
|
<p>
|
|
<code class="computeroutput"><span class="identifier">bind</span></code> covers the functionality
|
|
of <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">bind1st</span></code> as well:
|
|
</p>
|
|
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">bind1st</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">ptr_fun</span><span class="special">(</span><span class="identifier">f</span><span class="special">),</span> <span class="number">5</span><span class="special">)(</span><span class="identifier">x</span><span class="special">);</span> <span class="comment">// f(5, x)</span>
|
|
<span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="number">5</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">)(</span><span class="identifier">x</span><span class="special">);</span> <span class="comment">// f(5, x)</span>
|
|
</pre>
|
|
<p>
|
|
<code class="computeroutput"><span class="identifier">bind</span></code> can handle functions
|
|
with more than two arguments, and its argument substitution mechanism is
|
|
more general:
|
|
</p>
|
|
<pre class="programlisting"><span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">_2</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">)(</span><span class="identifier">x</span><span class="special">,</span> <span class="identifier">y</span><span class="special">);</span> <span class="comment">// f(y, x)</span>
|
|
<span class="identifier">bind</span><span class="special">(</span><span class="identifier">g</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">,</span> <span class="number">9</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">)(</span><span class="identifier">x</span><span class="special">);</span> <span class="comment">// g(x, 9, x)</span>
|
|
<span class="identifier">bind</span><span class="special">(</span><span class="identifier">g</span><span class="special">,</span> <span class="identifier">_3</span><span class="special">,</span> <span class="identifier">_3</span><span class="special">,</span> <span class="identifier">_3</span><span class="special">)(</span><span class="identifier">x</span><span class="special">,</span> <span class="identifier">y</span><span class="special">,</span> <span class="identifier">z</span><span class="special">);</span> <span class="comment">// g(z, z, z)</span>
|
|
<span class="identifier">bind</span><span class="special">(</span><span class="identifier">g</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">)(</span><span class="identifier">x</span><span class="special">,</span> <span class="identifier">y</span><span class="special">,</span> <span class="identifier">z</span><span class="special">);</span> <span class="comment">// g(x, x, x)</span>
|
|
</pre>
|
|
<p>
|
|
Note that, in the last example, the function object produced by <code class="computeroutput"><span class="identifier">bind</span><span class="special">(</span><span class="identifier">g</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">,</span>
|
|
<span class="identifier">_1</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">)</span></code> does
|
|
not contain references to any arguments beyond the first, but it can still
|
|
be used with more than one argument. Any extra arguments are silently ignored,
|
|
just like the first and the second argument are ignored in the third example.
|
|
</p>
|
|
<p>
|
|
The arguments that <code class="computeroutput"><span class="identifier">bind</span></code> takes
|
|
are copied and held internally by the returned function object. For example,
|
|
in the following code:
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">5</span><span class="special">;</span>
|
|
<span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">i</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">);</span>
|
|
</pre>
|
|
<p>
|
|
a copy of the value of <code class="computeroutput"><span class="identifier">i</span></code>
|
|
is stored into the function object. <a href="../../../../libs/core/doc/html/core/ref.html" target="_top"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">ref</span></code></a> and <a href="../../../../libs/core/doc/html/core/ref.html" target="_top"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">cref</span></code></a> can be used to make the function
|
|
object store a reference to an object, rather than a copy:
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">5</span><span class="special">;</span>
|
|
<span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">ref</span><span class="special">(</span><span class="identifier">i</span><span class="special">),</span> <span class="identifier">_1</span><span class="special">);</span>
|
|
<span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">cref</span><span class="special">(</span><span class="identifier">i</span><span class="special">),</span> <span class="identifier">_1</span><span class="special">);</span>
|
|
</pre>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.purpose.with_function_objects"></a><a class="link" href="bind.html#bind.purpose.with_function_objects" title="Using bind with function objects">Using bind with function
|
|
objects</a>
|
|
</h3></div></div></div>
|
|
<p>
|
|
<code class="computeroutput"><span class="identifier">bind</span></code> is not limited to functions;
|
|
it accepts arbitrary function objects. In the general case, the return type
|
|
of the generated function object's <code class="computeroutput"><span class="keyword">operator</span><span class="special">()</span></code> has to be specified explicitly (without
|
|
a <code class="computeroutput"><span class="identifier">typeof</span></code> operator the return
|
|
type cannot be inferred):
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">F</span>
|
|
<span class="special">{</span>
|
|
<span class="keyword">int</span> <span class="keyword">operator</span><span class="special">()(</span><span class="keyword">int</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">b</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">a</span> <span class="special">-</span> <span class="identifier">b</span><span class="special">;</span> <span class="special">}</span>
|
|
<span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">()(</span><span class="keyword">long</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">long</span> <span class="identifier">b</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">a</span> <span class="special">==</span> <span class="identifier">b</span><span class="special">;</span> <span class="special">}</span>
|
|
<span class="special">};</span>
|
|
|
|
<span class="identifier">F</span> <span class="identifier">f</span><span class="special">;</span>
|
|
<span class="keyword">int</span> <span class="identifier">x</span> <span class="special">=</span> <span class="number">104</span><span class="special">;</span>
|
|
<span class="identifier">bind</span><span class="special"><</span><span class="keyword">int</span><span class="special">>(</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">)(</span><span class="identifier">x</span><span class="special">);</span> <span class="comment">// f(x, x), i.e. zero</span>
|
|
</pre>
|
|
<p>
|
|
Some compilers have trouble with the <code class="computeroutput"><span class="identifier">bind</span><span class="special"><</span><span class="identifier">R</span><span class="special">>(</span><span class="identifier">f</span><span class="special">,</span> <span class="special">...)</span></code>
|
|
syntax. For portability reasons, an alternative way to express the above
|
|
is supported:
|
|
</p>
|
|
<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">type</span><span class="special"><</span><span class="keyword">int</span><span class="special">>(),</span> <span class="identifier">f</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">)(</span><span class="identifier">x</span><span class="special">);</span>
|
|
</pre>
|
|
<p>
|
|
Note, however, that the alternative syntax is provided only as a workaround.
|
|
It is not part of the interface.
|
|
</p>
|
|
<p>
|
|
When the function object exposes a nested type named <code class="computeroutput"><span class="identifier">result_type</span></code>,
|
|
the explicit return type can be omitted:
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">x</span> <span class="special">=</span> <span class="number">8</span><span class="special">;</span>
|
|
<span class="identifier">bind</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">less</span><span class="special"><</span><span class="keyword">int</span><span class="special">>(),</span> <span class="identifier">_1</span><span class="special">,</span> <span class="number">9</span><span class="special">)(</span><span class="identifier">x</span><span class="special">);</span> <span class="comment">// x < 9</span>
|
|
</pre>
|
|
<p>
|
|
<span class="emphasis"><em>[Note:</em></span> the ability to omit the return type is not available
|
|
on all compilers.<span class="emphasis"><em>]</em></span>
|
|
</p>
|
|
<p>
|
|
By default, <code class="computeroutput"><span class="identifier">bind</span></code> makes a
|
|
copy of the provided function object. <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">ref</span></code> and
|
|
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">cref</span></code> can be used to make it store a reference
|
|
to the function object, rather than a copy. This can be useful when the function
|
|
object is non-copyable, expensive to copy, or contains state; of course,
|
|
in this case the programmer is expected to ensure that the function object
|
|
is not destroyed while it's still being used.
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">F2</span>
|
|
<span class="special">{</span>
|
|
<span class="keyword">int</span> <span class="identifier">s</span><span class="special">;</span>
|
|
|
|
<span class="keyword">typedef</span> <span class="keyword">void</span> <span class="identifier">result_type</span><span class="special">;</span>
|
|
<span class="keyword">void</span> <span class="keyword">operator</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="identifier">s</span> <span class="special">+=</span> <span class="identifier">x</span><span class="special">;</span> <span class="special">}</span>
|
|
<span class="special">};</span>
|
|
|
|
<span class="identifier">F2</span> <span class="identifier">f2</span> <span class="special">=</span> <span class="special">{</span> <span class="number">0</span> <span class="special">};</span>
|
|
<span class="keyword">int</span> <span class="identifier">a</span><span class="special">[]</span> <span class="special">=</span> <span class="special">{</span> <span class="number">1</span><span class="special">,</span> <span class="number">2</span><span class="special">,</span> <span class="number">3</span> <span class="special">};</span>
|
|
|
|
<span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span><span class="special">(</span><span class="identifier">a</span><span class="special">,</span> <span class="identifier">a</span><span class="special">+</span><span class="number">3</span><span class="special">,</span> <span class="identifier">bind</span><span class="special">(</span><span class="identifier">ref</span><span class="special">(</span><span class="identifier">f2</span><span class="special">),</span> <span class="identifier">_1</span><span class="special">));</span>
|
|
|
|
<span class="identifier">assert</span><span class="special">(</span><span class="identifier">f2</span><span class="special">.</span><span class="identifier">s</span> <span class="special">==</span> <span class="number">6</span><span class="special">);</span>
|
|
</pre>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.purpose.using_bind_with_pointers_to_memb"></a><a class="link" href="bind.html#bind.purpose.using_bind_with_pointers_to_memb" title="Using bind with pointers to members">Using
|
|
bind with pointers to members</a>
|
|
</h3></div></div></div>
|
|
<p>
|
|
Pointers to member functions and pointers to data members are not function
|
|
objects, because they do not support <code class="computeroutput"><span class="keyword">operator</span><span class="special">()</span></code>. For convenience, <code class="computeroutput"><span class="identifier">bind</span></code>
|
|
accepts member pointers as its first argument, and the behavior is as if
|
|
<a href="../../../../libs/bind/mem_fn.html" target="_top"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">mem_fn</span></code></a>
|
|
has been used to convert the member pointer into a function object. In other
|
|
words, the expression
|
|
</p>
|
|
<pre class="programlisting"><span class="identifier">bind</span><span class="special">(&</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">args</span><span class="special">)</span>
|
|
</pre>
|
|
<p>
|
|
is equivalent to
|
|
</p>
|
|
<pre class="programlisting"><span class="identifier">bind</span><span class="special"><</span><span class="identifier">R</span><span class="special">>(</span><a href="../../../../libs/bind/mem_fn.html" target="_top"><code class="computeroutput"><span class="identifier">mem_fn</span></code></a><span class="special">(&</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">f</span><span class="special">),</span> <span class="identifier">args</span><span class="special">)</span>
|
|
</pre>
|
|
<p>
|
|
where <code class="computeroutput"><span class="identifier">R</span></code> is the return type
|
|
of <code class="computeroutput"><span class="identifier">X</span><span class="special">::</span><span class="identifier">f</span></code> (for member functions) or the type of
|
|
the member (for data members.)
|
|
</p>
|
|
<p>
|
|
<span class="emphasis"><em>[Note:</em></span> <code class="computeroutput"><span class="identifier">mem_fn</span></code>
|
|
creates function objects that are able to accept a pointer, a reference,
|
|
or a smart pointer to an object as its first argument; for additional information,
|
|
see the <code class="computeroutput"><span class="identifier">mem_fn</span></code> <a href="../../../../libs/bind/mem_fn.html" target="_top">documentation</a>.<span class="emphasis"><em>]</em></span>
|
|
</p>
|
|
<p>
|
|
Example:
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">X</span>
|
|
<span class="special">{</span>
|
|
<span class="keyword">bool</span> <span class="identifier">f</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">a</span><span class="special">);</span>
|
|
<span class="special">};</span>
|
|
|
|
<span class="identifier">X</span> <span class="identifier">x</span><span class="special">;</span>
|
|
<span class="identifier">shared_ptr</span><span class="special"><</span><span class="identifier">X</span><span class="special">></span> <span class="identifier">p</span><span class="special">(</span><span class="keyword">new</span> <span class="identifier">X</span><span class="special">);</span>
|
|
<span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">5</span><span class="special">;</span>
|
|
|
|
<span class="identifier">bind</span><span class="special">(&</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">ref</span><span class="special">(</span><span class="identifier">x</span><span class="special">),</span> <span class="identifier">_1</span><span class="special">)(</span><span class="identifier">i</span><span class="special">);</span> <span class="comment">// x.f(i)</span>
|
|
<span class="identifier">bind</span><span class="special">(&</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">f</span><span class="special">,</span> <span class="special">&</span><span class="identifier">x</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">)(</span><span class="identifier">i</span><span class="special">);</span> <span class="comment">// (&x)->f(i)</span>
|
|
<span class="identifier">bind</span><span class="special">(&</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">)(</span><span class="identifier">i</span><span class="special">);</span> <span class="comment">// (internal copy of x).f(i)</span>
|
|
<span class="identifier">bind</span><span class="special">(&</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">p</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">)(</span><span class="identifier">i</span><span class="special">);</span> <span class="comment">// (internal copy of p)->f(i)</span>
|
|
</pre>
|
|
<p>
|
|
The last two examples are interesting in that they produce "self-contained"
|
|
function objects. <code class="computeroutput"><span class="identifier">bind</span><span class="special">(&</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">x</span><span class="special">,</span>
|
|
<span class="identifier">_1</span><span class="special">)</span></code>
|
|
stores a copy of <code class="computeroutput"><span class="identifier">x</span></code>. <code class="computeroutput"><span class="identifier">bind</span><span class="special">(&</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">p</span><span class="special">,</span>
|
|
<span class="identifier">_1</span><span class="special">)</span></code>
|
|
stores a copy of <code class="computeroutput"><span class="identifier">p</span></code>, and since
|
|
<code class="computeroutput"><span class="identifier">p</span></code> is a <a href="../../../../libs/smart_ptr/doc/html/smart_ptr.html#shared_ptr" target="_top"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">shared_ptr</span></code></a>, the function object
|
|
retains a reference to its instance of <code class="computeroutput"><span class="identifier">X</span></code>
|
|
and will remain valid even when <code class="computeroutput"><span class="identifier">p</span></code>
|
|
goes out of scope or is <code class="computeroutput"><span class="identifier">reset</span><span class="special">()</span></code>.
|
|
</p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.purpose.using_nested_binds_for_function_"></a><a class="link" href="bind.html#bind.purpose.using_nested_binds_for_function_" title="Using nested binds for function composition">Using
|
|
nested binds for function composition</a>
|
|
</h3></div></div></div>
|
|
<p>
|
|
Some of the arguments passed to <code class="computeroutput"><span class="identifier">bind</span></code>
|
|
may be nested <span class="emphasis"><em>bind expressions</em></span> themselves:
|
|
</p>
|
|
<pre class="programlisting"><span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">bind</span><span class="special">(</span><span class="identifier">g</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">))(</span><span class="identifier">x</span><span class="special">);</span> <span class="comment">// f(g(x))</span>
|
|
</pre>
|
|
<p>
|
|
The inner <span class="emphasis"><em>bind expressions</em></span> are evaluated, in unspecified
|
|
order, before the outer <code class="computeroutput"><span class="identifier">bind</span></code>
|
|
when the function object is called; the results of the evaluation are then
|
|
substituted in their place when the outer <code class="computeroutput"><span class="identifier">bind</span></code>
|
|
is evaluated. In the example above, when the function object is called with
|
|
the argument list <code class="computeroutput"><span class="special">(</span><span class="identifier">x</span><span class="special">)</span></code>, <code class="computeroutput"><span class="identifier">bind</span><span class="special">(</span><span class="identifier">g</span><span class="special">,</span>
|
|
<span class="identifier">_1</span><span class="special">)(</span><span class="identifier">x</span><span class="special">)</span></code> is evaluated
|
|
first, yielding <code class="computeroutput"><span class="identifier">g</span><span class="special">(</span><span class="identifier">x</span><span class="special">)</span></code>, and
|
|
then <code class="computeroutput"><span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">g</span><span class="special">(</span><span class="identifier">x</span><span class="special">))(</span><span class="identifier">x</span><span class="special">)</span></code> is evaluated,
|
|
yielding the final result <code class="computeroutput"><span class="identifier">f</span><span class="special">(</span><span class="identifier">g</span><span class="special">(</span><span class="identifier">x</span><span class="special">))</span></code>.
|
|
</p>
|
|
<p>
|
|
This feature of <code class="computeroutput"><span class="identifier">bind</span></code> can
|
|
be used to perform function composition. See <a href="../../bind_as_compose.cpp" target="_top">bind_as_compose.cpp</a>
|
|
for an example that demonstrates how to use <code class="computeroutput"><span class="identifier">bind</span></code>
|
|
to achieve similar functionality to <a href="http://www.boost.org/doc/libs/1_31_0/libs/compose/index.htm" target="_top">Boost.Compose</a>.
|
|
</p>
|
|
<p>
|
|
Note that the first argument - the bound function object - is not evaluated,
|
|
even when it's a function object that is produced by <code class="computeroutput"><span class="identifier">bind</span></code>
|
|
or a <span class="emphasis"><em>placeholder</em></span> argument, so the example below does
|
|
not work as expected:
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">typedef</span> <span class="keyword">void</span> <span class="special">(*</span><span class="identifier">pf</span><span class="special">)(</span><span class="keyword">int</span><span class="special">);</span>
|
|
|
|
<span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span><span class="identifier">pf</span><span class="special">></span> <span class="identifier">v</span><span class="special">;</span>
|
|
<span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span><span class="special">(</span><span class="identifier">v</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">v</span><span class="special">.</span><span class="identifier">end</span><span class="special">(),</span> <span class="identifier">bind</span><span class="special">(</span><span class="identifier">_1</span><span class="special">,</span> <span class="number">5</span><span class="special">));</span>
|
|
</pre>
|
|
<p>
|
|
The desired effect can be achieved via a helper function object <code class="computeroutput"><span class="identifier">apply</span></code> that applies its first argument,
|
|
as a function object, to the rest of its argument list. For convenience,
|
|
an implementation of <code class="computeroutput"><span class="identifier">apply</span></code>
|
|
is provided in the <a href="../../../../boost/bind/apply.hpp" target="_top">apply.hpp</a>
|
|
header file. Here is how the modified version of the previous example looks
|
|
like:
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">typedef</span> <span class="keyword">void</span> <span class="special">(*</span><span class="identifier">pf</span><span class="special">)(</span><span class="keyword">int</span><span class="special">);</span>
|
|
|
|
<span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span><span class="identifier">pf</span><span class="special">></span> <span class="identifier">v</span><span class="special">;</span>
|
|
<span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span><span class="special">(</span><span class="identifier">v</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">v</span><span class="special">.</span><span class="identifier">end</span><span class="special">(),</span> <span class="identifier">bind</span><span class="special">(</span><span class="identifier">apply</span><span class="special"><</span><span class="keyword">void</span><span class="special">>(),</span> <span class="identifier">_1</span><span class="special">,</span> <span class="number">5</span><span class="special">));</span>
|
|
</pre>
|
|
<p>
|
|
Although the first argument is, by default, not evaluated, all other arguments
|
|
are. Sometimes it is necessary not to evaluate arguments subsequent to the
|
|
first, even when they are nested <span class="emphasis"><em>bind subexpressions</em></span>.
|
|
This can be achieved with the help of another function object, <code class="computeroutput"><span class="identifier">protect</span></code>, that masks the type so that <code class="computeroutput"><span class="identifier">bind</span></code> does not recognize and evaluate it.
|
|
When called, protect simply forwards the argument list to the other function
|
|
object unmodified.
|
|
</p>
|
|
<p>
|
|
The header <a href="../../../../boost/bind/protect.hpp" target="_top">protect.hpp</a>
|
|
contains an implementation of <code class="computeroutput"><span class="identifier">protect</span></code>.
|
|
To <code class="computeroutput"><span class="identifier">protect</span></code> a bind function
|
|
object from evaluation, use <code class="computeroutput"><span class="identifier">protect</span><span class="special">(</span><span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="special">...))</span></code>.
|
|
</p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.purpose.overloaded_operators_new_in_boos"></a><a class="link" href="bind.html#bind.purpose.overloaded_operators_new_in_boos" title="Overloaded operators (new in Boost 1.33)">Overloaded
|
|
operators (new in Boost 1.33)</a>
|
|
</h3></div></div></div>
|
|
<p>
|
|
For convenience, the function objects produced by <code class="computeroutput"><span class="identifier">bind</span></code>
|
|
overload the logical not operator <code class="computeroutput"><span class="special">!</span></code>
|
|
and the relational and logical operators <code class="computeroutput"><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="special">&&,</span>
|
|
<span class="special">||</span></code>.
|
|
</p>
|
|
<p>
|
|
<code class="computeroutput"><span class="special">!</span><span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span>
|
|
<span class="special">...)</span></code> is equivalent to <code class="computeroutput"><span class="identifier">bind</span><span class="special">(</span><span class="identifier">logical_not</span><span class="special">(),</span> <span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span>
|
|
<span class="special">...))</span></code>, where <code class="computeroutput"><span class="identifier">logical_not</span></code>
|
|
is a function object that takes one argument <code class="computeroutput"><span class="identifier">x</span></code>
|
|
and returns <code class="computeroutput"><span class="special">!</span><span class="identifier">x</span></code>.
|
|
</p>
|
|
<p>
|
|
<code class="computeroutput"><span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="special">...)</span>
|
|
<span class="identifier">op</span> <span class="identifier">x</span></code>,
|
|
where <span class="underline">op</span> is a relational or logical
|
|
operator, is equivalent to <code class="computeroutput"><span class="identifier">bind</span><span class="special">(</span><span class="identifier">relation</span><span class="special">(),</span> <span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span>
|
|
<span class="special">...),</span> <span class="identifier">x</span><span class="special">)</span></code>, where <code class="computeroutput"><span class="identifier">relation</span></code>
|
|
is a function object that takes two arguments <code class="computeroutput"><span class="identifier">a</span></code>
|
|
and <code class="computeroutput"><span class="identifier">b</span></code> and returns <code class="computeroutput"><span class="identifier">a</span> <span class="identifier">op</span> <span class="identifier">b</span></code>.
|
|
</p>
|
|
<p>
|
|
What this means in practice is that you can conveniently negate the result
|
|
of <code class="computeroutput"><span class="identifier">bind</span></code>:
|
|
</p>
|
|
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">remove_if</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">,</span> <span class="special">!</span><span class="identifier">bind</span><span class="special">(&</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">visible</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">));</span> <span class="comment">// remove invisible objects</span>
|
|
</pre>
|
|
<p>
|
|
and compare the result of <code class="computeroutput"><span class="identifier">bind</span></code>
|
|
against a value:
|
|
</p>
|
|
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">find_if</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">,</span> <span class="identifier">bind</span><span class="special">(&</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">name</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">)</span> <span class="special">==</span> <span class="string">"Peter"</span><span class="special">);</span>
|
|
<span class="identifier">std</span><span class="special">::</span><span class="identifier">find_if</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">,</span> <span class="identifier">bind</span><span class="special">(&</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">name</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">)</span> <span class="special">==</span> <span class="string">"Peter"</span> <span class="special">||</span> <span class="identifier">bind</span><span class="special">(&</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">name</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">)</span> <span class="special">==</span> <span class="string">"Paul"</span><span class="special">);</span>
|
|
</pre>
|
|
<p>
|
|
against a <span class="emphasis"><em>placeholder</em></span>:
|
|
</p>
|
|
<pre class="programlisting"><span class="identifier">bind</span><span class="special">(&</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">name</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">)</span> <span class="special">==</span> <span class="identifier">_2</span>
|
|
</pre>
|
|
<p>
|
|
or against another <span class="emphasis"><em>bind expression</em></span>:
|
|
</p>
|
|
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">sort</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">,</span> <span class="identifier">bind</span><span class="special">(&</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">name</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">)</span> <span class="special"><</span> <span class="identifier">bind</span><span class="special">(&</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">name</span><span class="special">,</span> <span class="identifier">_2</span><span class="special">));</span> <span class="comment">// sort by name</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
|
<a name="bind.examples"></a><a class="link" href="bind.html#bind.examples" title="Examples">Examples</a>
|
|
</h2></div></div></div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.examples.using_bind_with_standard_algorit"></a><a class="link" href="bind.html#bind.examples.using_bind_with_standard_algorit" title="Using bind with standard algorithms">Using
|
|
bind with standard algorithms</a>
|
|
</h3></div></div></div>
|
|
<pre class="programlisting"><span class="keyword">class</span> <span class="identifier">image</span><span class="special">;</span>
|
|
|
|
<span class="keyword">class</span> <span class="identifier">animation</span>
|
|
<span class="special">{</span>
|
|
<span class="keyword">public</span><span class="special">:</span>
|
|
<span class="keyword">void</span> <span class="identifier">advance</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">ms</span><span class="special">);</span>
|
|
<span class="keyword">bool</span> <span class="identifier">inactive</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
|
|
<span class="keyword">void</span> <span class="identifier">render</span><span class="special">(</span><span class="identifier">image</span> <span class="special">&</span> <span class="identifier">target</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
|
|
<span class="special">};</span>
|
|
|
|
<span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span><span class="identifier">animation</span><span class="special">></span> <span class="identifier">anims</span><span class="special">;</span>
|
|
|
|
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">C</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">P</span><span class="special">></span> <span class="keyword">void</span> <span class="identifier">erase_if</span><span class="special">(</span><span class="identifier">C</span> <span class="special">&</span> <span class="identifier">c</span><span class="special">,</span> <span class="identifier">P</span> <span class="identifier">pred</span><span class="special">)</span>
|
|
<span class="special">{</span>
|
|
<span class="identifier">c</span><span class="special">.</span><span class="identifier">erase</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">remove_if</span><span class="special">(</span><span class="identifier">c</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">c</span><span class="special">.</span><span class="identifier">end</span><span class="special">(),</span> <span class="identifier">pred</span><span class="special">),</span> <span class="identifier">c</span><span class="special">.</span><span class="identifier">end</span><span class="special">());</span>
|
|
<span class="special">}</span>
|
|
|
|
<span class="keyword">void</span> <span class="identifier">update</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">ms</span><span class="special">)</span>
|
|
<span class="special">{</span>
|
|
<span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span><span class="special">(</span><span class="identifier">anims</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">anims</span><span class="special">.</span><span class="identifier">end</span><span class="special">(),</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(&</span><span class="identifier">animation</span><span class="special">::</span><span class="identifier">advance</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">,</span> <span class="identifier">ms</span><span class="special">));</span>
|
|
<span class="identifier">erase_if</span><span class="special">(</span><span class="identifier">anims</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">mem_fn</span><span class="special">(&</span><span class="identifier">animation</span><span class="special">::</span><span class="identifier">inactive</span><span class="special">));</span>
|
|
<span class="special">}</span>
|
|
|
|
<span class="keyword">void</span> <span class="identifier">render</span><span class="special">(</span><span class="identifier">image</span> <span class="special">&</span> <span class="identifier">target</span><span class="special">)</span>
|
|
<span class="special">{</span>
|
|
<span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span><span class="special">(</span><span class="identifier">anims</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">anims</span><span class="special">.</span><span class="identifier">end</span><span class="special">(),</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(&</span><span class="identifier">animation</span><span class="special">::</span><span class="identifier">render</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ref</span><span class="special">(</span><span class="identifier">target</span><span class="special">)));</span>
|
|
<span class="special">}</span>
|
|
</pre>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.examples.using_bind_with_boost_function"></a><a class="link" href="bind.html#bind.examples.using_bind_with_boost_function" title="Using bind with Boost.Function">Using bind
|
|
with Boost.Function</a>
|
|
</h3></div></div></div>
|
|
<pre class="programlisting"><span class="keyword">class</span> <span class="identifier">button</span>
|
|
<span class="special">{</span>
|
|
<span class="keyword">public</span><span class="special">:</span>
|
|
<a href="../../../../libs/function/index.html" target="_top"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">function</span></code></a><span class="special"><</span><span class="keyword">void</span><span class="special">()></span> <span class="identifier">onClick</span><span class="special">;</span>
|
|
<span class="special">};</span>
|
|
|
|
<span class="keyword">class</span> <span class="identifier">player</span>
|
|
<span class="special">{</span>
|
|
<span class="keyword">public</span><span class="special">:</span>
|
|
<span class="keyword">void</span> <span class="identifier">play</span><span class="special">();</span>
|
|
<span class="keyword">void</span> <span class="identifier">stop</span><span class="special">();</span>
|
|
<span class="special">};</span>
|
|
|
|
<span class="identifier">button</span> <span class="identifier">playButton</span><span class="special">,</span> <span class="identifier">stopButton</span><span class="special">;</span>
|
|
<span class="identifier">player</span> <span class="identifier">thePlayer</span><span class="special">;</span>
|
|
|
|
<span class="keyword">void</span> <span class="identifier">connect</span><span class="special">()</span>
|
|
<span class="special">{</span>
|
|
<span class="identifier">playButton</span><span class="special">.</span><span class="identifier">onClick</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(&</span><span class="identifier">player</span><span class="special">::</span><span class="identifier">play</span><span class="special">,</span> <span class="special">&</span><span class="identifier">thePlayer</span><span class="special">);</span>
|
|
<span class="identifier">stopButton</span><span class="special">.</span><span class="identifier">onClick</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(&</span><span class="identifier">player</span><span class="special">::</span><span class="identifier">stop</span><span class="special">,</span> <span class="special">&</span><span class="identifier">thePlayer</span><span class="special">);</span>
|
|
<span class="special">}</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
|
<a name="bind.limitations"></a><a class="link" href="bind.html#bind.limitations" title="Limitations">Limitations</a>
|
|
</h2></div></div></div>
|
|
<p>
|
|
As a general rule, the function objects generated by <code class="computeroutput"><span class="identifier">bind</span></code>
|
|
take their arguments by reference and cannot, therefore, accept non-const temporaries
|
|
or literal constants. This is an inherent limitation of the C++ language in
|
|
its current (2003) incarnation, known as the <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2002/n1385.htm" target="_top">forwarding
|
|
problem</a>. (It will be fixed in the next standard, usually called C++0x.)
|
|
</p>
|
|
<p>
|
|
The library uses signatures of the form
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> <span class="keyword">void</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">T</span> <span class="special">&</span> <span class="identifier">t</span><span class="special">);</span>
|
|
</pre>
|
|
<p>
|
|
to accept arguments of arbitrary types and pass them on unmodified. As noted,
|
|
this does not work with non-const r-values.
|
|
</p>
|
|
<p>
|
|
On compilers that support partial ordering of function templates, a possible
|
|
solution is to add an overload:
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> <span class="keyword">void</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">T</span> <span class="special">&</span> <span class="identifier">t</span><span class="special">);</span>
|
|
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> <span class="keyword">void</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span> <span class="special">&</span> <span class="identifier">t</span><span class="special">);</span>
|
|
</pre>
|
|
<p>
|
|
Unfortunately, this requires providing 512 overloads for nine arguments, which
|
|
is impractical. The library chooses a small subset: for up to two arguments,
|
|
it provides the const overloads in full, for arities of three and more it provides
|
|
a single additional overload with all of the arguments taken by const reference.
|
|
This covers a reasonable portion of the use cases.
|
|
</p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
|
<a name="bind.faq"></a><a class="link" href="bind.html#bind.faq" title="Frequently Asked Questions">Frequently Asked Questions</a>
|
|
</h2></div></div></div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.faq.why_doesn_t_this_compile"></a><a class="link" href="bind.html#bind.faq.why_doesn_t_this_compile" title="Why doesn't this compile?">Why doesn't this compile?</a>
|
|
</h3></div></div></div>
|
|
<p>
|
|
See the dedicated <a class="link" href="bind.html#bind.troubleshooting" title="Troubleshooting">Troubleshooting section</a>.
|
|
</p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.faq.why_does_this_compile_it_should_"></a><a class="link" href="bind.html#bind.faq.why_does_this_compile_it_should_" title="Why does this compile? It should not.">Why does this
|
|
compile? It should not.</a>
|
|
</h3></div></div></div>
|
|
<p>
|
|
Probably because you used the general <code class="computeroutput"><span class="identifier">bind</span><span class="special"><</span><span class="identifier">R</span><span class="special">>(</span><span class="identifier">f</span><span class="special">,</span> <span class="special">...)</span></code>
|
|
syntax, thereby instructing <code class="computeroutput"><span class="identifier">bind</span></code>
|
|
to not "inspect" f to detect arity and return type errors.
|
|
</p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.faq.Q_forms"></a><a class="link" href="bind.html#bind.faq.Q_forms" title="What is the difference between bind(f, ...) and bind<R>(f, ...)?">What is the difference between <code class="computeroutput"><span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="special">...)</span></code> and
|
|
<code class="computeroutput"><span class="identifier">bind</span><span class="special"><</span><span class="identifier">R</span><span class="special">>(</span><span class="identifier">f</span><span class="special">,</span> <span class="special">...)</span></code>?</a>
|
|
</h3></div></div></div>
|
|
<p>
|
|
The first form instructs <code class="computeroutput"><span class="identifier">bind</span></code>
|
|
to inspect the type of <code class="computeroutput"><span class="identifier">f</span></code>
|
|
in order to determine its arity (number of arguments) and return type. Arity
|
|
errors will be detected at "bind time". This syntax, of course,
|
|
places some requirements on <code class="computeroutput"><span class="identifier">f</span></code>.
|
|
It must be a function, function pointer, member function pointer, or a function
|
|
object that defines a nested type named <code class="computeroutput"><span class="identifier">result_type</span></code>;
|
|
in short, it must be something that <code class="computeroutput"><span class="identifier">bind</span></code>
|
|
can recognize.
|
|
</p>
|
|
<p>
|
|
The second form instructs <code class="computeroutput"><span class="identifier">bind</span></code>
|
|
to not attempt to recognize the type of <code class="computeroutput"><span class="identifier">f</span></code>.
|
|
It is generally used with function objects that do not, or cannot, expose
|
|
<code class="computeroutput"><span class="identifier">result_type</span></code>, but it can also
|
|
be used with nonstandard functions. For example, the current implementation
|
|
does not automatically recognize variable-argument functions like <code class="computeroutput"><span class="identifier">printf</span></code>, so you will have to use <code class="computeroutput"><span class="identifier">bind</span><span class="special"><</span><span class="keyword">int</span><span class="special">>(</span><span class="identifier">printf</span><span class="special">,</span> <span class="special">...)</span></code>. Note
|
|
that an alternative <code class="computeroutput"><span class="identifier">bind</span><span class="special">(</span><span class="identifier">type</span><span class="special"><</span><span class="identifier">R</span><span class="special">>(),</span> <span class="identifier">f</span><span class="special">,</span> <span class="special">...)</span></code>
|
|
syntax is supported for portability reasons.
|
|
</p>
|
|
<p>
|
|
Another important factor to consider is that compilers without partial template
|
|
specialization or function template partial ordering support cannot handle
|
|
the first form when <code class="computeroutput"><span class="identifier">f</span></code> is
|
|
a function object, and in most cases will not handle the second form when
|
|
<code class="computeroutput"><span class="identifier">f</span></code> is a function (pointer)
|
|
or a member function pointer.
|
|
</p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.faq.does_bind_work_with_windows_api_"></a><a class="link" href="bind.html#bind.faq.does_bind_work_with_windows_api_" title="Does bind work with Windows API functions?">Does bind
|
|
work with Windows API functions?</a>
|
|
</h3></div></div></div>
|
|
<p>
|
|
Yes, if you <a class="link" href="bind.html#bind.implementation.stdcall" title="__stdcall, __cdecl, __fastcall, and pascal Support"><code class="computeroutput"><span class="preprocessor">#define</span>
|
|
<span class="identifier">BOOST_BIND_ENABLE_STDCALL</span></code></a>.
|
|
An alternative is to treat the function as a <a class="link" href="bind.html#bind.purpose.with_function_objects" title="Using bind with function objects">generic
|
|
function object</a> and use the <code class="computeroutput"><span class="identifier">bind</span><span class="special"><</span><span class="identifier">R</span><span class="special">>(</span><span class="identifier">f</span><span class="special">,</span> <span class="special">...)</span></code>
|
|
syntax.
|
|
</p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.faq.does_bind_work_with_com_methods"></a><a class="link" href="bind.html#bind.faq.does_bind_work_with_com_methods" title="Does bind work with COM methods?">Does bind work
|
|
with COM methods?</a>
|
|
</h3></div></div></div>
|
|
<p>
|
|
Yes, if you <a class="link" href="bind.html#bind.implementation.stdcall" title="__stdcall, __cdecl, __fastcall, and pascal Support"><code class="computeroutput"><span class="preprocessor">#define</span>
|
|
<span class="identifier">BOOST_MEM_FN_ENABLE_STDCALL</span></code></a>.
|
|
</p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.faq.does_bind_work_with_mac_toolbox_"></a><a class="link" href="bind.html#bind.faq.does_bind_work_with_mac_toolbox_" title="Does bind work with Mac toolbox functions?">Does bind
|
|
work with Mac toolbox functions?</a>
|
|
</h3></div></div></div>
|
|
<p>
|
|
Yes, if you <a class="link" href="bind.html#bind.implementation.stdcall" title="__stdcall, __cdecl, __fastcall, and pascal Support"><code class="computeroutput"><span class="preprocessor">#define</span>
|
|
<span class="identifier">BOOST_BIND_ENABLE_PASCAL</span></code></a>.
|
|
An alternative is to treat the function as a <a class="link" href="bind.html#bind.purpose.with_function_objects" title="Using bind with function objects">generic
|
|
function object</a> and use the <code class="computeroutput"><span class="identifier">bind</span><span class="special"><</span><span class="identifier">R</span><span class="special">>(</span><span class="identifier">f</span><span class="special">,</span> <span class="special">...)</span></code>
|
|
syntax.
|
|
</p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.faq.does_bind_work_with_extern_c_fun"></a><a class="link" href="bind.html#bind.faq.does_bind_work_with_extern_c_fun" title='Does bind work with extern "C" functions?'>Does bind
|
|
work with extern "C" functions?</a>
|
|
</h3></div></div></div>
|
|
<p>
|
|
Sometimes. On some platforms, pointers to extern "C" functions
|
|
are equivalent to "ordinary" function pointers, so they work fine.
|
|
Other platforms treat them as different types. A platform-specific implementation
|
|
of <code class="computeroutput"><span class="identifier">bind</span></code> is expected to handle
|
|
the problem transparently; this implementation does not. As usual, the workaround
|
|
is to treat the function as a <a class="link" href="bind.html#bind.purpose.with_function_objects" title="Using bind with function objects">generic
|
|
function object</a> and use the <code class="computeroutput"><span class="identifier">bind</span><span class="special"><</span><span class="identifier">R</span><span class="special">>(</span><span class="identifier">f</span><span class="special">,</span> <span class="special">...)</span></code>
|
|
syntax.
|
|
</p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.faq.why_doesn_t_bind_automatically_r"></a><a class="link" href="bind.html#bind.faq.why_doesn_t_bind_automatically_r" title="Why doesn't bind automatically recognize nonstandard functions?">Why doesn't
|
|
bind automatically recognize nonstandard functions?</a>
|
|
</h3></div></div></div>
|
|
<p>
|
|
Non-portable extensions, in general, should default to off to prevent vendor
|
|
lock-in. Had the <a class="link" href="bind.html#bind.implementation.stdcall" title="__stdcall, __cdecl, __fastcall, and pascal Support">appropriate
|
|
macros</a> been defined automatically, you could have accidentally taken
|
|
advantage of them without realizing that your code is, perhaps, no longer
|
|
portable. In addition, some compilers have the option to make <code class="computeroutput"><span class="identifier">__stdcall</span></code> (<code class="computeroutput"><span class="identifier">__fastcall</span></code>)
|
|
their default calling convention, in which case no separate support would
|
|
be necessary.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
|
<a name="bind.troubleshooting"></a><a class="link" href="bind.html#bind.troubleshooting" title="Troubleshooting">Troubleshooting</a>
|
|
</h2></div></div></div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.troubleshooting.incorrect_number_of_arguments"></a><a class="link" href="bind.html#bind.troubleshooting.incorrect_number_of_arguments" title="Incorrect number of arguments">Incorrect
|
|
number of arguments</a>
|
|
</h3></div></div></div>
|
|
<p>
|
|
In a <code class="computeroutput"><span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">a1</span><span class="special">,</span> <span class="identifier">a2</span><span class="special">,</span>
|
|
<span class="special">...,</span> <span class="identifier">aN</span><span class="special">)</span></code> expression, the function object <code class="computeroutput"><span class="identifier">f</span></code> must be able to take exactly N arguments.
|
|
This error is normally detected at "bind time"; in other words,
|
|
the compilation error is reported on the line where <code class="computeroutput"><span class="identifier">bind</span><span class="special">()</span></code> is invoked:
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">f</span><span class="special">(</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">int</span><span class="special">);</span>
|
|
|
|
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
|
<span class="special">{</span>
|
|
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="number">1</span><span class="special">);</span> <span class="comment">// error, f takes two arguments</span>
|
|
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="number">1</span><span class="special">,</span> <span class="number">2</span><span class="special">);</span> <span class="comment">// OK</span>
|
|
<span class="special">}</span>
|
|
</pre>
|
|
<p>
|
|
A common variation of this error is to forget that member functions have
|
|
an implicit "this" argument:
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">X</span>
|
|
<span class="special">{</span>
|
|
<span class="keyword">int</span> <span class="identifier">f</span><span class="special">(</span><span class="keyword">int</span><span class="special">);</span>
|
|
<span class="special">}</span>
|
|
|
|
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
|
<span class="special">{</span>
|
|
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(&</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">f</span><span class="special">,</span> <span class="number">1</span><span class="special">);</span> <span class="comment">// error, X::f takes two arguments</span>
|
|
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(&</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">,</span> <span class="number">1</span><span class="special">);</span> <span class="comment">// OK</span>
|
|
<span class="special">}</span>
|
|
</pre>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.troubleshooting.the_function_object_cannot_be_ca"></a><a class="link" href="bind.html#bind.troubleshooting.the_function_object_cannot_be_ca" title="The function object cannot be called with the specified arguments">The
|
|
function object cannot be called with the specified arguments</a>
|
|
</h3></div></div></div>
|
|
<p>
|
|
As in normal function calls, the function object that is bound must be compatible
|
|
with the argument list. The incompatibility will usually be detected by the
|
|
compiler at "call time" and the result is typically an error in
|
|
<code class="computeroutput"><span class="identifier">bind</span><span class="special">.</span><span class="identifier">hpp</span></code> on a line that looks like:
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">return</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">a</span><span class="special">[</span><span class="identifier">a1_</span><span class="special">],</span> <span class="identifier">a</span><span class="special">[</span><span class="identifier">a2_</span><span class="special">]);</span>
|
|
</pre>
|
|
<p>
|
|
An example of this kind of error:
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">f</span><span class="special">(</span><span class="keyword">int</span><span class="special">);</span>
|
|
|
|
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
|
<span class="special">{</span>
|
|
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="string">"incompatible"</span><span class="special">);</span> <span class="comment">// OK so far, no call</span>
|
|
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="string">"incompatible"</span><span class="special">)();</span> <span class="comment">// error, "incompatible" is not an int</span>
|
|
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">);</span> <span class="comment">// OK</span>
|
|
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">)(</span><span class="string">"incompatible"</span><span class="special">);</span> <span class="comment">// error, "incompatible" is not an int</span>
|
|
<span class="special">}</span>
|
|
</pre>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.troubleshooting.accessing_an_argument_that_does_"></a><a class="link" href="bind.html#bind.troubleshooting.accessing_an_argument_that_does_" title="Accessing an argument that does not exist">Accessing
|
|
an argument that does not exist</a>
|
|
</h3></div></div></div>
|
|
<p>
|
|
The placeholder <code class="computeroutput"><span class="identifier">_N</span></code> selects
|
|
the argument at position <code class="computeroutput"><span class="identifier">N</span></code>
|
|
from the argument list passed at "call time." Naturally, it is
|
|
an error to attempt to access beyond the end of this list:
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">f</span><span class="special">(</span><span class="keyword">int</span><span class="special">);</span>
|
|
|
|
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
|
<span class="special">{</span>
|
|
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">);</span> <span class="comment">// OK</span>
|
|
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">)();</span> <span class="comment">// error, there is no argument number 1</span>
|
|
<span class="special">}</span>
|
|
</pre>
|
|
<p>
|
|
The error is usually reported in <code class="computeroutput"><span class="identifier">bind</span><span class="special">.</span><span class="identifier">hpp</span></code>, at
|
|
a line similar to:
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">return</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">a</span><span class="special">[</span><span class="identifier">a1_</span><span class="special">]);</span>
|
|
</pre>
|
|
<p>
|
|
When emulating <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">bind1st</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">a</span><span class="special">)</span></code>, a common mistake of this category is to
|
|
type <code class="computeroutput"><span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">_2</span><span class="special">)</span></code>
|
|
instead of the correct <code class="computeroutput"><span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span>
|
|
<span class="identifier">a</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">)</span></code>.
|
|
</p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.troubleshooting.inappropriate_use_of_bind_f"></a><a class="link" href="bind.html#bind.troubleshooting.inappropriate_use_of_bind_f" title="Inappropriate use of bind(f, ...)">Inappropriate
|
|
use of <code class="computeroutput"><span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="special">...)</span></code></a>
|
|
</h3></div></div></div>
|
|
<p>
|
|
The <code class="computeroutput"><span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">a1</span><span class="special">,</span> <span class="identifier">a2</span><span class="special">,</span>
|
|
<span class="special">...,</span> <span class="identifier">aN</span><span class="special">)</span></code> <a class="link" href="bind.html#bind.faq.Q_forms" title="What is the difference between bind(f, ...) and bind<R>(f, ...)?">form</a>
|
|
causes automatic recognition of the type of <code class="computeroutput"><span class="identifier">f</span></code>.
|
|
It will not work with arbitrary function objects; <code class="computeroutput"><span class="identifier">f</span></code>
|
|
must be a function or a member function pointer.
|
|
</p>
|
|
<p>
|
|
It is possible to use this form with function objects that define <code class="computeroutput"><span class="identifier">result_type</span></code>, but only on compilers that
|
|
support partial specialization and partial ordering. In particular, MSVC
|
|
up to version 7.0 does not support this syntax for function objects.
|
|
</p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.troubleshooting.inappropriate_use_of_bind_r_f"></a><a class="link" href="bind.html#bind.troubleshooting.inappropriate_use_of_bind_r_f" title="Inappropriate use of bind<R>(f, ...)">Inappropriate
|
|
use of <code class="computeroutput"><span class="identifier">bind</span><span class="special"><</span><span class="identifier">R</span><span class="special">>(</span><span class="identifier">f</span><span class="special">,</span> <span class="special">...)</span></code></a>
|
|
</h3></div></div></div>
|
|
<p>
|
|
The <code class="computeroutput"><span class="identifier">bind</span><span class="special"><</span><span class="identifier">R</span><span class="special">>(</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">a1</span><span class="special">,</span> <span class="identifier">a2</span><span class="special">,</span>
|
|
<span class="special">...,</span> <span class="identifier">aN</span><span class="special">)</span></code> <a class="link" href="bind.html#bind.faq.Q_forms" title="What is the difference between bind(f, ...) and bind<R>(f, ...)?">form</a>
|
|
supports arbitrary function objects.
|
|
</p>
|
|
<p>
|
|
It is possible (but not recommended) to use this form with functions or member
|
|
function pointers, but only on compilers that support partial ordering. In
|
|
particular, MSVC up to version 7.0 does not fully support this syntax for
|
|
functions and member function pointers.
|
|
</p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.troubleshooting.binding_a_nonstandard_function"></a><a class="link" href="bind.html#bind.troubleshooting.binding_a_nonstandard_function" title="Binding a nonstandard function">Binding
|
|
a nonstandard function</a>
|
|
</h3></div></div></div>
|
|
<p>
|
|
By default, the <code class="computeroutput"><span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">a1</span><span class="special">,</span> <span class="identifier">a2</span><span class="special">,</span>
|
|
<span class="special">...,</span> <span class="identifier">aN</span><span class="special">)</span></code> <a class="link" href="bind.html#bind.faq.Q_forms" title="What is the difference between bind(f, ...) and bind<R>(f, ...)?">form</a>
|
|
recognizes "ordinary" C++ functions and function pointers. <a class="link" href="bind.html#bind.implementation.stdcall" title="__stdcall, __cdecl, __fastcall, and pascal Support">Functions that use a different calling
|
|
convention</a>, or variable-argument functions such as <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">printf</span></code>,
|
|
do not work. The general <code class="computeroutput"><span class="identifier">bind</span><span class="special"><</span><span class="identifier">R</span><span class="special">>(</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">a1</span><span class="special">,</span> <span class="identifier">a2</span><span class="special">,</span>
|
|
<span class="special">...,</span> <span class="identifier">aN</span><span class="special">)</span></code> <a class="link" href="bind.html#bind.faq.Q_forms" title="What is the difference between bind(f, ...) and bind<R>(f, ...)?">form</a>
|
|
works with nonstandard functions.
|
|
</p>
|
|
<p>
|
|
On some platforms, extern "C" functions, like <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">strcmp</span></code>,
|
|
are not recognized by the short form of <code class="computeroutput"><span class="identifier">bind</span></code>.
|
|
</p>
|
|
<p>
|
|
See also <a class="link" href="bind.html#bind.implementation.stdcall" title="__stdcall, __cdecl, __fastcall, and pascal Support"><code class="computeroutput"><span class="identifier">__stdcall</span></code>
|
|
and <code class="computeroutput"><span class="identifier">pascal</span></code> Support</a>.
|
|
</p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.troubleshooting.binding_an_overloaded_function"></a><a class="link" href="bind.html#bind.troubleshooting.binding_an_overloaded_function" title="Binding an overloaded function">Binding
|
|
an overloaded function</a>
|
|
</h3></div></div></div>
|
|
<p>
|
|
An attempt to bind an overloaded function usually results in an error, as
|
|
there is no way to tell which overload was meant to be bound. This is a common
|
|
problem with member functions with two overloads, const and non-const, as
|
|
in this simplified example:
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">X</span>
|
|
<span class="special">{</span>
|
|
<span class="keyword">int</span><span class="special">&</span> <span class="identifier">get</span><span class="special">();</span>
|
|
<span class="keyword">int</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">get</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
|
|
<span class="special">};</span>
|
|
|
|
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
|
<span class="special">{</span>
|
|
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(&</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">get</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">);</span>
|
|
<span class="special">}</span>
|
|
</pre>
|
|
<p>
|
|
The ambiguity can be resolved manually by casting the (member) function pointer
|
|
to the desired type:
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
|
<span class="special">{</span>
|
|
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span><span class="keyword">static_cast</span><span class="special"><</span> <span class="keyword">int</span> <span class="keyword">const</span><span class="special">&</span> <span class="special">(</span><span class="identifier">X</span><span class="special">::*)</span> <span class="special">()</span> <span class="keyword">const</span> <span class="special">>(&</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">get</span><span class="special">),</span> <span class="identifier">_1</span><span class="special">);</span>
|
|
<span class="special">}</span>
|
|
</pre>
|
|
<p>
|
|
Another, arguably more readable, alternative is to introduce a temporary
|
|
variable:
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
|
<span class="special">{</span>
|
|
<span class="keyword">int</span> <span class="keyword">const</span><span class="special">&</span> <span class="special">(</span><span class="identifier">X</span><span class="special">::*</span><span class="identifier">get</span><span class="special">)</span> <span class="special">()</span> <span class="keyword">const</span> <span class="special">=</span> <span class="special">&</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">get</span><span class="special">;</span>
|
|
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span><span class="identifier">get</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">);</span>
|
|
<span class="special">}</span>
|
|
</pre>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.troubleshooting.modeling_stl_function_object_con"></a><a class="link" href="bind.html#bind.troubleshooting.modeling_stl_function_object_con" title="Modeling STL function object concepts">Modeling
|
|
STL function object concepts</a>
|
|
</h3></div></div></div>
|
|
<p>
|
|
The function objects that are produced by <code class="computeroutput"><span class="identifier">bind</span></code>
|
|
do not model the STL <a href="https://boost.org/sgi/stl/UnaryFunction.html" target="_top"><span class="emphasis"><em>Unary
|
|
Function</em></span></a> or <a href="https://boost.org/sgi/stl/BinaryFunction.html" target="_top"><span class="emphasis"><em>Binary
|
|
Function</em></span></a> concepts, even when the function objects are
|
|
unary or binary operations, because the function object types are missing
|
|
public typedefs <code class="computeroutput"><span class="identifier">result_type</span></code>
|
|
and <code class="computeroutput"><span class="identifier">argument_type</span></code> or <code class="computeroutput"><span class="identifier">first_argument_type</span></code> and <code class="computeroutput"><span class="identifier">second_argument_type</span></code>.
|
|
In cases where these typedefs are desirable, however, the utility function
|
|
<code class="computeroutput"><span class="identifier">make_adaptable</span></code> can be used
|
|
to adapt unary and binary function objects to these concepts. This allows
|
|
unary and binary function objects resulting from <code class="computeroutput"><span class="identifier">bind</span></code>
|
|
to be combined with STL templates such as <a href="http://en.cppreference.com/w/cpp/utility/functional/unary_negate" target="_top"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">unary_negate</span></code></a>
|
|
and <a href="http://en.cppreference.com/w/cpp/utility/functional/binary_negate" target="_top"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">binary_negate</span></code></a>.
|
|
</p>
|
|
<p>
|
|
The <code class="computeroutput"><span class="identifier">make_adaptable</span></code> function
|
|
is defined in <a href="../../../../boost/bind/make_adaptable.hpp" target="_top"><code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">bind</span><span class="special">/</span><span class="identifier">make_adaptable</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a>,
|
|
which must be included explicitly in addition to <a href="../../../../boost/bind.hpp" target="_top"><code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">bind</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a>:
|
|
</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">bind</span><span class="special">/</span><span class="identifier">make_adaptable</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
|
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">F</span><span class="special">></span> <span class="emphasis"><em>unspecified-type</em></span> <span class="identifier">make_adaptable</span><span class="special">(</span><span class="identifier">F</span> <span class="identifier">f</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">F</span><span class="special">></span> <span class="emphasis"><em>unspecified-unary-functional-type</em></span> <span class="identifier">make_adaptable</span><span class="special">(</span><span class="identifier">F</span> <span class="identifier">f</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">F</span><span class="special">></span> <span class="emphasis"><em>unspecified-binary-functional-type</em></span> <span class="identifier">make_adaptable</span><span class="special">(</span><span class="identifier">F</span> <span class="identifier">f</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A3</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">F</span><span class="special">></span> <span class="emphasis"><em>unspecified-ternary-functional-type</em></span> <span class="identifier">make_adaptable</span><span class="special">(</span><span class="identifier">F</span> <span class="identifier">f</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A3</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A4</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">F</span><span class="special">></span> <span class="emphasis"><em>unspecified-4-ary-functional-type</em></span> <span class="identifier">make_adaptable</span><span class="special">(</span><span class="identifier">F</span> <span class="identifier">f</span><span class="special">);</span>
|
|
</pre>
|
|
<p>
|
|
This example shows how to use <code class="computeroutput"><span class="identifier">make_adaptable</span></code>
|
|
to make a predicate for "is not a space":
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">typedef</span> <span class="keyword">char</span> <span class="identifier">char_t</span><span class="special">;</span>
|
|
<span class="identifier">std</span><span class="special">::</span><span class="identifier">locale</span> <span class="identifier">loc</span><span class="special">(</span><span class="string">""</span><span class="special">);</span>
|
|
<span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">ctype</span><span class="special"><</span><span class="identifier">char_t</span><span class="special">>&</span> <span class="identifier">ct</span> <span class="special">=</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">use_facet</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">ctype</span><span class="special"><</span><span class="identifier">char_t</span><span class="special">></span> <span class="special">>(</span><span class="identifier">loc</span><span class="special">);</span>
|
|
|
|
<span class="keyword">auto</span> <span class="identifier">isntspace</span> <span class="special">=</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">not1</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">make_adaptable</span><span class="special"><</span><span class="keyword">bool</span><span class="special">,</span> <span class="identifier">char_t</span><span class="special">>(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(&</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">ctype</span><span class="special"><</span><span class="identifier">char_t</span><span class="special">>::</span><span class="identifier">is</span><span class="special">,</span> <span class="special">&</span><span class="identifier">ct</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">ctype_base</span><span class="special">::</span><span class="identifier">space</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">)));</span>
|
|
</pre>
|
|
<p>
|
|
In this example, <code class="computeroutput"><span class="identifier">bind</span></code> creates
|
|
the "is a space" (unary) predicate. It is then passed to <code class="computeroutput"><span class="identifier">make_adaptable</span></code> so that a function object
|
|
modeling the <span class="emphasis"><em>Unary Function</em></span> concept can be created,
|
|
serving as the argument to <a href="http://en.cppreference.com/w/cpp/utility/functional/not1" target="_top"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">not1</span></code></a>.
|
|
</p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.troubleshooting.const_in_signatures"></a><a class="link" href="bind.html#bind.troubleshooting.const_in_signatures" title="const in signatures"><code class="computeroutput"><span class="keyword">const</span></code> in signatures</a>
|
|
</h3></div></div></div>
|
|
<p>
|
|
Some compilers, including MSVC 6.0 and Borland C++ 5.5.1, have problems with
|
|
the top-level <code class="computeroutput"><span class="keyword">const</span></code> in function
|
|
signatures:
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">f</span><span class="special">(</span><span class="keyword">int</span> <span class="keyword">const</span><span class="special">);</span>
|
|
|
|
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
|
<span class="special">{</span>
|
|
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="number">1</span><span class="special">);</span> <span class="comment">// error</span>
|
|
<span class="special">}</span>
|
|
</pre>
|
|
<p>
|
|
Workaround: remove the <code class="computeroutput"><span class="keyword">const</span></code>
|
|
qualifier from the argument.
|
|
</p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.troubleshooting.msvc_specific_using_boost_bind"></a><a class="link" href="bind.html#bind.troubleshooting.msvc_specific_using_boost_bind" title="MSVC specific: using boost::bind;">MSVC
|
|
specific: <code class="computeroutput"><span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">;</span></code></a>
|
|
</h3></div></div></div>
|
|
<p>
|
|
On MSVC (up to version 7.0), when <code class="computeroutput"><span class="identifier">boostbind</span></code>
|
|
is brought into scope with an using declaration:
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">;</span>
|
|
</pre>
|
|
<p>
|
|
the syntax <code class="computeroutput"><span class="identifier">bind</span><span class="special"><</span><span class="identifier">R</span><span class="special">>(</span><span class="identifier">f</span><span class="special">,</span> <span class="special">...)</span></code>
|
|
does not work. Workaround: either use the qualified name, <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span></code>,
|
|
or use an using directive instead:
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">;</span>
|
|
</pre>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.troubleshooting.msvc_specific_class_templates_sh"></a><a class="link" href="bind.html#bind.troubleshooting.msvc_specific_class_templates_sh" title="MSVC specific: class templates shadow function templates">MSVC
|
|
specific: class templates shadow function templates</a>
|
|
</h3></div></div></div>
|
|
<p>
|
|
On MSVC (up to version 7.0), a nested class template named <code class="computeroutput"><span class="identifier">bind</span></code> will shadow the function template
|
|
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span></code>, breaking the <code class="computeroutput"><span class="identifier">bind</span><span class="special"><</span><span class="identifier">R</span><span class="special">>(</span><span class="identifier">f</span><span class="special">,</span> <span class="special">...)</span></code>syntax.
|
|
Unfortunately, some libraries contain nested class templates named <code class="computeroutput"><span class="identifier">bind</span></code> (ironically, such code is often an
|
|
MSVC specific workaround.)
|
|
</p>
|
|
<p>
|
|
The workaround is to use the alternative <code class="computeroutput"><span class="identifier">bind</span><span class="special">(</span><span class="identifier">type</span><span class="special"><</span><span class="identifier">R</span><span class="special">>(),</span> <span class="identifier">f</span><span class="special">,</span> <span class="special">...)</span></code>
|
|
syntax.
|
|
</p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.troubleshooting.msvc_specific_in_signatures_trea"></a><a class="link" href="bind.html#bind.troubleshooting.msvc_specific_in_signatures_trea" title="MSVC specific: ... in signatures treated as type">MSVC
|
|
specific: <code class="computeroutput"><span class="special">...</span></code> in signatures treated
|
|
as type</a>
|
|
</h3></div></div></div>
|
|
<p>
|
|
MSVC (up to version 7.0) treats the ellipsis in a variable argument function
|
|
(such as <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">printf</span></code>) as a type. Therefore, it will accept
|
|
the (incorrect in the current implementation) form:
|
|
</p>
|
|
<pre class="programlisting"><span class="identifier">bind</span><span class="special">(</span><span class="identifier">printf</span><span class="special">,</span> <span class="string">"%s\n"</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">);</span>
|
|
</pre>
|
|
<p>
|
|
and will reject the correct version:
|
|
</p>
|
|
<pre class="programlisting"><span class="identifier">bind</span><span class="special"><</span><span class="keyword">int</span><span class="special">>(</span><span class="identifier">printf</span><span class="special">,</span> <span class="string">"%s\n"</span><span class="special">,</span> <span class="identifier">_1</span><span class="special">);</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
|
<a name="bind.interface"></a><a class="link" href="bind.html#bind.interface" title="Interface">Interface</a>
|
|
</h2></div></div></div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.interface.synopsys"></a><a class="link" href="bind.html#bind.interface.synopsys" title="Synopsis">Synopsis</a>
|
|
</h3></div></div></div>
|
|
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span>
|
|
<span class="special">{</span>
|
|
<span class="comment">// no arguments</span>
|
|
|
|
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">F</span><span class="special">></span> <span class="emphasis"><em>unspecified-1</em></span> <a class="link" href="bind.html#bind_1"><code class="computeroutput"><span class="identifier">bind</span></code></a><span class="special">(</span><span class="identifier">F</span> <span class="identifier">f</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">F</span><span class="special">></span> <span class="emphasis"><em>unspecified-1-1</em></span> <a class="link" href="bind.html#bind_1_1"><code class="computeroutput"><span class="identifier">bind</span></code></a><span class="special">(</span><span class="identifier">F</span> <span class="identifier">f</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">></span> <span class="emphasis"><em>unspecified-2</em></span> <a class="link" href="bind.html#bind_2"><code class="computeroutput"><span class="identifier">bind</span></code></a><span class="special">(</span><span class="identifier">R</span> <span class="special">(*</span><span class="identifier">f</span><span class="special">)</span> <span class="special">());</span>
|
|
|
|
<span class="comment">// one argument</span>
|
|
|
|
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">F</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">></span> <span class="emphasis"><em>unspecified-3</em></span> <a class="link" href="bind.html#bind_3"><code class="computeroutput"><span class="identifier">bind</span></code></a><span class="special">(</span><span class="identifier">F</span> <span class="identifier">f</span><span class="special">,</span> <span class="identifier">A1</span> <span class="identifier">a1</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">F</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">></span> <span class="emphasis"><em>unspecified-3-1</em></span> <a class="link" href="bind.html#bind_3_1"><code class="computeroutput"><span class="identifier">bind</span></code></a><span class="special">(</span><span class="identifier">F</span> <span class="identifier">f</span><span class="special">,</span> <span class="identifier">A1</span> <span class="identifier">a1</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">B1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">></span> <span class="emphasis"><em>unspecified-4</em></span> <a class="link" href="bind.html#bind_4"><code class="computeroutput"><span class="identifier">bind</span></code></a><span class="special">(</span><span class="identifier">R</span> <span class="special">(*</span><span class="identifier">f</span><span class="special">)</span> <span class="special">(</span><span class="identifier">B1</span><span class="special">),</span> <span class="identifier">A1</span> <span class="identifier">a1</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">></span> <span class="emphasis"><em>unspecified-5</em></span> <a class="link" href="bind.html#bind_5"><code class="computeroutput"><span class="identifier">bind</span></code></a><span class="special">(</span><span class="identifier">R</span> <span class="special">(</span><span class="identifier">T</span><span class="special">::*</span><span class="identifier">f</span><span class="special">)</span> <span class="special">(),</span> <span class="identifier">A1</span> <span class="identifier">a1</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">></span> <span class="emphasis"><em>unspecified-6</em></span> <a class="link" href="bind.html#bind_6"><code class="computeroutput"><span class="identifier">bind</span></code></a><span class="special">(</span><span class="identifier">R</span> <span class="special">(</span><span class="identifier">T</span><span class="special">::*</span><span class="identifier">f</span><span class="special">)</span> <span class="special">()</span> <span class="keyword">const</span><span class="special">,</span> <span class="identifier">A1</span> <span class="identifier">a1</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">></span> <span class="emphasis"><em>unspecified-6-1</em></span> <a class="link" href="bind.html#bind_6_1"><code class="computeroutput"><span class="identifier">bind</span></code></a><span class="special">(</span><span class="identifier">R</span> <span class="identifier">T</span><span class="special">::*</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">A1</span> <span class="identifier">a1</span><span class="special">);</span>
|
|
|
|
<span class="comment">// two arguments</span>
|
|
|
|
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">F</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A2</span><span class="special">></span> <span class="emphasis"><em>unspecified-7</em></span> <a class="link" href="bind.html#bind_7"><code class="computeroutput"><span class="identifier">bind</span></code></a><span class="special">(</span><span class="identifier">F</span> <span class="identifier">f</span><span class="special">,</span> <span class="identifier">A1</span> <span class="identifier">a1</span><span class="special">,</span> <span class="identifier">A2</span> <span class="identifier">a2</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">F</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A2</span><span class="special">></span> <span class="emphasis"><em>unspecified-7-1</em></span> <a class="link" href="bind.html#bind_7_1"><code class="computeroutput"><span class="identifier">bind</span></code></a><span class="special">(</span><span class="identifier">F</span> <span class="identifier">f</span><span class="special">,</span> <span class="identifier">A1</span> <span class="identifier">a1</span><span class="special">,</span> <span class="identifier">A2</span> <span class="identifier">a2</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">B1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">B2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A2</span><span class="special">></span> <span class="emphasis"><em>unspecified-8</em></span> <a class="link" href="bind.html#bind_8"><code class="computeroutput"><span class="identifier">bind</span></code></a><span class="special">(</span><span class="identifier">R</span> <span class="special">(*</span><span class="identifier">f</span><span class="special">)</span> <span class="special">(</span><span class="identifier">B1</span><span class="special">,</span> <span class="identifier">B2</span><span class="special">),</span> <span class="identifier">A1</span> <span class="identifier">a1</span><span class="special">,</span> <span class="identifier">A2</span> <span class="identifier">a2</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">B1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A2</span><span class="special">></span> <span class="emphasis"><em>unspecified-9</em></span> <a class="link" href="bind.html#bind_9"><code class="computeroutput"><span class="identifier">bind</span></code></a><span class="special">(</span><span class="identifier">R</span> <span class="special">(</span><span class="identifier">T</span><span class="special">::*</span><span class="identifier">f</span><span class="special">)</span> <span class="special">(</span><span class="identifier">B1</span><span class="special">),</span> <span class="identifier">A1</span> <span class="identifier">a1</span><span class="special">,</span> <span class="identifier">A2</span> <span class="identifier">a2</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">B1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A2</span><span class="special">></span> <span class="emphasis"><em>unspecified-10</em></span> <a class="link" href="bind.html#bind_10"><code class="computeroutput"><span class="identifier">bind</span></code></a><span class="special">(</span><span class="identifier">R</span> <span class="special">(</span><span class="identifier">T</span><span class="special">::*</span><span class="identifier">f</span><span class="special">)</span> <span class="special">(</span><span class="identifier">B1</span><span class="special">)</span> <span class="keyword">const</span><span class="special">,</span> <span class="identifier">A1</span> <span class="identifier">a1</span><span class="special">,</span> <span class="identifier">A2</span> <span class="identifier">a2</span><span class="special">);</span>
|
|
|
|
<span class="comment">// implementation defined number of additional overloads for more arguments</span>
|
|
<span class="special">}</span>
|
|
|
|
<span class="keyword">namespace</span>
|
|
<span class="special">{</span>
|
|
<span class="emphasis"><em>unspecified-placeholder-type-1</em></span> <span class="identifier">_1</span><span class="special">;</span>
|
|
|
|
<span class="emphasis"><em>unspecified-placeholder-type-2</em></span> <span class="identifier">_2</span><span class="special">;</span>
|
|
|
|
<span class="emphasis"><em>unspecified-placeholder-type-3</em></span> <span class="identifier">_3</span><span class="special">;</span>
|
|
|
|
<span class="comment">// implementation defined number of additional placeholder definitions</span>
|
|
<span class="special">}</span>
|
|
</pre>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.interface.common_requirements"></a><a class="link" href="bind.html#bind.interface.common_requirements" title="Common requirements">Common requirements</a>
|
|
</h3></div></div></div>
|
|
<p>
|
|
All <span class="emphasis"><em>unspecified-N</em></span> types returned by <code class="computeroutput"><span class="identifier">bind</span></code>
|
|
are <span class="emphasis"><em>CopyConstructible</em></span>. <span class="emphasis"><em>unspecified-N</em></span><code class="computeroutput"><span class="special">::</span><span class="identifier">result_type</span></code>
|
|
is defined as the return type of <span class="emphasis"><em>unspecified-N</em></span><code class="computeroutput"><span class="special">::</span><span class="keyword">operator</span><span class="special">()</span></code>.
|
|
</p>
|
|
<p>
|
|
All <span class="emphasis"><em>unspecified-placeholder-N</em></span> types are <span class="emphasis"><em>CopyConstructible</em></span>.
|
|
Their copy constructors do not throw exceptions.
|
|
</p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.interface.common_definitions"></a><a class="link" href="bind.html#bind.interface.common_definitions" title="Common definitions">Common definitions</a>
|
|
</h3></div></div></div>
|
|
<p>
|
|
The function μ<code class="computeroutput"><span class="special">(</span><span class="identifier">x</span><span class="special">,</span> <span class="identifier">v1</span><span class="special">,</span>
|
|
<span class="identifier">v2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">vm</span><span class="special">)</span></code>, where <code class="computeroutput"><span class="identifier">m</span></code>
|
|
is a nonnegative integer, is defined as:
|
|
</p>
|
|
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
|
<li class="listitem">
|
|
<code class="computeroutput"><span class="identifier">x</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span></code>,
|
|
when <code class="computeroutput"><span class="identifier">x</span></code> is of type <a href="../../../../libs/core/doc/html/core/ref.html" target="_top"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">reference_wrapper</span></code></a><code class="computeroutput"><span class="special"><</span><span class="identifier">T</span><span class="special">></span></code> for some type <code class="computeroutput"><span class="identifier">T</span></code>;
|
|
</li>
|
|
<li class="listitem">
|
|
<code class="computeroutput"><span class="identifier">vk</span></code>, when <code class="computeroutput"><span class="identifier">x</span></code> is (a copy of) the placeholder <span class="emphasis"><em>_k</em></span>
|
|
for some positive integer <span class="emphasis"><em>k</em></span>;
|
|
</li>
|
|
<li class="listitem">
|
|
<code class="computeroutput"><span class="identifier">x</span><span class="special">(</span><span class="identifier">v1</span><span class="special">,</span> <span class="identifier">v2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">vm</span><span class="special">)</span></code> when <code class="computeroutput"><span class="identifier">x</span></code>
|
|
is (a copy of) a function object returned by <code class="computeroutput"><span class="identifier">bind</span></code>;
|
|
</li>
|
|
<li class="listitem">
|
|
<code class="computeroutput"><span class="identifier">x</span></code> otherwise.
|
|
</li>
|
|
</ul></div>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.interface.bind"></a><a class="link" href="bind.html#bind.interface.bind" title="bind"><code class="computeroutput"><span class="identifier">bind</span></code></a>
|
|
</h3></div></div></div>
|
|
<a name="bind_1"></a><pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">F</span><span class="special">></span> <span class="emphasis"><em>unspecified-1</em></span> <span class="identifier">bind</span><span class="special">(</span><span class="identifier">F</span> <span class="identifier">f</span><span class="special">)</span>
|
|
</pre>
|
|
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
|
<li class="listitem">
|
|
<span class="emphasis"><em>Returns:</em></span> A function object λ such that the
|
|
expression λ<code class="computeroutput"><span class="special">(</span><span class="identifier">v1</span><span class="special">,</span> <span class="identifier">v2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">vm</span><span class="special">)</span></code>
|
|
is equivalent to <code class="computeroutput"><span class="identifier">f</span><span class="special">()</span></code>,
|
|
implicitly converted to <code class="computeroutput"><span class="identifier">R</span></code>.
|
|
</li>
|
|
<li class="listitem">
|
|
<span class="emphasis"><em>Throws:</em></span> Nothing unless the copy constructor of
|
|
<code class="computeroutput"><span class="identifier">F</span></code> throws an exception.
|
|
</li>
|
|
</ul></div>
|
|
<a name="bind_1_1"></a><pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">F</span><span class="special">></span> <span class="emphasis"><em>unspecified-1-1</em></span> <span class="identifier">bind</span><span class="special">(</span><span class="identifier">F</span> <span class="identifier">f</span><span class="special">)</span>
|
|
</pre>
|
|
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
|
<li class="listitem">
|
|
<span class="emphasis"><em>Effects:</em></span> Equivalent to <code class="computeroutput"><span class="identifier">bind</span><span class="special"><</span><span class="keyword">typename</span>
|
|
<span class="identifier">F</span><span class="special">::</span><span class="identifier">result_type</span><span class="special">,</span>
|
|
<span class="identifier">F</span><span class="special">>(</span><span class="identifier">f</span><span class="special">)</span></code>.
|
|
</li>
|
|
<li class="listitem">
|
|
<span class="emphasis"><em>Notes:</em></span> Implementations are allowed to infer the
|
|
return type of <code class="computeroutput"><span class="identifier">f</span></code> via
|
|
other means as an extension, without relying on the <code class="computeroutput"><span class="identifier">result_type</span></code>
|
|
member.
|
|
</li>
|
|
</ul></div>
|
|
<a name="bind_2"></a><pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">></span> <span class="emphasis"><em>unspecified-2</em></span> <span class="identifier">bind</span><span class="special">(</span><span class="identifier">R</span> <span class="special">(*</span><span class="identifier">f</span><span class="special">)</span> <span class="special">())</span>
|
|
</pre>
|
|
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
|
<li class="listitem">
|
|
<span class="emphasis"><em>Returns:</em></span> A function object λ such that the
|
|
expression λ<code class="computeroutput"><span class="special">(</span><span class="identifier">v1</span><span class="special">,</span> <span class="identifier">v2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">vm</span><span class="special">)</span></code>
|
|
is equivalent to <code class="computeroutput"><span class="identifier">f</span><span class="special">()</span></code>.
|
|
</li>
|
|
<li class="listitem">
|
|
<span class="emphasis"><em>Throws:</em></span> Nothing.
|
|
</li>
|
|
</ul></div>
|
|
<a name="bind_3"></a><pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">F</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">></span> <span class="emphasis"><em>unspecified-3</em></span> <span class="identifier">bind</span><span class="special">(</span><span class="identifier">F</span> <span class="identifier">f</span><span class="special">,</span> <span class="identifier">A1</span> <span class="identifier">a1</span><span class="special">)</span>
|
|
</pre>
|
|
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
|
<li class="listitem">
|
|
<span class="emphasis"><em>Returns:</em></span> A function object λ such that the
|
|
expression λ<code class="computeroutput"><span class="special">(</span><span class="identifier">v1</span><span class="special">,</span> <span class="identifier">v2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">vm</span><span class="special">)</span></code>
|
|
is equivalent to <code class="computeroutput"><span class="identifier">f</span><span class="special">(</span></code>μ<code class="computeroutput"><span class="special">(</span><span class="identifier">a1</span><span class="special">,</span> <span class="identifier">v1</span><span class="special">,</span> <span class="identifier">v2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">vm</span><span class="special">))</span></code>,
|
|
implicitly converted to <code class="computeroutput"><span class="identifier">R</span></code>.
|
|
</li>
|
|
<li class="listitem">
|
|
<span class="emphasis"><em>Throws:</em></span> Nothing unless the copy constructors of
|
|
<code class="computeroutput"><span class="identifier">F</span></code> or <code class="computeroutput"><span class="identifier">A1</span></code>
|
|
throw an exception.
|
|
</li>
|
|
</ul></div>
|
|
<a name="bind_3_1"></a><pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">F</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">></span> <span class="emphasis"><em>unspecified-3-1</em></span> <span class="identifier">bind</span><span class="special">(</span><span class="identifier">F</span> <span class="identifier">f</span><span class="special">,</span> <span class="identifier">A1</span> <span class="identifier">a1</span><span class="special">)</span>
|
|
</pre>
|
|
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
|
<li class="listitem">
|
|
<span class="emphasis"><em>Effects:</em></span> Equivalent to <code class="computeroutput"><span class="identifier">bind</span><span class="special"><</span><span class="keyword">typename</span>
|
|
<span class="identifier">F</span><span class="special">::</span><span class="identifier">result_type</span><span class="special">,</span>
|
|
<span class="identifier">F</span><span class="special">,</span>
|
|
<span class="identifier">A1</span><span class="special">>(</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">a1</span><span class="special">)</span></code>.
|
|
</li>
|
|
<li class="listitem">
|
|
<span class="emphasis"><em>Notes:</em></span> Implementations are allowed to infer the
|
|
return type of <code class="computeroutput"><span class="identifier">f</span></code> via
|
|
other means as an extension, without relying on the <code class="computeroutput"><span class="identifier">result_type</span></code>
|
|
member.
|
|
</li>
|
|
</ul></div>
|
|
<a name="bind_4"></a><pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">B1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">></span> <span class="emphasis"><em>unspecified-4</em></span> <span class="identifier">bind</span><span class="special">(</span><span class="identifier">R</span> <span class="special">(*</span><span class="identifier">f</span><span class="special">)</span> <span class="special">(</span><span class="identifier">B1</span><span class="special">),</span> <span class="identifier">A1</span> <span class="identifier">a1</span><span class="special">)</span>
|
|
</pre>
|
|
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
|
<li class="listitem">
|
|
<span class="emphasis"><em>Returns:</em></span> A function object λ such that the
|
|
expression λ<code class="computeroutput"><span class="special">(</span><span class="identifier">v1</span><span class="special">,</span> <span class="identifier">v2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">vm</span><span class="special">)</span></code>
|
|
is equivalent to <code class="computeroutput"><span class="identifier">f</span><span class="special">(</span></code>μ<code class="computeroutput"><span class="special">(</span><span class="identifier">a1</span><span class="special">,</span> <span class="identifier">v1</span><span class="special">,</span> <span class="identifier">v2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">vm</span><span class="special">))</span></code>.
|
|
</li>
|
|
<li class="listitem">
|
|
<span class="emphasis"><em>Throws:</em></span> Nothing unless the copy constructor of
|
|
<code class="computeroutput"><span class="identifier">A1</span></code> throws an exception.
|
|
</li>
|
|
</ul></div>
|
|
<a name="bind_5"></a><pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">></span> <span class="emphasis"><em>unspecified-5</em></span> <span class="identifier">bind</span><span class="special">(</span><span class="identifier">R</span> <span class="special">(</span><span class="identifier">T</span><span class="special">::*</span><span class="identifier">f</span><span class="special">)</span> <span class="special">(),</span> <span class="identifier">A1</span> <span class="identifier">a1</span><span class="special">)</span>
|
|
</pre>
|
|
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
|
|
<span class="emphasis"><em>Effects:</em></span> Equivalent to <code class="computeroutput"><span class="identifier">bind</span><span class="special"><</span><span class="identifier">R</span><span class="special">>(</span></code><a href="../../../../libs/bind/mem_fn.html" target="_top"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">mem_fn</span></code></a><code class="computeroutput"><span class="special">(</span><span class="identifier">f</span><span class="special">),</span> <span class="identifier">a1</span><span class="special">)</span></code>.
|
|
</li></ul></div>
|
|
<a name="bind_6"></a><pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">></span> <span class="emphasis"><em>unspecified-6</em></span> <span class="identifier">bind</span><span class="special">(</span><span class="identifier">R</span> <span class="special">(</span><span class="identifier">T</span><span class="special">::*</span><span class="identifier">f</span><span class="special">)</span> <span class="special">()</span> <span class="keyword">const</span><span class="special">,</span> <span class="identifier">A1</span> <span class="identifier">a1</span><span class="special">)</span>
|
|
</pre>
|
|
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
|
|
<span class="emphasis"><em>Effects:</em></span> Equivalent to <code class="computeroutput"><span class="identifier">bind</span><span class="special"><</span><span class="identifier">R</span><span class="special">>(</span></code><a href="../../../../libs/bind/mem_fn.html" target="_top"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">mem_fn</span></code></a><code class="computeroutput"><span class="special">(</span><span class="identifier">f</span><span class="special">),</span> <span class="identifier">a1</span><span class="special">)</span></code>.
|
|
</li></ul></div>
|
|
<a name="bind_6_1"></a><pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">></span> <span class="emphasis"><em>unspecified-6-1</em></span> <span class="identifier">bind</span><span class="special">(</span><span class="identifier">R</span> <span class="identifier">T</span><span class="special">::*</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">A1</span> <span class="identifier">a1</span><span class="special">)</span>
|
|
</pre>
|
|
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
|
|
<span class="emphasis"><em>Effects:</em></span> Equivalent to <code class="computeroutput"><span class="identifier">bind</span><span class="special"><</span><span class="identifier">R</span><span class="special">>(</span></code><a href="../../../../libs/bind/mem_fn.html" target="_top"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">mem_fn</span></code></a><code class="computeroutput"><span class="special">(</span><span class="identifier">f</span><span class="special">),</span> <span class="identifier">a1</span><span class="special">)</span></code>.
|
|
</li></ul></div>
|
|
<a name="bind_7"></a><pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">F</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A2</span><span class="special">></span> <span class="emphasis"><em>unspecified-7</em></span> <span class="identifier">bind</span><span class="special">(</span><span class="identifier">F</span> <span class="identifier">f</span><span class="special">,</span> <span class="identifier">A1</span> <span class="identifier">a1</span><span class="special">,</span> <span class="identifier">A2</span> <span class="identifier">a2</span><span class="special">)</span>
|
|
</pre>
|
|
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
|
<li class="listitem">
|
|
<span class="emphasis"><em>Returns:</em></span> A function object λ such that the
|
|
expression λ<code class="computeroutput"><span class="special">(</span><span class="identifier">v1</span><span class="special">,</span> <span class="identifier">v2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">vm</span><span class="special">)</span></code>
|
|
is equivalent to <code class="computeroutput"><span class="identifier">f</span><span class="special">(</span></code>μ<code class="computeroutput"><span class="special">(</span><span class="identifier">a1</span><span class="special">,</span> <span class="identifier">v1</span><span class="special">,</span> <span class="identifier">v2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">vm</span><span class="special">),</span> </code>μ<code class="computeroutput"><span class="special">(</span><span class="identifier">a2</span><span class="special">,</span> <span class="identifier">v1</span><span class="special">,</span> <span class="identifier">v2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">vm</span><span class="special">))</span></code>,
|
|
implicitly converted to <code class="computeroutput"><span class="identifier">R</span></code>.
|
|
</li>
|
|
<li class="listitem">
|
|
<span class="emphasis"><em>Throws:</em></span> Nothing unless the copy constructors of
|
|
<code class="computeroutput"><span class="identifier">F</span></code>, <code class="computeroutput"><span class="identifier">A1</span></code>
|
|
or <code class="computeroutput"><span class="identifier">A2</span></code> throw an exception.
|
|
</li>
|
|
</ul></div>
|
|
<a name="bind_7_1"></a><pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">F</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A2</span><span class="special">></span> <span class="emphasis"><em>unspecified-7-1</em></span> <span class="identifier">bind</span><span class="special">(</span><span class="identifier">F</span> <span class="identifier">f</span><span class="special">,</span> <span class="identifier">A1</span> <span class="identifier">a1</span><span class="special">,</span> <span class="identifier">A2</span> <span class="identifier">a2</span><span class="special">)</span>
|
|
</pre>
|
|
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
|
<li class="listitem">
|
|
<span class="emphasis"><em>Effects:</em></span> Equivalent to <code class="computeroutput"><span class="identifier">bind</span><span class="special"><</span><span class="keyword">typename</span>
|
|
<span class="identifier">F</span><span class="special">::</span><span class="identifier">result_type</span><span class="special">,</span>
|
|
<span class="identifier">F</span><span class="special">,</span>
|
|
<span class="identifier">A1</span><span class="special">,</span>
|
|
<span class="identifier">A2</span><span class="special">>(</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">a1</span><span class="special">,</span> <span class="identifier">a2</span><span class="special">)</span></code>.
|
|
</li>
|
|
<li class="listitem">
|
|
<span class="emphasis"><em>Notes:</em></span> Implementations are allowed to infer the
|
|
return type of <code class="computeroutput"><span class="identifier">f</span></code> via
|
|
other means as an extension, without relying on the <code class="computeroutput"><span class="identifier">result_type</span></code>
|
|
member.
|
|
</li>
|
|
</ul></div>
|
|
<a name="bind_8"></a><pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">B1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">B2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A2</span><span class="special">></span> <span class="emphasis"><em>unspecified-8</em></span> <span class="identifier">bind</span><span class="special">(</span><span class="identifier">R</span> <span class="special">(*</span><span class="identifier">f</span><span class="special">)</span> <span class="special">(</span><span class="identifier">B1</span><span class="special">,</span> <span class="identifier">B2</span><span class="special">),</span> <span class="identifier">A1</span> <span class="identifier">a1</span><span class="special">,</span> <span class="identifier">A2</span> <span class="identifier">a2</span><span class="special">)</span>
|
|
</pre>
|
|
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
|
<li class="listitem">
|
|
<span class="emphasis"><em>Returns:</em></span> A function object λ such that the
|
|
expression λ<code class="computeroutput"><span class="special">(</span><span class="identifier">v1</span><span class="special">,</span> <span class="identifier">v2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">vm</span><span class="special">)</span></code>
|
|
is equivalent to <code class="computeroutput"><span class="identifier">f</span><span class="special">(</span></code>μ<code class="computeroutput"><span class="special">(</span><span class="identifier">a1</span><span class="special">,</span> <span class="identifier">v1</span><span class="special">,</span> <span class="identifier">v2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">vm</span><span class="special">),</span> </code>μ<code class="computeroutput"><span class="special">(</span><span class="identifier">a2</span><span class="special">,</span> <span class="identifier">v1</span><span class="special">,</span> <span class="identifier">v2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">vm</span><span class="special">))</span></code>.
|
|
</li>
|
|
<li class="listitem">
|
|
<span class="emphasis"><em>Throws:</em></span> Nothing unless the copy constructors of
|
|
<code class="computeroutput"><span class="identifier">A1</span></code> or <code class="computeroutput"><span class="identifier">A2</span></code>
|
|
throw an exception.
|
|
</li>
|
|
</ul></div>
|
|
<a name="bind_9"></a><pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">B1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A2</span><span class="special">></span> <span class="emphasis"><em>unspecified-9</em></span> <span class="identifier">bind</span><span class="special">(</span><span class="identifier">R</span> <span class="special">(</span><span class="identifier">T</span><span class="special">::*</span><span class="identifier">f</span><span class="special">)</span> <span class="special">(</span><span class="identifier">B1</span><span class="special">),</span> <span class="identifier">A1</span> <span class="identifier">a1</span><span class="special">,</span> <span class="identifier">A2</span> <span class="identifier">a2</span><span class="special">)</span>
|
|
</pre>
|
|
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
|
|
<span class="emphasis"><em>Effects:</em></span> Equivalent to <code class="computeroutput"><span class="identifier">bind</span><span class="special"><</span><span class="identifier">R</span><span class="special">>(</span></code><a href="../../../../libs/bind/mem_fn.html" target="_top"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">mem_fn</span></code></a><code class="computeroutput"><span class="special">(</span><span class="identifier">f</span><span class="special">),</span> <span class="identifier">a1</span><span class="special">,</span> <span class="identifier">a2</span><span class="special">)</span></code>.
|
|
</li></ul></div>
|
|
<a name="bind_10"></a><pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">B1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A2</span><span class="special">></span> <span class="emphasis"><em>unspecified-10</em></span> <span class="identifier">bind</span><span class="special">(</span><span class="identifier">R</span> <span class="special">(</span><span class="identifier">T</span><span class="special">::*</span><span class="identifier">f</span><span class="special">)</span> <span class="special">(</span><span class="identifier">B1</span><span class="special">)</span> <span class="keyword">const</span><span class="special">,</span> <span class="identifier">A1</span> <span class="identifier">a1</span><span class="special">,</span> <span class="identifier">A2</span> <span class="identifier">a2</span><span class="special">)</span>
|
|
</pre>
|
|
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
|
|
<span class="emphasis"><em>Effects:</em></span> Equivalent to <code class="computeroutput"><span class="identifier">bind</span><span class="special"><</span><span class="identifier">R</span><span class="special">>(</span></code><a href="../../../../libs/bind/mem_fn.html" target="_top"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">mem_fn</span></code></a><code class="computeroutput"><span class="special">(</span><span class="identifier">f</span><span class="special">),</span> <span class="identifier">a1</span><span class="special">,</span> <span class="identifier">a2</span><span class="special">)</span></code>.
|
|
</li></ul></div>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.interface.additional_overloads"></a><a class="link" href="bind.html#bind.interface.additional_overloads" title="Additional overloads">Additional overloads</a>
|
|
</h3></div></div></div>
|
|
<p>
|
|
Implementations are allowed to provide additional <code class="computeroutput"><span class="identifier">bind</span></code>
|
|
overloads in order to support more arguments or different function pointer
|
|
variations.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
|
<a name="bind.implementation"></a><a class="link" href="bind.html#bind.implementation" title="Implementation">Implementation</a>
|
|
</h2></div></div></div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.implementation.files"></a><a class="link" href="bind.html#bind.implementation.files" title="Files">Files</a>
|
|
</h3></div></div></div>
|
|
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
|
<li class="listitem">
|
|
<a href="../../../../boost/bind.hpp" target="_top">boost/bind.hpp</a> (main
|
|
header)
|
|
</li>
|
|
<li class="listitem">
|
|
<a href="../../../../boost/bind/bind_cc.hpp" target="_top">boost/bind/bind_cc.hpp</a>
|
|
(used by <code class="computeroutput"><span class="identifier">bind</span><span class="special">.</span><span class="identifier">hpp</span></code>, do not include directly)
|
|
</li>
|
|
<li class="listitem">
|
|
<a href="../../../../boost/bind/bind_mf_cc.hpp" target="_top">boost/bind/bind_mf_cc.hpp</a>
|
|
(used by <code class="computeroutput"><span class="identifier">bind</span><span class="special">.</span><span class="identifier">hpp</span></code>, do not include directly)
|
|
</li>
|
|
<li class="listitem">
|
|
<a href="../../../../boost/bind/bind_template.hpp" target="_top">boost/bind/bind_template.hpp</a>
|
|
(used by <code class="computeroutput"><span class="identifier">bind</span><span class="special">.</span><span class="identifier">hpp</span></code>, do not include directly)
|
|
</li>
|
|
<li class="listitem">
|
|
<a href="../../../../boost/bind/arg.hpp" target="_top">boost/bind/arg.hpp</a>
|
|
(defines the type of the placeholder arguments)
|
|
</li>
|
|
<li class="listitem">
|
|
<a href="../../../../boost/bind/placeholders.hpp" target="_top">boost/bind/placeholders.hpp</a>
|
|
(defines the <code class="computeroutput"><span class="identifier">_1</span></code>, <code class="computeroutput"><span class="identifier">_2</span></code>, ... <code class="computeroutput"><span class="identifier">_9</span></code>
|
|
placeholders)
|
|
</li>
|
|
<li class="listitem">
|
|
<a href="../../../../boost/bind/apply.hpp" target="_top">boost/bind/apply.hpp</a>
|
|
(<code class="computeroutput"><span class="identifier">apply</span></code> helper function
|
|
object)
|
|
</li>
|
|
<li class="listitem">
|
|
<a href="../../../../boost/bind/protect.hpp" target="_top">boost/bind/protect.hpp</a>
|
|
(<code class="computeroutput"><span class="identifier">protect</span></code> helper function)
|
|
</li>
|
|
<li class="listitem">
|
|
<a href="../../../../boost/bind/make_adaptable.hpp" target="_top">boost/bind/make_adaptable.hpp</a>
|
|
(<code class="computeroutput"><span class="identifier">make_adaptable</span></code> helper
|
|
function)
|
|
</li>
|
|
<li class="listitem">
|
|
<a href="../../test/bind_test.cpp" target="_top">libs/bind/test/bind_test.cpp</a>
|
|
(test)
|
|
</li>
|
|
<li class="listitem">
|
|
<a href="../../bind_as_compose.cpp" target="_top">libs/bind/bind_as_compose.cpp</a>
|
|
(function composition example)
|
|
</li>
|
|
<li class="listitem">
|
|
<a href="../../bind_visitor.cpp" target="_top">libs/bind/bind_visitor.cpp</a>
|
|
(visitor example)
|
|
</li>
|
|
<li class="listitem">
|
|
<a href="../../test/bind_stdcall_test.cpp" target="_top">libs/bind/test/bind_stdcall_test.cpp</a>
|
|
(test with <code class="computeroutput"><span class="identifier">__stdcall</span></code>
|
|
functions)
|
|
</li>
|
|
<li class="listitem">
|
|
<a href="../../test/bind_stdcall_mf_test.cpp" target="_top">libs/bind/test/bind_stdcall_mf_test.cpp</a>
|
|
(test with <code class="computeroutput"><span class="identifier">__stdcall</span></code>
|
|
member functions)
|
|
</li>
|
|
<li class="listitem">
|
|
<a href="../../test/bind_fastcall_test.cpp" target="_top">libs/bind/test/bind_fastcall_test.</a>
|
|
(test with <code class="computeroutput"><span class="identifier">__fastcall</span></code>
|
|
functions)
|
|
</li>
|
|
<li class="listitem">
|
|
<a href="../../test/bind_fastcall_mf_test.cpp" target="_top">libs/bind/test/bind_fastcall_mf_test.cpp</a>
|
|
(test with <code class="computeroutput"><span class="identifier">__fastcall</span></code>
|
|
member functions)
|
|
</li>
|
|
</ul></div>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.implementation.dependencies"></a><a class="link" href="bind.html#bind.implementation.dependencies" title="Dependencies">Dependencies</a>
|
|
</h3></div></div></div>
|
|
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
|
<li class="listitem">
|
|
<a href="../../../../libs/config/config.htm" target="_top">Boost.Config</a>
|
|
</li>
|
|
<li class="listitem">
|
|
<a href="../../../../libs/core/doc/html/core/ref.html" target="_top">boost/ref.hpp</a>
|
|
</li>
|
|
<li class="listitem">
|
|
<a href="../../../../libs/bind/mem_fn.html" target="_top">boost/mem_fn.hpp</a>
|
|
</li>
|
|
<li class="listitem">
|
|
<a href="../../../../boost/type.hpp" target="_top">boost/type.hpp</a>
|
|
</li>
|
|
</ul></div>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.implementation.number_of_arguments"></a><a class="link" href="bind.html#bind.implementation.number_of_arguments" title="Number of Arguments">Number of Arguments</a>
|
|
</h3></div></div></div>
|
|
<p>
|
|
This implementation supports function objects with up to nine arguments.
|
|
This is an implementation detail, not an inherent limitation of the design.
|
|
</p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.implementation.stdcall"></a><a class="link" href="bind.html#bind.implementation.stdcall" title="__stdcall, __cdecl, __fastcall, and pascal Support"><code class="computeroutput"><span class="identifier">__stdcall</span></code>,
|
|
<code class="computeroutput"><span class="identifier">__cdecl</span></code>, <code class="computeroutput"><span class="identifier">__fastcall</span></code>,
|
|
and <code class="computeroutput"><span class="identifier">pascal</span></code> Support</a>
|
|
</h3></div></div></div>
|
|
<p>
|
|
Some platforms allow several types of (member) functions that differ by their
|
|
calling convention (the rules by which the function is invoked: how are arguments
|
|
passed, how is the return value handled, and who cleans up the stack - if
|
|
any.)
|
|
</p>
|
|
<p>
|
|
For example, Windows API functions and COM interface member functions use
|
|
a calling convention known as <code class="computeroutput"><span class="identifier">__stdcall</span></code>.
|
|
Borland VCL components use <code class="computeroutput"><span class="identifier">__fastcall</span></code>.
|
|
Mac toolbox functions use a <code class="computeroutput"><span class="identifier">pascal</span></code>
|
|
calling convention.
|
|
</p>
|
|
<p>
|
|
To use <code class="computeroutput"><span class="identifier">bind</span></code> with <code class="computeroutput"><span class="identifier">__stdcall</span></code> functions, <code class="computeroutput"><span class="preprocessor">#define</span></code>
|
|
the macro <code class="computeroutput"><span class="identifier">BOOST_BIND_ENABLE_STDCALL</span></code>
|
|
before including <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">bind</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code>.
|
|
</p>
|
|
<p>
|
|
To use <code class="computeroutput"><span class="identifier">bind</span></code> with <code class="computeroutput"><span class="identifier">__stdcall</span></code> member functions, <code class="computeroutput"><span class="preprocessor">#define</span></code> the macro <code class="computeroutput"><span class="identifier">BOOST_MEM_FN_ENABLE_STDCALL</span></code>
|
|
before including <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">bind</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code>.
|
|
</p>
|
|
<p>
|
|
To use <code class="computeroutput"><span class="identifier">bind</span></code> with <code class="computeroutput"><span class="identifier">__fastcall</span></code> functions, <code class="computeroutput"><span class="preprocessor">#define</span></code>
|
|
the macro <code class="computeroutput"><span class="identifier">BOOST_BIND_ENABLE_FASTCALL</span></code>
|
|
before including <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">bind</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code>.
|
|
</p>
|
|
<p>
|
|
To use <code class="computeroutput"><span class="identifier">bind</span></code> with <code class="computeroutput"><span class="identifier">__fastcall</span></code> member functions, <code class="computeroutput"><span class="preprocessor">#define</span></code> the macro <code class="computeroutput"><span class="identifier">BOOST_MEM_FN_ENABLE_FASTCALL</span></code>
|
|
before including <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">bind</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code>.
|
|
</p>
|
|
<p>
|
|
To use <code class="computeroutput"><span class="identifier">bind</span></code> with <code class="computeroutput"><span class="identifier">pascal</span></code> functions, <code class="computeroutput"><span class="preprocessor">#define</span></code>
|
|
the macro <code class="computeroutput"><span class="identifier">BOOST_BIND_ENABLE_PASCAL</span></code>
|
|
before including <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">bind</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code>.
|
|
</p>
|
|
<p>
|
|
To use <code class="computeroutput"><span class="identifier">bind</span></code> with <code class="computeroutput"><span class="identifier">__cdecl</span></code> member functions, <code class="computeroutput"><span class="preprocessor">#define</span></code> the macro <code class="computeroutput"><span class="identifier">BOOST_MEM_FN_ENABLE_CDECL</span></code>
|
|
before including <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">bind</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code>.
|
|
</p>
|
|
<p>
|
|
<span class="bold"><strong>It is best to define these macros in the project options,
|
|
via <code class="computeroutput"><span class="special">-</span><span class="identifier">D</span></code>
|
|
on the command line, or as the first line in the translation unit (.cpp file)
|
|
where <code class="computeroutput"><span class="identifier">bind</span></code> is used.</strong></span>
|
|
Not following this rule can lead to obscure errors when a header includes
|
|
<code class="computeroutput"><span class="identifier">bind</span><span class="special">.</span><span class="identifier">hpp</span></code> before the macro has been defined.
|
|
</p>
|
|
<p>
|
|
<span class="emphasis"><em>[Note:</em></span> this is a non-portable extension. It is not part
|
|
of the interface.<span class="emphasis"><em>]</em></span>
|
|
</p>
|
|
<p>
|
|
<span class="emphasis"><em>[Note:</em></span> Some compilers provide only minimal support for
|
|
the <code class="computeroutput"><span class="identifier">__stdcall</span></code> keyword.<span class="emphasis"><em>]</em></span>
|
|
</p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="bind.implementation.visit_each_support"></a><a class="link" href="bind.html#bind.implementation.visit_each_support" title="visit_each support"><code class="computeroutput"><span class="identifier">visit_each</span></code> support</a>
|
|
</h3></div></div></div>
|
|
<p>
|
|
Function objects returned by <code class="computeroutput"><span class="identifier">bind</span></code>
|
|
support the experimental and undocumented, as of yet, <code class="computeroutput"><span class="identifier">visit_each</span></code>
|
|
enumeration interface.
|
|
</p>
|
|
<p>
|
|
See <a href="../../bind_visitor.cpp" target="_top">bind_visitor.cpp</a> for an example.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
|
<a name="bind.acknowledgements"></a><a class="link" href="bind.html#bind.acknowledgements" title="Acknowledgements">Acknowledgements</a>
|
|
</h2></div></div></div>
|
|
<p>
|
|
Earlier efforts that have influenced the library design:
|
|
</p>
|
|
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
|
<li class="listitem">
|
|
The <a href="http://staff.cs.utu.fi/BL/" target="_top">Binder Library</a> by Jaakko
|
|
Järvi;
|
|
</li>
|
|
<li class="listitem">
|
|
The <a href="../../../../libs/lambda/index.html" target="_top">Lambda Library</a> (now
|
|
part of Boost) by Jaakko Järvi and Gary Powell (the successor to the
|
|
Binder Library);
|
|
</li>
|
|
<li class="listitem">
|
|
<a href="http://more.sourceforge.net/" target="_top">Extensions to the STL</a>
|
|
by Petter Urkedal.
|
|
</li>
|
|
</ul></div>
|
|
<p>
|
|
Doug Gregor suggested that a visitor mechanism would allow <code class="computeroutput"><span class="identifier">bind</span></code>
|
|
to interoperate with a signal/slot library.
|
|
</p>
|
|
<p>
|
|
John Maddock fixed a MSVC-specific conflict between <code class="computeroutput"><span class="identifier">bind</span></code>
|
|
and the <a href="../../../../libs/type_traits/index.html" target="_top">type traits library</a>.
|
|
</p>
|
|
<p>
|
|
Numerous improvements were suggested during the formal review period by Ross
|
|
Smith, Richard Crossley, Jens Maurer, Ed Brey, and others. Review manager was
|
|
Darin Adler.
|
|
</p>
|
|
<p>
|
|
The precise semantics of <code class="computeroutput"><span class="identifier">bind</span></code>
|
|
were refined in discussions with Jaakko Järvi.
|
|
</p>
|
|
<p>
|
|
Dave Abrahams fixed a MSVC-specific conflict between <code class="computeroutput"><span class="identifier">bind</span></code>
|
|
and the <a href="../../../../libs/utility/iterator_adaptors.htm" target="_top">iterator adaptors
|
|
library</a>.
|
|
</p>
|
|
<p>
|
|
Dave Abrahams modified <code class="computeroutput"><span class="identifier">bind</span></code>
|
|
and <code class="computeroutput"><span class="identifier">mem_fn</span></code> to support <code class="computeroutput"><span class="keyword">void</span></code> returns on deficient compilers.
|
|
</p>
|
|
<p>
|
|
Mac Murrett contributed the "pascal" support enabled by <code class="computeroutput"><span class="identifier">BOOST_BIND_ENABLE_PASCAL</span></code>.
|
|
</p>
|
|
<p>
|
|
The alternative <code class="computeroutput"><span class="identifier">bind</span><span class="special">(</span><span class="identifier">type</span><span class="special"><</span><span class="identifier">R</span><span class="special">>(),</span> <span class="identifier">f</span><span class="special">,</span> <span class="special">...)</span></code>
|
|
syntax was inspired by a discussion with Dave Abrahams and Joel de Guzman.
|
|
</p>
|
|
<p>
|
|
This documentation was ported to Quickbook by Agustín Bergé.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
|
<td align="left"><p><small>Last revised: July 07, 2017 at 11:19:28 GMT</small></p></td>
|
|
<td align="right"><div class="copyright-footer"></div></td>
|
|
</tr></table>
|
|
<hr>
|
|
<div class="spirit-nav"></div>
|
|
</body>
|
|
</html>
|