reference.xml 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!--
  3. Copyright (c) 2002 Douglas Gregor <doug.gregor -at- gmail.com>
  4. Distributed under the Boost Software License, Version 1.0.
  5. (See accompanying file LICENSE_1_0.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. -->
  8. <!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
  9. "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
  10. <library-reference id="function.reference" last-revision="$Date$">
  11. <section id="function.definitions">
  12. <title>Definitions</title>
  13. <para>
  14. <itemizedlist>
  15. <listitem>
  16. <para>A function object <computeroutput>f</computeroutput> is
  17. <emphasis>compatible</emphasis> if for the given set of argument
  18. types <computeroutput>Arg1</computeroutput>,
  19. <computeroutput>Arg2</computeroutput>, ...,
  20. <computeroutput>ArgN</computeroutput> and a
  21. return type <computeroutput>ResultType</computeroutput>, the
  22. appropriate following function is well-formed:
  23. <programlisting>
  24. <emphasis>// if ResultType is not <emphasis role="bold">void</emphasis></emphasis>
  25. ResultType foo(Arg1 arg1, Arg2 arg2, ..., Arg<emphasis>N</emphasis> arg<emphasis>N</emphasis>)
  26. {
  27. <emphasis role="bold">return</emphasis> f(arg1, arg2, ..., arg<emphasis>N</emphasis>);
  28. }
  29. <emphasis>// if ResultType is <emphasis role="bold">void</emphasis></emphasis>
  30. ResultType foo(Arg1 arg1, Arg2 arg2, ..., Arg<emphasis>N</emphasis> arg<emphasis>N</emphasis>)
  31. {
  32. f(arg1, arg2, ..., arg<emphasis>N</emphasis>);
  33. }
  34. </programlisting></para>
  35. <para> A special provision is made for pointers to member
  36. functions. Though they are not function objects, Boost.Function
  37. will adapt them internally to function objects. This requires
  38. that a pointer to member function of the form <code>R
  39. (X::*mf)(Arg1, Arg2, ..., ArgN)
  40. cv-quals</code> be adapted to a
  41. function object with the following function call operator
  42. overloads:
  43. <programlisting>
  44. <emphasis role="bold">template</emphasis>&lt;<emphasis role="bold">typename P</emphasis>&gt;
  45. R <emphasis role="bold">operator</emphasis>()(<emphasis>cv-quals</emphasis> P&amp; x, Arg1 arg1, Arg2 arg2, ..., Arg<emphasis>N</emphasis> arg<emphasis>N</emphasis>) <emphasis role="bold">const</emphasis>
  46. {
  47. <emphasis role="bold">return</emphasis> (*x).*mf(arg1, arg2, ..., arg<emphasis>N</emphasis>);
  48. }
  49. </programlisting>
  50. </para>
  51. </listitem>
  52. <listitem>
  53. <para>A function object <code>f</code> of
  54. type <code>F</code> is
  55. <emphasis>stateless</emphasis> if it is a function pointer or if
  56. <code><classname>boost::is_stateless</classname>&lt;F&gt;</code>
  57. is true. The construction of or copy to a Boost.Function object
  58. from a stateless function object will not cause exceptions to be
  59. thrown and will not allocate any storage.
  60. </para>
  61. </listitem>
  62. </itemizedlist>
  63. </para>
  64. </section>
  65. <header name="boost/function.hpp">
  66. <namespace name="boost">
  67. <class name="bad_function_call">
  68. <inherit access="public"><classname>std::runtime_error</classname></inherit>
  69. <purpose>An exception type thrown when an instance of a <code>function</code> object is empty when invoked.</purpose>
  70. <constructor>
  71. <effects><simpara>Constructs a <code><classname>bad_function_call</classname></code> exception object.</simpara></effects>
  72. </constructor>
  73. </class>
  74. <class name="function_base">
  75. <purpose>The common base class for all Boost.Function
  76. objects. Objects of type function_base may not be created
  77. directly.</purpose>
  78. <method-group name="capacity">
  79. <method name="empty" cv="const">
  80. <type>bool</type>
  81. <returns><simpara><code>false</code> if <code>this</code> has a target, and <code>true</code> otherwise.</simpara></returns>
  82. <throws><simpara>Will not throw.</simpara></throws>
  83. </method>
  84. </method-group>
  85. <method-group name="target access">
  86. <overloaded-method name="target">
  87. <signature>
  88. <template>
  89. <template-type-parameter name="Functor"/>
  90. </template>
  91. <type>Functor*</type>
  92. </signature>
  93. <signature cv="const">
  94. <template>
  95. <template-type-parameter name="Functor"/>
  96. </template>
  97. <type>const Functor*</type>
  98. </signature>
  99. <returns><simpara>If <code>this</code> stores a target of type
  100. <code>Functor</code>, returns the address of the
  101. target. Otherwise, returns the NULL
  102. pointer.</simpara></returns>
  103. <throws><simpara>Will not throw.</simpara></throws>
  104. </overloaded-method>
  105. <method name="contains" cv="const">
  106. <template>
  107. <template-type-parameter name="Functor"/>
  108. </template>
  109. <type>bool</type>
  110. <parameter name="f">
  111. <paramtype>const Functor&amp;</paramtype>
  112. </parameter>
  113. <returns><simpara><code>true</code> if <code>this-&gt;<methodname>target</methodname>&lt;Functor&gt;()</code> is non-NULL and <code><functionname>function_equal</functionname>(*(this-&gt;target&lt;Functor&gt;()), f)</code></simpara></returns>
  114. </method>
  115. <method name="target_type" cv="const">
  116. <type>const std::type_info&amp;</type>
  117. <returns><simpara><code>typeid</code> of the target function object, or <code>typeid(void)</code> if <code>this-&gt;<methodname>empty</methodname>()</code>. Works even with RTTI off.</simpara></returns>
  118. <throws><simpara>Will not throw.</simpara></throws>
  119. </method>
  120. </method-group>
  121. </class>
  122. <class name="functionN">
  123. <template>
  124. <template-type-parameter name="R"/>
  125. <template-type-parameter name="T1"/>
  126. <template-type-parameter name="T2"/>
  127. <template-varargs/>
  128. <template-type-parameter name="TN"/>
  129. </template>
  130. <inherit access="public"><classname>function_base</classname></inherit>
  131. <purpose>A set of generalized function pointers that can be used for callbacks or wrapping function objects.</purpose>
  132. <description>
  133. <para>Class template <classname>functionN</classname> is
  134. actually a family of related classes <classname
  135. alt="functionN">function0</classname>, <classname
  136. alt="functionN">function1</classname>, etc., up to some
  137. implementation-defined maximum. In this context, <code>N</code>
  138. refers to the number of parameters.</para>
  139. </description>
  140. <typedef name="result_type"><type>R</type></typedef>
  141. <typedef name="argument_type">
  142. <type>T1</type><purpose>If N == 1</purpose>
  143. </typedef>
  144. <typedef name="first_argument_type">
  145. <type>T1</type>
  146. <purpose>If N == 2</purpose>
  147. </typedef>
  148. <typedef name="second_argument_type">
  149. <type>T2</type>
  150. <purpose>If N == 2</purpose>
  151. </typedef>
  152. <typedef name="arg1_type"><type>T1</type></typedef>
  153. <typedef name="arg2_type"><type>T2</type></typedef>
  154. <typedef name="..."><type/></typedef>
  155. <typedef name="argN_type"><type>TN</type></typedef>
  156. <static-constant name="arity">
  157. <type>int</type>
  158. <default>N</default>
  159. </static-constant>
  160. <struct name="sig">
  161. <template>
  162. <template-type-parameter name="Args"/>
  163. </template>
  164. <purpose>
  165. <simpara><libraryname>Lambda</libraryname> library support</simpara>
  166. </purpose>
  167. <typedef name="type"><type>result_type</type></typedef>
  168. </struct>
  169. <constructor>
  170. <postconditions><simpara><code>this-&gt;<methodname>empty</methodname>()</code></simpara></postconditions>
  171. <throws><simpara>Will not throw.</simpara></throws>
  172. </constructor>
  173. <constructor>
  174. <parameter name="f">
  175. <paramtype>const <classname>functionN</classname>&amp;</paramtype>
  176. </parameter>
  177. <postconditions><simpara>Contains a copy of the <code>f</code>'s target, if it has one, or is empty if <code>f.<methodname>empty</methodname>()</code>.</simpara></postconditions>
  178. <throws><simpara>Will not throw unless copying the target of <code>f</code> throws.</simpara></throws>
  179. </constructor>
  180. <constructor>
  181. <parameter name="f">
  182. <paramtype><classname>functionN</classname>&amp;&amp;</paramtype>
  183. </parameter>
  184. <requires><simpara>C++11 compatible compiler.</simpara></requires>
  185. <postconditions><simpara>Moves the value from <code>f</code> to <code>*this</code>. If the argument has its function object allocated on the heap, its buffer will be assigned to <code>*this</code> leaving argument empty.</simpara></postconditions>
  186. <throws><simpara>Will not throw unless argument has its function object allocated not on the heap and copying the target of <code>f</code> throws.</simpara></throws>
  187. </constructor>
  188. <constructor>
  189. <template>
  190. <template-type-parameter name="F"/>
  191. </template>
  192. <parameter name="f"><paramtype>F</paramtype></parameter>
  193. <requires><simpara>F is a function object Callable from <code>this</code>.</simpara></requires>
  194. <postconditions><simpara><code>*this</code> targets a copy of <code>f</code> if <code>f</code> is nonempty, or <code>this-&gt;<methodname>empty</methodname>()</code> if <code>f</code> is empty.</simpara></postconditions>
  195. </constructor>
  196. <constructor>
  197. <template>
  198. <template-type-parameter name="F"/>
  199. <template-type-parameter name="Allocator"/>
  200. </template>
  201. <parameter name="f"><paramtype>F</paramtype></parameter>
  202. <parameter name="alloc"><paramtype>Allocator</paramtype></parameter>
  203. <requires><simpara>F is a function object Callable from <code>this</code>, Allocator is an allocator. The copy constructor and destructor of Allocator shall not throw.</simpara></requires>
  204. <postconditions><simpara><code>*this</code> targets a copy of <code>f</code> if <code>f</code> is nonempty, or <code>this-&gt;<methodname>empty</methodname>()</code> if <code>f</code> is empty.</simpara></postconditions>
  205. <effects><simpara>If memory allocation is required, the given allocator (or a copy of it) will be used to allocate that memory.</simpara></effects>
  206. </constructor>
  207. <destructor>
  208. <effects><simpara>If <code>!this-&gt;<methodname>empty</methodname>()</code>, destroys the target of this.</simpara></effects>
  209. </destructor>
  210. <copy-assignment>
  211. <parameter name="f">
  212. <paramtype>const <classname>functionN</classname>&amp;</paramtype>
  213. </parameter>
  214. <postconditions><simpara>If copy construction does not throw, <code>*this</code> targets a copy of <code>f</code>'s target, if it has one, or is empty if <code>f.<methodname>empty</methodname>()</code>. If copy construction does throw, <code>this-&gt;<methodname>empty</methodname>()</code>.</simpara></postconditions>
  215. </copy-assignment>
  216. <copy-assignment>
  217. <parameter name="f">
  218. <paramtype><classname>functionN</classname>&amp;&amp;</paramtype>
  219. </parameter>
  220. <requires><simpara>C++11 compatible compiler.</simpara></requires>
  221. <postconditions><simpara>Moves the value from <code>f</code> to <code>*this</code>. If the argument has its function object allocated on the heap, its buffer will be assigned to <code>*this</code> leaving argument empty.</simpara></postconditions>
  222. <throws><simpara>Will not throw unless argument has its function object allocated not on the heap and copying the target of <code>f</code> throws.</simpara></throws>
  223. </copy-assignment>
  224. <method-group name="modifiers">
  225. <method name="swap">
  226. <type>void</type>
  227. <parameter name="f"><paramtype>const <classname>functionN</classname>&amp;</paramtype></parameter>
  228. <effects><simpara>Interchanges the targets of <code>*this</code> and <code>f</code>.</simpara></effects>
  229. </method>
  230. <method name="clear">
  231. <type>void</type>
  232. <postconditions><simpara>this-&gt;<methodname>empty</methodname>()</simpara></postconditions>
  233. </method>
  234. </method-group>
  235. <method-group name="capacity">
  236. <method name="empty" cv="const">
  237. <type>bool</type>
  238. <returns><simpara><code>false</code> if <code>this</code> has a target, and <code>true</code> otherwise.</simpara></returns>
  239. <throws><simpara>Will not throw.</simpara></throws>
  240. </method>
  241. <method name="conversion-operator" cv="const">
  242. <type>safe_bool</type>
  243. <returns><simpara>A <code>safe_bool</code> that evaluates <code>false</code> in a boolean context when <code>this-&gt;<methodname>empty</methodname>()</code>, and <code>true</code> otherwise.</simpara></returns>
  244. <throws><simpara>Will not throw.</simpara></throws>
  245. </method>
  246. <method name="operator!" cv="const">
  247. <type>bool</type>
  248. <returns><simpara><code>this-&gt;<methodname>empty</methodname>()</code></simpara></returns>
  249. <throws><simpara>Will not throw.</simpara></throws>
  250. </method>
  251. </method-group>
  252. <method-group name="target access">
  253. <overloaded-method name="target">
  254. <signature>
  255. <template>
  256. <template-type-parameter name="Functor"/>
  257. </template>
  258. <type>Functor*</type>
  259. </signature>
  260. <signature cv="const">
  261. <template>
  262. <template-type-parameter name="Functor"/>
  263. </template>
  264. <type>const Functor*</type>
  265. </signature>
  266. <returns><simpara>If <code>this</code> stores a target of type
  267. <code>Functor</code>, returns the address of the
  268. target. Otherwise, returns the NULL
  269. pointer.</simpara></returns>
  270. <throws><simpara>Will not throw.</simpara></throws>
  271. </overloaded-method>
  272. <method name="contains" cv="const">
  273. <template>
  274. <template-type-parameter name="Functor"/>
  275. </template>
  276. <type>bool</type>
  277. <parameter name="f">
  278. <paramtype>const Functor&amp;</paramtype>
  279. </parameter>
  280. <returns><simpara><code>true</code> if <code>this-&gt;<methodname>target</methodname>&lt;Functor&gt;()</code> is non-NULL and <code><functionname>function_equal</functionname>(*(this-&gt;target&lt;Functor&gt;()), f)</code></simpara></returns>
  281. </method>
  282. <method name="target_type" cv="const">
  283. <type>const std::type_info&amp;</type>
  284. <returns><simpara><code>typeid</code> of the target function object, or <code>typeid(void)</code> if <code>this-&gt;<methodname>empty</methodname>()</code>.</simpara></returns>
  285. <throws><simpara>Will not throw.</simpara></throws>
  286. </method>
  287. </method-group>
  288. <method-group name="invocation">
  289. <method name="operator()" cv="const">
  290. <type>result_type</type>
  291. <parameter name="a1"><paramtype>arg1_type</paramtype></parameter>
  292. <parameter name="a2"><paramtype>arg2_type</paramtype></parameter>
  293. <parameter><paramtype>...</paramtype></parameter>
  294. <parameter name="aN"><paramtype>argN_type</paramtype></parameter>
  295. <effects><simpara><code>f(a1, a2, ..., aN)</code>, where <code>f</code> is the target of <code>*this</code>.</simpara></effects>
  296. <returns><simpara>if <code>R</code> is <code>void</code>, nothing is returned; otherwise, the return value of the call to <code>f</code> is returned.</simpara></returns>
  297. <throws><simpara><code><classname>bad_function_call</classname></code> if <code>this-&gt;<methodname>empty</methodname>()</code>. Otherwise, may through any exception thrown by the target function <code>f</code>.</simpara></throws>
  298. </method>
  299. </method-group>
  300. <free-function-group name="specialized algorithms">
  301. <function name="swap">
  302. <template>
  303. <template-type-parameter name="T1"/>
  304. <template-type-parameter name="T2"/>
  305. <template-varargs/>
  306. <template-type-parameter name="TN"/>
  307. </template>
  308. <type>void</type>
  309. <parameter name="f1"><paramtype><classname>functionN</classname>&lt;T1, T2, ..., TN&gt;&amp;</paramtype></parameter>
  310. <parameter name="f2"><paramtype><classname>functionN</classname>&lt;T1, T2, ..., TN&gt;&amp;</paramtype></parameter>
  311. <effects><simpara><code>f1.<methodname>swap</methodname>(f2)</code></simpara></effects>
  312. </function>
  313. </free-function-group>
  314. <free-function-group name="comparison operators">
  315. <overloaded-function name="operator==">
  316. <signature>
  317. <template>
  318. <template-type-parameter name="T1"/>
  319. <template-type-parameter name="T2"/>
  320. <template-varargs/>
  321. <template-type-parameter name="TN"/>
  322. <template-type-parameter name="Functor"/>
  323. </template>
  324. <type>bool</type>
  325. <parameter name="f"><paramtype>const <classname>functionN</classname>&lt;T1, T2, ..., TN&gt;&amp;</paramtype></parameter>
  326. <parameter name="g"><paramtype>Functor</paramtype></parameter>
  327. </signature>
  328. <signature>
  329. <template>
  330. <template-type-parameter name="T1"/>
  331. <template-type-parameter name="T2"/>
  332. <template-varargs/>
  333. <template-type-parameter name="TN"/>
  334. <template-type-parameter name="Functor"/>
  335. </template>
  336. <type>bool</type>
  337. <parameter name="g"><paramtype>Functor</paramtype></parameter>
  338. <parameter name="f"><paramtype>const <classname>functionN</classname>&lt;T1, T2, ..., TN&gt;&amp;</paramtype></parameter>
  339. </signature>
  340. <signature>
  341. <template>
  342. <template-type-parameter name="T1"/>
  343. <template-type-parameter name="T2"/>
  344. <template-varargs/>
  345. <template-type-parameter name="TN"/>
  346. <template-type-parameter name="Functor"/>
  347. </template>
  348. <type>bool</type>
  349. <parameter name="f"><paramtype>const <classname>functionN</classname>&lt;T1, T2, ..., TN&gt;&amp;</paramtype></parameter>
  350. <parameter name="g"><paramtype><classname>reference_wrapper</classname>&lt;Functor&gt;</paramtype></parameter>
  351. </signature>
  352. <signature>
  353. <template>
  354. <template-type-parameter name="T1"/>
  355. <template-type-parameter name="T2"/>
  356. <template-varargs/>
  357. <template-type-parameter name="TN"/>
  358. <template-type-parameter name="Functor"/>
  359. </template>
  360. <type>bool</type>
  361. <parameter name="g"><paramtype><classname>reference_wrapper</classname>&lt;Functor&gt;</paramtype></parameter>
  362. <parameter name="f"><paramtype>const <classname>functionN</classname>&lt;T1, T2, ..., TN&gt;&amp;</paramtype></parameter>
  363. </signature>
  364. <signature>
  365. <template>
  366. <template-type-parameter name="T1"/>
  367. <template-type-parameter name="T2"/>
  368. <template-varargs/>
  369. <template-type-parameter name="TN"/>
  370. <template-type-parameter name="U1"/>
  371. <template-type-parameter name="U2"/>
  372. <template-varargs/>
  373. <template-type-parameter name="UN"/>
  374. </template>
  375. <type>void</type>
  376. <parameter name="f1"><paramtype>const <classname>functionN</classname>&lt;T1, T2, ..., TN&gt;&amp;</paramtype></parameter>
  377. <parameter name="f2"><paramtype>const <classname>functionN</classname>&lt;U1, U2, ..., UN&gt;&amp;</paramtype></parameter>
  378. </signature>
  379. <returns><simpara>True when <code>f</code> stores an object of
  380. type <code>Functor</code> and one of the following conditions applies:
  381. <itemizedlist>
  382. <listitem><simpara><code>g</code> is of type
  383. <code><classname>reference_wrapper</classname>&lt;Functor&gt;</code>
  384. and <code>f.target&lt;Functor&gt;() == g.<methodname
  385. alt="reference_wrapper::get_pointer">get_pointer</methodname>()</code>.</simpara></listitem>
  386. <listitem><simpara><code>g</code> is not of type
  387. <code><classname>reference_wrapper</classname>&lt;Functor&gt;</code>
  388. and
  389. <code><functionname>function_equal</functionname>(*(f.target&lt;Functor&gt;()),
  390. g)</code>.</simpara></listitem>
  391. </itemizedlist>
  392. </simpara></returns>
  393. <notes><simpara><code><classname>functionN</classname></code>
  394. objects are not
  395. <conceptname>EqualityComparable</conceptname>.</simpara></notes>
  396. <rationale><simpara>The <code>safe_bool</code> conversion
  397. opens a loophole whereby two <code>functionN</code>
  398. instances can be compared via <code>==</code>, although this
  399. is not feasible to implement. The undefined <code>void
  400. operator==</code> closes the loophole and ensures a
  401. compile-time or link-time error.</simpara></rationale>
  402. </overloaded-function>
  403. <overloaded-function name="operator!=">
  404. <signature>
  405. <template>
  406. <template-type-parameter name="T1"/>
  407. <template-type-parameter name="T2"/>
  408. <template-varargs/>
  409. <template-type-parameter name="TN"/>
  410. <template-type-parameter name="Functor"/>
  411. </template>
  412. <type>bool</type>
  413. <parameter name="f"><paramtype>const <classname>functionN</classname>&lt;T1, T2, ..., TN&gt;&amp;</paramtype></parameter>
  414. <parameter name="g"><paramtype>Functor</paramtype></parameter>
  415. </signature>
  416. <signature>
  417. <template>
  418. <template-type-parameter name="T1"/>
  419. <template-type-parameter name="T2"/>
  420. <template-varargs/>
  421. <template-type-parameter name="TN"/>
  422. <template-type-parameter name="Functor"/>
  423. </template>
  424. <type>bool</type>
  425. <parameter name="g"><paramtype>Functor</paramtype></parameter>
  426. <parameter name="f"><paramtype>const <classname>functionN</classname>&lt;T1, T2, ..., TN&gt;&amp;</paramtype></parameter>
  427. </signature>
  428. <signature>
  429. <template>
  430. <template-type-parameter name="T1"/>
  431. <template-type-parameter name="T2"/>
  432. <template-varargs/>
  433. <template-type-parameter name="TN"/>
  434. <template-type-parameter name="Functor"/>
  435. </template>
  436. <type>bool</type>
  437. <parameter name="f"><paramtype>const <classname>functionN</classname>&lt;T1, T2, ..., TN&gt;&amp;</paramtype></parameter>
  438. <parameter name="g"><paramtype><classname>reference_wrapper</classname>&lt;Functor&gt;</paramtype></parameter>
  439. </signature>
  440. <signature>
  441. <template>
  442. <template-type-parameter name="T1"/>
  443. <template-type-parameter name="T2"/>
  444. <template-varargs/>
  445. <template-type-parameter name="TN"/>
  446. <template-type-parameter name="Functor"/>
  447. </template>
  448. <type>bool</type>
  449. <parameter name="g"><paramtype><classname>reference_wrapper</classname>&lt;Functor&gt;</paramtype></parameter>
  450. <parameter name="f"><paramtype>const <classname>functionN</classname>&lt;T1, T2, ..., TN&gt;&amp;</paramtype></parameter>
  451. </signature>
  452. <signature>
  453. <template>
  454. <template-type-parameter name="T1"/>
  455. <template-type-parameter name="T2"/>
  456. <template-varargs/>
  457. <template-type-parameter name="TN"/>
  458. <template-type-parameter name="U1"/>
  459. <template-type-parameter name="U2"/>
  460. <template-varargs/>
  461. <template-type-parameter name="UN"/>
  462. </template>
  463. <type>void</type>
  464. <parameter name="f1"><paramtype>const <classname>functionN</classname>&lt;T1, T2, ..., TN&gt;&amp;</paramtype></parameter>
  465. <parameter name="f2"><paramtype>const <classname>functionN</classname>&lt;U1, U2, ..., UN&gt;&amp;</paramtype></parameter>
  466. </signature>
  467. <returns><simpara>True when <code>f</code> does not store an
  468. object of type <code>Functor</code> or it stores an object of
  469. type <code>Functor</code> and one of the following conditions
  470. applies:
  471. <itemizedlist>
  472. <listitem><simpara><code>g</code> is of type
  473. <code><classname>reference_wrapper</classname>&lt;Functor&gt;</code>
  474. and <code>f.target&lt;Functor&gt;() != g.<methodname
  475. alt="reference_wrapper::get_pointer">get_pointer</methodname>()</code>.</simpara></listitem>
  476. <listitem><simpara><code>g</code> is not of type
  477. <code><classname>reference_wrapper</classname>&lt;Functor&gt;</code>
  478. and <code>!<functionname>function_equal</functionname>(*(f.target&lt;Functor&gt;()), g)</code>.</simpara></listitem>
  479. </itemizedlist>
  480. </simpara></returns>
  481. <notes><simpara><code><classname>functionN</classname></code>
  482. objects are not
  483. <conceptname>EqualityComparable</conceptname>.</simpara></notes>
  484. <rationale><simpara>The <code>safe_bool</code> conversion
  485. opens a loophole whereby two <code>functionN</code>
  486. instances can be compared via <code>!=</code>, although this
  487. is not feasible to implement. The undefined <code>void
  488. operator!=</code> closes the loophole and ensures a
  489. compile-time or link-time error.</simpara></rationale>
  490. </overloaded-function>
  491. </free-function-group>
  492. </class>
  493. <class name="function">
  494. <template>
  495. <template-type-parameter name="Signature">
  496. <purpose>Function type R (T1, T2, ..., TN)</purpose>
  497. </template-type-parameter>
  498. </template>
  499. <inherit access="public"><classname>functionN</classname>&lt;R, T1, T2, ..., TN&gt;</inherit>
  500. <purpose>A generalized function pointer that can be used for
  501. callbacks or wrapping function objects.</purpose>
  502. <description>
  503. <para>Class template <classname>function</classname> is a thin
  504. wrapper around the numbered class templates <classname
  505. alt="functionN">function0</classname>, <classname
  506. alt="functionN">function1</classname>, etc. It accepts a
  507. function type with N arguments and will will derive from
  508. <classname>functionN</classname> instantiated with the arguments
  509. it receives.</para>
  510. <para>The semantics of all operations in class template
  511. <classname>function</classname> are equivalent to that of the
  512. underlying <classname>functionN</classname> object, although
  513. additional member functions are required to allow proper copy
  514. construction and copy assignment of function objects.</para>
  515. </description>
  516. <typedef name="result_type"><type>R</type></typedef>
  517. <typedef name="argument_type">
  518. <type>T1</type><purpose>If N == 1</purpose>
  519. </typedef>
  520. <typedef name="first_argument_type">
  521. <type>T1</type>
  522. <purpose>If N == 2</purpose>
  523. </typedef>
  524. <typedef name="second_argument_type">
  525. <type>T2</type>
  526. <purpose>If N == 2</purpose>
  527. </typedef>
  528. <typedef name="arg1_type"><type>T1</type></typedef>
  529. <typedef name="arg2_type"><type>T2</type></typedef>
  530. <typedef name="..."><type/></typedef>
  531. <typedef name="argN_type"><type>TN</type></typedef>
  532. <static-constant name="arity">
  533. <type>int</type>
  534. <default>N</default>
  535. </static-constant>
  536. <struct name="sig">
  537. <template>
  538. <template-type-parameter name="Args"/>
  539. </template>
  540. <purpose>
  541. <simpara><libraryname>Lambda</libraryname> library support</simpara>
  542. </purpose>
  543. <typedef name="type"><type>result_type</type></typedef>
  544. </struct>
  545. <constructor>
  546. <postconditions><simpara><code>this-&gt;<methodname>empty</methodname>()</code></simpara></postconditions>
  547. <throws><simpara>Will not throw.</simpara></throws>
  548. </constructor>
  549. <constructor>
  550. <parameter name="f">
  551. <paramtype>const <classname>functionN</classname>&amp;</paramtype>
  552. </parameter>
  553. <postconditions><simpara>Contains a copy of the <code>f</code>'s target, if it has one, or is empty if <code>f.<methodname>empty</methodname>()</code>.</simpara></postconditions>
  554. <throws><simpara>Will not throw unless copying the target of <code>f</code> throws.</simpara></throws>
  555. </constructor>
  556. <constructor>
  557. <parameter name="f">
  558. <paramtype><classname>functionN</classname>&amp;&amp;</paramtype>
  559. </parameter>
  560. <requires><simpara>C++11 compatible compiler.</simpara></requires>
  561. <postconditions><simpara>Moves the value from <code>f</code> to <code>*this</code>. If the argument has its function object allocated on the heap, its buffer will be assigned to <code>*this</code> leaving argument empty.</simpara></postconditions>
  562. <throws><simpara>Will not throw unless argument has its function object allocated not on the heap and copying the target of <code>f</code> throws.</simpara></throws>
  563. </constructor>
  564. <constructor>
  565. <parameter name="f">
  566. <paramtype>const <classname>function</classname>&amp;</paramtype>
  567. </parameter>
  568. <postconditions><simpara>Contains a copy of the <code>f</code>'s target, if it has one, or is empty if <code>f.<methodname>empty</methodname>()</code>.</simpara></postconditions>
  569. <throws><simpara>Will not throw unless copying the target of <code>f</code> throws.</simpara></throws>
  570. </constructor>
  571. <constructor>
  572. <parameter name="f">
  573. <paramtype><classname>function</classname>&amp;&amp;</paramtype>
  574. </parameter>
  575. <requires><simpara>C++11 compatible compiler.</simpara></requires>
  576. <postconditions><simpara>Moves the value from <code>f</code> to <code>*this</code>. If the argument has its function object allocated on the heap, its buffer will be assigned to <code>*this</code> leaving argument empty.</simpara></postconditions>
  577. <throws><simpara>Will not throw unless argument has its function object allocated not on the heap and copying the target of <code>f</code> throws.</simpara></throws>
  578. </constructor>
  579. <constructor>
  580. <template>
  581. <template-type-parameter name="F"/>
  582. </template>
  583. <parameter name="f"><paramtype>F</paramtype></parameter>
  584. <requires><simpara>F is a function object Callable from <code>this</code>.</simpara></requires>
  585. <postconditions><simpara><code>*this</code> targets a copy of <code>f</code> if <code>f</code> is nonempty, or <code>this-&gt;<methodname>empty</methodname>()</code> if <code>f</code> is empty.</simpara></postconditions>
  586. </constructor>
  587. <constructor>
  588. <template>
  589. <template-type-parameter name="F"/>
  590. <template-type-parameter name="Allocator"/>
  591. </template>
  592. <parameter name="f"><paramtype>F</paramtype></parameter>
  593. <parameter name="alloc"><paramtype>Allocator</paramtype></parameter>
  594. <requires><simpara>F is a function object Callable from <code>this</code>, Allocator is an allocator. The copy constructor and destructor of Allocator shall not throw.</simpara></requires>
  595. <postconditions><simpara><code>*this</code> targets a copy of <code>f</code> if <code>f</code> is nonempty, or <code>this-&gt;<methodname>empty</methodname>()</code> if <code>f</code> is empty.</simpara></postconditions>
  596. <effects><simpara>If memory allocation is required, the given allocator (or a copy of it) will be used to allocate that memory.</simpara></effects>
  597. </constructor>
  598. <destructor>
  599. <effects><simpara>If <code>!this-&gt;<methodname>empty</methodname>()</code>, destroys the target of <code>this</code>.</simpara></effects>
  600. </destructor>
  601. <copy-assignment>
  602. <parameter name="f">
  603. <paramtype>const <classname>functionN</classname>&amp;</paramtype>
  604. </parameter>
  605. <postconditions><simpara>If copy construction does not throw, <code>*this</code> targets a copy of <code>f</code>'s target, if it has one, or is empty if <code>f.<methodname>empty</methodname>()</code>. If copy construction does throw, <code>this-&gt;<methodname>empty</methodname>()</code>.</simpara></postconditions>
  606. </copy-assignment>
  607. <copy-assignment>
  608. <parameter name="f">
  609. <paramtype><classname>functionN</classname>&amp;&amp;</paramtype>
  610. </parameter>
  611. <requires><simpara>C++11 compatible compiler.</simpara></requires>
  612. <postconditions><simpara>Moves the value from <code>f</code> to <code>*this</code>. If the argument has its function object allocated on the heap, its buffer will be assigned to <code>*this</code> leaving argument empty.</simpara></postconditions>
  613. <throws><simpara>Will not throw unless argument has its function object allocated not on the heap and copying the target of <code>f</code> throws.</simpara></throws>
  614. </copy-assignment>
  615. <copy-assignment>
  616. <parameter name="f">
  617. <paramtype>const <classname>function</classname>&amp;</paramtype>
  618. </parameter>
  619. <postconditions><simpara>If copy construction of the target of <code>f</code> does not throw, <code>*this</code> targets a copy of <code>f</code>'s target, if it has one, or is empty if <code>f.<methodname>empty</methodname>()</code>. </simpara></postconditions>
  620. <throws><simpara>Will not throw when the target of <code>f</code> is a stateless function object or a reference to the function object. If copy construction does throw, <code>this-&gt;<methodname>empty</methodname>()</code>.</simpara></throws>
  621. </copy-assignment>
  622. <copy-assignment>
  623. <parameter name="f">
  624. <paramtype><classname>function</classname>&amp;&amp;</paramtype>
  625. </parameter>
  626. <requires><simpara>C++11 compatible compiler.</simpara></requires>
  627. <postconditions><simpara>Moves the value from <code>f</code> to <code>*this</code>. If the argument has its function object allocated on the heap, its buffer will be assigned to <code>*this</code> leaving argument empty.</simpara></postconditions>
  628. <throws><simpara>Will not throw unless argument has its function object allocated not on the heap and copying the target of <code>f</code> throws.</simpara></throws>
  629. </copy-assignment>
  630. <method-group name="modifiers">
  631. <method name="swap">
  632. <type>void</type>
  633. <parameter name="f"><paramtype>const <classname>function</classname>&amp;</paramtype></parameter>
  634. <effects><simpara>Interchanges the targets of <code>*this</code> and <code>f</code>.</simpara></effects>
  635. </method>
  636. <method name="clear">
  637. <type>void</type>
  638. <postconditions><simpara><code>this-&gt;<methodname>empty</methodname>()</code></simpara></postconditions>
  639. <throws><simpara>Will not throw.</simpara></throws>
  640. </method>
  641. </method-group>
  642. <method-group name="capacity">
  643. <method name="empty" cv="const">
  644. <type>bool</type>
  645. <returns><simpara><code>false</code> if <code>this</code> has a target, and <code>true</code> otherwise.</simpara></returns>
  646. <throws><simpara>Will not throw.</simpara></throws>
  647. </method>
  648. <method name="conversion-operator" cv="const">
  649. <type>safe_bool</type>
  650. <returns><simpara>A <code>safe_bool</code> that evaluates <code>false</code> in a boolean context when <code>this-&gt;<methodname>empty</methodname>()</code>, and <code>true</code> otherwise.</simpara></returns>
  651. <throws><simpara>Will not throw.</simpara></throws>
  652. </method>
  653. <method name="operator!" cv="const">
  654. <type>bool</type>
  655. <returns><simpara><code>this-&gt;<methodname>empty</methodname>()</code></simpara></returns>
  656. <throws><simpara>Will not throw.</simpara></throws>
  657. </method>
  658. </method-group>
  659. <method-group name="target access">
  660. <overloaded-method name="target">
  661. <signature>
  662. <template>
  663. <template-type-parameter name="Functor"/>
  664. </template>
  665. <type>Functor*</type>
  666. </signature>
  667. <signature cv="const">
  668. <template>
  669. <template-type-parameter name="Functor"/>
  670. </template>
  671. <type>const Functor*</type>
  672. </signature>
  673. <returns><simpara>If <code>this</code> stores a target of type
  674. <code>Functor</code>, returns the address of the
  675. target. Otherwise, returns the NULL
  676. pointer.</simpara></returns>
  677. <throws><simpara>Will not throw.</simpara></throws>
  678. </overloaded-method>
  679. <method name="contains" cv="const">
  680. <template>
  681. <template-type-parameter name="Functor"/>
  682. </template>
  683. <type>bool</type>
  684. <parameter name="f">
  685. <paramtype>const Functor&amp;</paramtype>
  686. </parameter>
  687. <returns><simpara><code>true</code> if <code>this-&gt;<methodname>target</methodname>&lt;Functor&gt;()</code> is non-NULL and <code><functionname>function_equal</functionname>(*(this-&gt;target&lt;Functor&gt;()), f)</code></simpara></returns>
  688. </method>
  689. <method name="target_type" cv="const">
  690. <type>const std::type_info&amp;</type>
  691. <returns><simpara><code>typeid</code> of the target function object, or <code>typeid(void)</code> if <code>this-&gt;<methodname>empty</methodname>()</code>.</simpara></returns>
  692. <throws><simpara>Will not throw.</simpara></throws>
  693. </method>
  694. </method-group>
  695. <method-group name="invocation">
  696. <method name="operator()" cv="const">
  697. <type>result_type</type>
  698. <parameter name="a1"><paramtype>arg1_type</paramtype></parameter>
  699. <parameter name="a2"><paramtype>arg2_type</paramtype></parameter>
  700. <parameter><paramtype>...</paramtype></parameter>
  701. <parameter name="aN"><paramtype>argN_type</paramtype></parameter>
  702. <effects><simpara><code>f(a1, a2, ..., aN)</code>, where <code>f</code> is the target of <code>*this</code>.</simpara></effects>
  703. <returns><simpara>if <code>R</code> is <code>void</code>, nothing is returned; otherwise, the return value of the call to <code>f</code> is returned.</simpara></returns>
  704. <throws><simpara><code><classname>bad_function_call</classname></code> if <code>this-&gt;<methodname>empty</methodname>()</code>. Otherwise, may through any exception thrown by the target function <code>f</code>.</simpara></throws>
  705. </method>
  706. </method-group>
  707. <free-function-group name="specialized algorithms">
  708. <function name="swap">
  709. <template>
  710. <template-type-parameter name="Signature"/>
  711. </template>
  712. <type>void</type>
  713. <parameter name="f1"><paramtype><classname>function</classname>&lt;Signature&gt;&amp;</paramtype></parameter>
  714. <parameter name="f2"><paramtype><classname>function</classname>&lt;Signature&gt;&amp;</paramtype></parameter>
  715. <effects><simpara><code>f1.<methodname>swap</methodname>(f2)</code></simpara></effects>
  716. </function>
  717. </free-function-group>
  718. <free-function-group name="comparison operators">
  719. <overloaded-function name="operator==">
  720. <signature>
  721. <template>
  722. <template-type-parameter name="Signature"/>
  723. <template-type-parameter name="Functor"/>
  724. </template>
  725. <type>bool</type>
  726. <parameter name="f"><paramtype>const <classname>function</classname>&lt;Signature&gt;&amp;</paramtype></parameter>
  727. <parameter name="g"><paramtype>Functor</paramtype></parameter>
  728. </signature>
  729. <signature>
  730. <template>
  731. <template-type-parameter name="Signature"/>
  732. <template-type-parameter name="Functor"/>
  733. </template>
  734. <type>bool</type>
  735. <parameter name="g"><paramtype>Functor</paramtype></parameter>
  736. <parameter name="f"><paramtype>const <classname>function</classname>&lt;Signature&gt;&amp;</paramtype></parameter>
  737. </signature>
  738. <signature>
  739. <template>
  740. <template-type-parameter name="Signature"/>
  741. <template-type-parameter name="Functor"/>
  742. </template>
  743. <type>bool</type>
  744. <parameter name="f"><paramtype>const <classname>function</classname>&lt;Signature&gt;&amp;</paramtype></parameter>
  745. <parameter name="g"><paramtype><classname>reference_wrapper</classname>&lt;Functor&gt;</paramtype></parameter>
  746. </signature>
  747. <signature>
  748. <template>
  749. <template-type-parameter name="Signature"/>
  750. <template-type-parameter name="Functor"/>
  751. </template>
  752. <type>bool</type>
  753. <parameter name="g"><paramtype><classname>reference_wrapper</classname>&lt;Functor&gt;</paramtype></parameter>
  754. <parameter name="f"><paramtype>const <classname>function</classname>&lt;Signature&gt;&amp;</paramtype></parameter>
  755. </signature>
  756. <signature>
  757. <template>
  758. <template-type-parameter name="Signature1"/>
  759. <template-type-parameter name="Signature2"/>
  760. </template>
  761. <type>void</type>
  762. <parameter name="f1"><paramtype>const <classname>function</classname>&lt;Signature1&gt;&amp;</paramtype></parameter>
  763. <parameter name="f2"><paramtype>const <classname>function</classname>&lt;Signature2&gt;&amp;</paramtype></parameter>
  764. </signature>
  765. <returns><simpara>True when <code>f</code> stores an object of
  766. type <code>Functor</code> and one of the following conditions applies:
  767. <itemizedlist>
  768. <listitem><simpara><code>g</code> is of type
  769. <code><classname>reference_wrapper</classname>&lt;Functor&gt;</code>
  770. and <code>f.target&lt;Functor&gt;() == g.<methodname
  771. alt="reference_wrapper::get_pointer">get_pointer</methodname>()</code>.</simpara></listitem>
  772. <listitem><simpara><code>g</code> is not of type
  773. <code><classname>reference_wrapper</classname>&lt;Functor&gt;</code>
  774. and <code><functionname>function_equals</functionname>(*(f.target&lt;Functor&gt;()), g)</code>.</simpara></listitem>
  775. </itemizedlist>
  776. </simpara></returns>
  777. <notes><simpara><code><classname>function</classname></code>
  778. objects are not
  779. <conceptname>EqualityComparable</conceptname>.</simpara></notes>
  780. <rationale><simpara>The <code>safe_bool</code> conversion
  781. opens a loophole whereby two <code>function</code>
  782. instances can be compared via <code>==</code>, although this
  783. is not feasible to implement. The undefined <code>void
  784. operator==</code> closes the loophole and ensures a
  785. compile-time or link-time error.</simpara></rationale>
  786. </overloaded-function>
  787. <overloaded-function name="operator!=">
  788. <signature>
  789. <template>
  790. <template-type-parameter name="Signature"/>
  791. <template-type-parameter name="Functor"/>
  792. </template>
  793. <type>bool</type>
  794. <parameter name="f"><paramtype>const <classname>function</classname>&lt;Signature&gt;&amp;</paramtype></parameter>
  795. <parameter name="g"><paramtype>Functor</paramtype></parameter>
  796. </signature>
  797. <signature>
  798. <template>
  799. <template-type-parameter name="Signature"/>
  800. <template-type-parameter name="Functor"/>
  801. </template>
  802. <type>bool</type>
  803. <parameter name="g"><paramtype>Functor</paramtype></parameter>
  804. <parameter name="f"><paramtype>const <classname>function</classname>&lt;Signature&gt;&amp;</paramtype></parameter>
  805. </signature>
  806. <signature>
  807. <template>
  808. <template-type-parameter name="Signature"/>
  809. <template-type-parameter name="Functor"/>
  810. </template>
  811. <type>bool</type>
  812. <parameter name="f"><paramtype>const <classname>function</classname>&lt;Signature&gt;&amp;</paramtype></parameter>
  813. <parameter name="g"><paramtype><classname>reference_wrapper</classname>&lt;Functor&gt;</paramtype></parameter>
  814. </signature>
  815. <signature>
  816. <template>
  817. <template-type-parameter name="Signature"/>
  818. <template-type-parameter name="Functor"/>
  819. </template>
  820. <type>bool</type>
  821. <parameter name="g"><paramtype><classname>reference_wrapper</classname>&lt;Functor&gt;</paramtype></parameter>
  822. <parameter name="f"><paramtype>const <classname>function</classname>&lt;Signature&gt;&amp;</paramtype></parameter>
  823. </signature>
  824. <signature>
  825. <template>
  826. <template-type-parameter name="Signature1"/>
  827. <template-type-parameter name="Signature2"/>
  828. </template>
  829. <type>void</type>
  830. <parameter name="f1"><paramtype>const <classname>function</classname>&lt;Signature1&gt;&amp;</paramtype></parameter>
  831. <parameter name="f2"><paramtype>const <classname>function</classname>&lt;Signature2&gt;&amp;</paramtype></parameter>
  832. </signature>
  833. <returns><simpara>True when <code>f</code> does not store an
  834. object of type <code>Functor</code> or it stores an object of
  835. type <code>Functor</code> and one of the following conditions
  836. applies:
  837. <itemizedlist>
  838. <listitem><simpara><code>g</code> is of type
  839. <code><classname>reference_wrapper</classname>&lt;Functor&gt;</code>
  840. and <code>f.target&lt;Functor&gt;() != g.<methodname
  841. alt="reference_wrapper::get_pointer">get_pointer</methodname>()</code>.</simpara></listitem>
  842. <listitem><simpara><code>g</code> is not of type
  843. <code><classname>reference_wrapper</classname>&lt;Functor&gt;</code>
  844. and <code>!<functionname>function_equals</functionname>(*(f.target&lt;Functor&gt;()), g)</code>.</simpara></listitem>
  845. </itemizedlist>
  846. </simpara></returns>
  847. <notes><simpara><code><classname>function</classname></code>
  848. objects are not
  849. <conceptname>EqualityComparable</conceptname>.</simpara></notes>
  850. <rationale><simpara>The <code>safe_bool</code> conversion
  851. opens a loophole whereby two <code>function</code>
  852. instances can be compared via <code>!=</code>, although this
  853. is not feasible to implement. The undefined <code>void
  854. operator!=</code> closes the loophole and ensures a
  855. compile-time or link-time error.</simpara></rationale>
  856. </overloaded-function>
  857. </free-function-group>
  858. </class>
  859. </namespace>
  860. </header>
  861. <header name="boost/function_equal.hpp">
  862. <namespace name="boost">
  863. <function name="function_equal">
  864. <template>
  865. <template-type-parameter name="F"/>
  866. <template-type-parameter name="G"/>
  867. </template>
  868. <type>bool</type>
  869. <parameter name="f">
  870. <paramtype>const F&amp;</paramtype>
  871. </parameter>
  872. <parameter name="g">
  873. <paramtype>const G&amp;</paramtype>
  874. </parameter>
  875. <purpose><simpara>Compare two function objects for equality.</simpara></purpose>
  876. <returns><simpara><code>f == g</code>.</simpara></returns>
  877. <throws><simpara>Only if <code>f == g</code> throws.</simpara></throws>
  878. </function>
  879. </namespace>
  880. </header>
  881. </library-reference>