1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
4 <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
5 <meta http-equiv="X-UA-Compatible" content="IE=9"/>
6 <meta name="generator" content="Doxygen 1.8.9.1"/>
7 <title>libsigc++: bind(), bind_return()</title>
8 <link href="tabs.css" rel="stylesheet" type="text/css"/>
9 <script type="text/javascript" src="jquery.js"></script>
10 <script type="text/javascript" src="dynsections.js"></script>
11 <link href="doxygen.css" rel="stylesheet" type="text/css" />
12 <link href="doxygen-extra.css" rel="stylesheet" type="text/css"/>
15 <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
17 <table cellspacing="0" cellpadding="0">
19 <tr style="height: 56px;">
20 <td style="padding-left: 0.5em;">
21 <div id="projectname">libsigc++
22  <span id="projectnumber">2.99.2</span>
29 <!-- end header part -->
30 <!-- Generated by Doxygen 1.8.9.1 -->
31 <div id="navrow1" class="tabs">
33 <li><a href="index.html"><span>Main Page</span></a></li>
34 <li><a href="pages.html"><span>Related Pages</span></a></li>
35 <li><a href="modules.html"><span>Modules</span></a></li>
36 <li><a href="namespaces.html"><span>Namespaces</span></a></li>
37 <li><a href="annotated.html"><span>Classes</span></a></li>
43 <a href="#nested-classes">Classes</a> |
44 <a href="#func-members">Functions</a> </div>
45 <div class="headertitle">
46 <div class="title">bind(), bind_return()<div class="ingroups"><a class="el" href="group__adaptors.html">Adaptors</a></div></div> </div>
48 <div class="contents">
50 <p><a class="el" href="group__bind.html#ga9ce84730439c5e1c688bc18c102e81ca" title="Creates an adaptor of type sigc::bind_functor which binds the passed argument to the passed functor...">sigc::bind()</a> alters an arbitrary functor by fixing arguments to certain values.
51 <a href="#details">More...</a></p>
52 <table class="memberdecls">
53 <tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="nested-classes"></a>
54 Classes</h2></td></tr>
55 <tr class="memitem:"><td class="memItemLeft" align="right" valign="top">struct  </td><td class="memItemRight" valign="bottom"><a class="el" href="structsigc_1_1bind__functor.html">sigc::bind_functor< I_location, T_functor, T_bound ></a></td></tr>
56 <tr class="memdesc:"><td class="mdescLeft"> </td><td class="mdescRight">Adaptor that binds arguments to the wrapped functor. <a href="structsigc_1_1bind__functor.html#details">More...</a><br /></td></tr>
57 <tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
58 <tr class="memitem:"><td class="memItemLeft" align="right" valign="top">struct  </td><td class="memItemRight" valign="bottom"><a class="el" href="structsigc_1_1bind__functor_3-1_00_01T__functor_00_01T__type_8_8_8_4.html">sigc::bind_functor<-1, T_functor, T_type...></a></td></tr>
59 <tr class="memdesc:"><td class="mdescLeft"> </td><td class="mdescRight">Adaptor that binds argument(s) to the wrapped functor. <a href="structsigc_1_1bind__functor_3-1_00_01T__functor_00_01T__type_8_8_8_4.html#details">More...</a><br /></td></tr>
60 <tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
61 <tr class="memitem:"><td class="memItemLeft" align="right" valign="top">struct  </td><td class="memItemRight" valign="bottom"><a class="el" href="structsigc_1_1bind__return__functor.html">sigc::bind_return_functor< T_return, T_functor ></a></td></tr>
62 <tr class="memdesc:"><td class="mdescLeft"> </td><td class="mdescRight">Adaptor that fixes the return value of the wrapped functor. <a href="structsigc_1_1bind__return__functor.html#details">More...</a><br /></td></tr>
63 <tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
64 </table><table class="memberdecls">
65 <tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
66 Functions</h2></td></tr>
67 <tr class="memitem:ga9ce84730439c5e1c688bc18c102e81ca"><td class="memTemplParams" colspan="2">template<int I_location, class T_functor , class... T_bound> </td></tr>
68 <tr class="memitem:ga9ce84730439c5e1c688bc18c102e81ca"><td class="memTemplItemLeft" align="right" valign="top">decltype(auto) </td><td class="memTemplItemRight" valign="bottom"><a class="el" href="group__bind.html#ga9ce84730439c5e1c688bc18c102e81ca">sigc::bind</a> (const T_functor& _A_func, T_bound..._A_b)</td></tr>
69 <tr class="memdesc:ga9ce84730439c5e1c688bc18c102e81ca"><td class="mdescLeft"> </td><td class="mdescRight">Creates an adaptor of type <a class="el" href="structsigc_1_1bind__functor.html" title="Adaptor that binds arguments to the wrapped functor. ">sigc::bind_functor</a> which binds the passed argument to the passed functor. <a href="#ga9ce84730439c5e1c688bc18c102e81ca">More...</a><br /></td></tr>
70 <tr class="separator:ga9ce84730439c5e1c688bc18c102e81ca"><td class="memSeparator" colspan="2"> </td></tr>
71 <tr class="memitem:ga6f1886c34a7b361a072bd5630f731df2"><td class="memTemplParams" colspan="2">template<class T_functor , class... T_type> </td></tr>
72 <tr class="memitem:ga6f1886c34a7b361a072bd5630f731df2"><td class="memTemplItemLeft" align="right" valign="top">decltype(auto) </td><td class="memTemplItemRight" valign="bottom"><a class="el" href="group__bind.html#ga6f1886c34a7b361a072bd5630f731df2">sigc::bind</a> (const T_functor& _A_func, T_type..._A_b)</td></tr>
73 <tr class="memdesc:ga6f1886c34a7b361a072bd5630f731df2"><td class="mdescLeft"> </td><td class="mdescRight">Creates an adaptor of type <a class="el" href="structsigc_1_1bind__functor.html" title="Adaptor that binds arguments to the wrapped functor. ">sigc::bind_functor</a> which fixes the last arguments of the passed functor. <a href="#ga6f1886c34a7b361a072bd5630f731df2">More...</a><br /></td></tr>
74 <tr class="separator:ga6f1886c34a7b361a072bd5630f731df2"><td class="memSeparator" colspan="2"> </td></tr>
75 <tr class="memitem:gaca1ae2466988d67d00a5f2cd16c8d90a"><td class="memTemplParams" colspan="2">template<class T_return , class T_functor > </td></tr>
76 <tr class="memitem:gaca1ae2466988d67d00a5f2cd16c8d90a"><td class="memTemplItemLeft" align="right" valign="top">bind_return_functor< T_return, T_functor > </td><td class="memTemplItemRight" valign="bottom"><a class="el" href="group__bind.html#gaca1ae2466988d67d00a5f2cd16c8d90a">sigc::bind_return</a> (const T_functor& _A_functor, T_return _A_ret_value)</td></tr>
77 <tr class="memdesc:gaca1ae2466988d67d00a5f2cd16c8d90a"><td class="mdescLeft"> </td><td class="mdescRight">Creates an adaptor of type <a class="el" href="structsigc_1_1bind__return__functor.html" title="Adaptor that fixes the return value of the wrapped functor. ">sigc::bind_return_functor</a> which fixes the return value of the passed functor to the passed argument. <a href="#gaca1ae2466988d67d00a5f2cd16c8d90a">More...</a><br /></td></tr>
78 <tr class="separator:gaca1ae2466988d67d00a5f2cd16c8d90a"><td class="memSeparator" colspan="2"> </td></tr>
80 <a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
81 <p><a class="el" href="group__bind.html#ga9ce84730439c5e1c688bc18c102e81ca" title="Creates an adaptor of type sigc::bind_functor which binds the passed argument to the passed functor...">sigc::bind()</a> alters an arbitrary functor by fixing arguments to certain values. </p>
82 <p>Up to 7 arguments can be bound at a time. For single argument binding, overloads of <a class="el" href="group__bind.html#ga9ce84730439c5e1c688bc18c102e81ca" title="Creates an adaptor of type sigc::bind_functor which binds the passed argument to the passed functor...">sigc::bind()</a> are provided that let you specify the zero-based position of the argument to fix with the first template parameter. (A value of <code>-1</code> fixes the last argument so <a class="el" href="group__bind.html#ga9ce84730439c5e1c688bc18c102e81ca" title="Creates an adaptor of type sigc::bind_functor which binds the passed argument to the passed functor...">sigc::bind</a><-1>() gives the same result as <a class="el" href="group__bind.html#ga9ce84730439c5e1c688bc18c102e81ca" title="Creates an adaptor of type sigc::bind_functor which binds the passed argument to the passed functor...">sigc::bind()</a>.) The types of the arguments can optionally be specified if not deduced.</p>
83 <dl class="section user"><dt>Examples:</dt><dd><div class="fragment"><div class="line"><span class="keywordtype">void</span> foo(<span class="keywordtype">int</span>, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>);</div>
84 <div class="line"><span class="comment">// single argument binding ...</span></div>
85 <div class="line"><a class="code" href="group__bind.html#ga9ce84730439c5e1c688bc18c102e81ca">sigc::bind</a>(&foo,1)(2,3); <span class="comment">//fixes the last (third) argument and calls foo(2,3,1)</span></div>
86 <div class="line"><a class="code" href="group__bind.html#ga9ce84730439c5e1c688bc18c102e81ca">sigc::bind</a><-1>(&foo,1)(2,3); <span class="comment">//same as bind(&foo,1)(2,3) (calls foo(2,3,1))</span></div>
87 <div class="line">sigc::bind<0>(&foo,1)(2,3); <span class="comment">//fixes the first argument and calls foo(1,2,3)</span></div>
88 <div class="line">sigc::bind<1>(&foo,1)(2,3); <span class="comment">//fixes the second argument and calls foo(2,1,3)</span></div>
89 <div class="line">sigc::bind<2>(&foo,1)(2,3); <span class="comment">//fixes the third argument and calls foo(2,3,1)</span></div>
90 <div class="line"><span class="comment">// multi argument binding ...</span></div>
91 <div class="line"><a class="code" href="group__bind.html#ga9ce84730439c5e1c688bc18c102e81ca">sigc::bind</a>(&foo,1,2)(3); <span class="comment">//fixes the last two arguments and calls foo(3,1,2)</span></div>
92 <div class="line"><a class="code" href="group__bind.html#ga9ce84730439c5e1c688bc18c102e81ca">sigc::bind</a>(&foo,1,2,3)(); <span class="comment">//fixes all three arguments and calls foo(1,2,3)</span></div>
93 </div><!-- fragment --></dd></dl>
94 <p>The functor <a class="el" href="group__bind.html#ga9ce84730439c5e1c688bc18c102e81ca" title="Creates an adaptor of type sigc::bind_functor which binds the passed argument to the passed functor...">sigc::bind()</a> returns can be passed into sigc::signal::connect() directly.</p>
95 <dl class="section user"><dt>Example:</dt><dd><div class="fragment"><div class="line"><a class="code" href="classsigc_1_1signal.html">sigc::signal<void()></a> some_signal;</div>
96 <div class="line"><span class="keywordtype">void</span> foo(<span class="keywordtype">int</span>);</div>
97 <div class="line">some_signal.connect(<a class="code" href="group__bind.html#ga9ce84730439c5e1c688bc18c102e81ca">sigc::bind</a>(&foo,1));</div>
98 </div><!-- fragment --></dd></dl>
99 <p><a class="el" href="group__bind.html#gaca1ae2466988d67d00a5f2cd16c8d90a" title="Creates an adaptor of type sigc::bind_return_functor which fixes the return value of the passed funct...">sigc::bind_return()</a> alters an arbitrary functor by fixing its return value to a certain value.</p>
100 <dl class="section user"><dt>Example:</dt><dd><div class="fragment"><div class="line"><span class="keywordtype">void</span> foo();</div>
101 <div class="line">std::cout << <a class="code" href="group__bind.html#gaca1ae2466988d67d00a5f2cd16c8d90a">sigc::bind_return</a>(&foo, 5)(); <span class="comment">// calls foo() and returns 5</span></div>
102 </div><!-- fragment --></dd></dl>
103 <p>You can bind references to functors by passing the objects through the std::ref() helper function.</p>
104 <dl class="section user"><dt>Example:</dt><dd><div class="fragment"><div class="line"><span class="keywordtype">int</span> some_int;</div>
105 <div class="line"><a class="code" href="classsigc_1_1signal.html">sigc::signal<void()></a> some_signal;</div>
106 <div class="line"><span class="keywordtype">void</span> foo(<span class="keywordtype">int</span>&);</div>
107 <div class="line">some_signal.connect(<a class="code" href="group__bind.html#ga9ce84730439c5e1c688bc18c102e81ca">sigc::bind</a>(&foo, std::ref(some_int)));</div>
108 </div><!-- fragment --></dd></dl>
109 <p>If you bind an object of a <a class="el" href="structsigc_1_1trackable.html" title="Base class for objects with auto-disconnection. ">sigc::trackable</a> derived type to a functor by reference, a slot assigned to the bind adaptor is cleared automatically when the object goes out of scope.</p>
110 <dl class="section user"><dt>Example:</dt><dd><div class="fragment"><div class="line"><span class="keyword">struct </span>bar : <span class="keyword">public</span> <a class="code" href="structsigc_1_1trackable.html">sigc::trackable</a> {} some_bar;</div>
111 <div class="line"><a class="code" href="classsigc_1_1signal.html">sigc::signal<void()></a> some_signal;</div>
112 <div class="line"><span class="keywordtype">void</span> foo(bar&);</div>
113 <div class="line">some_signal.connect(<a class="code" href="group__bind.html#ga9ce84730439c5e1c688bc18c102e81ca">sigc::bind</a>(&foo, std::ref(some_bar)));</div>
114 <div class="line"> <span class="comment">// disconnected automatically if some_bar goes out of scope</span></div>
115 </div><!-- fragment --> </dd></dl>
116 <h2 class="groupheader">Function Documentation</h2>
117 <a class="anchor" id="ga9ce84730439c5e1c688bc18c102e81ca"></a>
118 <div class="memitem">
119 <div class="memproto">
120 <div class="memtemplate">
121 template <int I_location, class T_functor , class... T_bound> </div>
122 <table class="mlabels">
124 <td class="mlabels-left">
125 <table class="memname">
127 <td class="memname">decltype(auto) sigc::bind </td>
129 <td class="paramtype">const T_functor & </td>
130 <td class="paramname"><em>_A_func</em>, </td>
133 <td class="paramkey"></td>
135 <td class="paramtype">T_bound... </td>
136 <td class="paramname"><em>_A_b</em> </td>
145 <td class="mlabels-right">
146 <span class="mlabels"><span class="mlabel">inline</span></span> </td>
149 </div><div class="memdoc">
151 <p>Creates an adaptor of type <a class="el" href="structsigc_1_1bind__functor.html" title="Adaptor that binds arguments to the wrapped functor. ">sigc::bind_functor</a> which binds the passed argument to the passed functor. </p>
152 <p>The optional template argument <em>I_location</em> specifies the zero-based position of the argument to be fixed (<code>-1</code> stands for the last argument).</p>
153 <dl class="params"><dt>Parameters</dt><dd>
154 <table class="params">
155 <tr><td class="paramname">_A_func</td><td>Functor that should be wrapped. </td></tr>
156 <tr><td class="paramname">_A_b1</td><td>Argument to bind to <em>_A_func</em>. </td></tr>
160 <dl class="section return"><dt>Returns</dt><dd>Adaptor that executes <em>_A_func</em> with the bound argument on invokation. </dd></dl>
164 <a class="anchor" id="ga6f1886c34a7b361a072bd5630f731df2"></a>
165 <div class="memitem">
166 <div class="memproto">
167 <div class="memtemplate">
168 template <class T_functor , class... T_type> </div>
169 <table class="mlabels">
171 <td class="mlabels-left">
172 <table class="memname">
174 <td class="memname">decltype(auto) sigc::bind </td>
176 <td class="paramtype">const T_functor & </td>
177 <td class="paramname"><em>_A_func</em>, </td>
180 <td class="paramkey"></td>
182 <td class="paramtype">T_type... </td>
183 <td class="paramname"><em>_A_b</em> </td>
192 <td class="mlabels-right">
193 <span class="mlabels"><span class="mlabel">inline</span></span> </td>
196 </div><div class="memdoc">
198 <p>Creates an adaptor of type <a class="el" href="structsigc_1_1bind__functor.html" title="Adaptor that binds arguments to the wrapped functor. ">sigc::bind_functor</a> which fixes the last arguments of the passed functor. </p>
199 <p>This function overload fixes the last arguments of <em>_A_func</em>.</p>
200 <dl class="params"><dt>Parameters</dt><dd>
201 <table class="params">
202 <tr><td class="paramname">_A_func</td><td>Functor that should be wrapped. </td></tr>
203 <tr><td class="paramname">_A_b</td><td>Arguments to bind to <em>_A_func</em>. </td></tr>
207 <dl class="section return"><dt>Returns</dt><dd>Adaptor that executes _A_func with the bound argument on invokation. </dd></dl>
211 <a class="anchor" id="gaca1ae2466988d67d00a5f2cd16c8d90a"></a>
212 <div class="memitem">
213 <div class="memproto">
214 <div class="memtemplate">
215 template <class T_return , class T_functor > </div>
216 <table class="mlabels">
218 <td class="mlabels-left">
219 <table class="memname">
221 <td class="memname">bind_return_functor<T_return, T_functor> sigc::bind_return </td>
223 <td class="paramtype">const T_functor & </td>
224 <td class="paramname"><em>_A_functor</em>, </td>
227 <td class="paramkey"></td>
229 <td class="paramtype">T_return </td>
230 <td class="paramname"><em>_A_ret_value</em> </td>
239 <td class="mlabels-right">
240 <span class="mlabels"><span class="mlabel">inline</span></span> </td>
243 </div><div class="memdoc">
245 <p>Creates an adaptor of type <a class="el" href="structsigc_1_1bind__return__functor.html" title="Adaptor that fixes the return value of the wrapped functor. ">sigc::bind_return_functor</a> which fixes the return value of the passed functor to the passed argument. </p>
246 <dl class="params"><dt>Parameters</dt><dd>
247 <table class="params">
248 <tr><td class="paramname">_A_functor</td><td>Functor that should be wrapped. </td></tr>
249 <tr><td class="paramname">_A_ret_value</td><td>Argument to fix the return value of <em>_A_functor</em> to. </td></tr>
253 <dl class="section return"><dt>Returns</dt><dd>Adaptor that executes <em>_A_functor</em> on invokation and returns <em>_A_ret_value</em>. </dd></dl>
257 </div><!-- contents -->
258 <!-- start footer part -->
259 <hr class="footer"/><address class="footer"><small>
260 Generated on Wed Mar 16 2016 20:53:27 for libsigc++ by  <a href="http://www.doxygen.org/index.html">
261 <img class="footer" src="doxygen.png" alt="doxygen"/>