apply_visitor.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!DOCTYPE header PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
  3. "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
  4. <!--
  5. Copyright 2003, Eric Friedman, Itay Maman.
  6. Copyright 2013-2019 Antony Polukhin.
  7. Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. -->
  10. <header name="boost/variant/apply_visitor.hpp">
  11. <namespace name="boost">
  12. <class name="apply_visitor_delayed_t">
  13. <purpose>Adapts a visitor for use as a function object.</purpose>
  14. <description>
  15. <simpara>Adapts the function given at construction for use as a
  16. function object. This is useful, for example, when one needs to
  17. operate on each element of a sequence of variant objects using a
  18. standard library algorithm such as
  19. <code>std::for_each</code>.</simpara>
  20. <simpara>See the &quot;visitor-only&quot; form of
  21. <code><functionname>apply_visitor</functionname></code> for a simple
  22. way to create <code>apply_visitor_delayed_t</code> objects.</simpara>
  23. <simpara>See <code><classname>apply_visitor_delayed_cpp14_t</classname></code>
  24. which is used on C++14 compatible compilers when <code>Visitor</code> has no
  25. <code>result_type</code> typedef.</simpara>
  26. </description>
  27. <template>
  28. <template-type-parameter name="Visitor"/>
  29. </template>
  30. <typedef name="result_type">
  31. <type>typename Visitor::result_type</type>
  32. </typedef>
  33. <constructor specifiers="explicit">
  34. <parameter name="visitor">
  35. <paramtype>Visitor &amp;</paramtype>
  36. </parameter>
  37. <effects>
  38. <simpara>Constructs the function object with the given
  39. visitor.</simpara>
  40. </effects>
  41. </constructor>
  42. <method-group name="function object interface">
  43. <overloaded-method name="operator()">
  44. <signature>
  45. <template>
  46. <template-type-parameter name="... Variant"/>
  47. </template>
  48. <type>result_type</type>
  49. <parameter name="operand">
  50. <paramtype>Variant&amp;...</paramtype>
  51. </parameter>
  52. </signature>
  53. <signature>
  54. <template>
  55. <template-type-parameter name="Variant"/>
  56. </template>
  57. <type>result_type</type>
  58. <parameter name="operand">
  59. <paramtype>Variant &amp;</paramtype>
  60. </parameter>
  61. </signature>
  62. <signature>
  63. <template>
  64. <template-type-parameter name="Variant1"/>
  65. <template-type-parameter name="Variant2"/>
  66. </template>
  67. <type>result_type</type>
  68. <parameter name="operand1">
  69. <paramtype>Variant1 &amp;</paramtype>
  70. </parameter>
  71. <parameter name="operand2">
  72. <paramtype>Variant2 &amp;</paramtype>
  73. </parameter>
  74. </signature>
  75. <purpose>Function call operator.</purpose>
  76. <description>
  77. <simpara>Invokes
  78. <code><functionname>apply_visitor</functionname></code> on the
  79. stored visitor using the given operands.</simpara>
  80. </description>
  81. <notes>Version with variadic templates is used by default if
  82. <macroname>BOOST_VARIANT_DO_NOT_USE_VARIADIC_TEMPLATES</macroname> is not defined.</notes>
  83. </overloaded-method>
  84. </method-group>
  85. </class>
  86. <class name="apply_visitor_delayed_cpp14_t">
  87. <purpose>Adapts a visitor for use as a function object.</purpose>
  88. <description>
  89. <simpara>Adapts the function given at construction for use as a
  90. function object. This is useful, for example, when one needs to
  91. operate on each element of a sequence of variant objects using a
  92. standard library algorithm such as
  93. <code>std::for_each</code>.</simpara>
  94. <simpara>See the &quot;visitor-only&quot; form of
  95. <code><functionname>apply_visitor</functionname></code> for a simple
  96. way to create <code>apply_visitor_delayed_t</code> objects.</simpara>
  97. <simpara>See <code><classname>apply_visitor_delayed_t</classname></code>
  98. which is used when <code>Visitor</code> has <code>result_type</code>
  99. typedef.</simpara>
  100. <simpara>Available only if macro
  101. <macroname>BOOST_VARIANT_DO_NOT_USE_VARIADIC_TEMPLATES</macroname> is not defined and
  102. compiler supports <code>decltype(auto)</code> and <code>decltype(some-expression)</code>.</simpara>
  103. </description>
  104. <template>
  105. <template-type-parameter name="Visitor"/>
  106. </template>
  107. <constructor specifiers="explicit">
  108. <parameter name="visitor">
  109. <paramtype>Visitor &amp;</paramtype>
  110. </parameter>
  111. <effects>
  112. <simpara>Constructs the function object with the given
  113. visitor.</simpara>
  114. </effects>
  115. </constructor>
  116. <method-group name="function object interface">
  117. <overloaded-method name="operator()">
  118. <signature>
  119. <template>
  120. <template-type-parameter name="... Variant"/>
  121. </template>
  122. <type>decltype(auto)</type>
  123. <parameter name="operand">
  124. <paramtype>Variant&amp;...</paramtype>
  125. </parameter>
  126. </signature>
  127. <purpose>Function call operator.</purpose>
  128. <description>
  129. <simpara>Invokes
  130. <code><functionname>apply_visitor</functionname></code> on the
  131. stored visitor using the given operands.</simpara>
  132. </description>
  133. </overloaded-method>
  134. </method-group>
  135. </class>
  136. <overloaded-function name="apply_visitor">
  137. <signature>
  138. <template>
  139. <template-type-parameter name="Visitor"/>
  140. <template-type-parameter name="Variant"/>
  141. </template>
  142. <type>typename Visitor::result_type</type>
  143. <parameter name="visitor">
  144. <paramtype>Visitor &amp;</paramtype>
  145. </parameter>
  146. <parameter name="operand">
  147. <paramtype>Variant&amp;&amp;</paramtype>
  148. </parameter>
  149. </signature>
  150. <signature>
  151. <template>
  152. <template-type-parameter name="Visitor"/>
  153. <template-type-parameter name="Variant"/>
  154. </template>
  155. <type>typename Visitor::result_type</type>
  156. <parameter name="visitor">
  157. <paramtype>const Visitor &amp;</paramtype>
  158. </parameter>
  159. <parameter name="operand">
  160. <paramtype>Variant&amp;&amp;</paramtype>
  161. </parameter>
  162. </signature>
  163. <signature>
  164. <template>
  165. <template-type-parameter name="BinaryVisitor"/>
  166. <template-type-parameter name="Variant1"/>
  167. <template-type-parameter name="Variant2"/>
  168. </template>
  169. <type>typename BinaryVisitor::result_type OR decltype(auto)</type>
  170. <parameter name="visitor">
  171. <paramtype>BinaryVisitor &amp;</paramtype>
  172. </parameter>
  173. <parameter name="operand1">
  174. <paramtype>Variant1&amp;&amp;</paramtype>
  175. </parameter>
  176. <parameter name="operand2">
  177. <paramtype>Variant2&amp;&amp;</paramtype>
  178. </parameter>
  179. </signature>
  180. <signature>
  181. <template>
  182. <template-type-parameter name="BinaryVisitor"/>
  183. <template-type-parameter name="Variant1"/>
  184. <template-type-parameter name="Variant2"/>
  185. </template>
  186. <type>typename BinaryVisitor::result_type OR decltype(auto)</type>
  187. <parameter name="visitor">
  188. <paramtype>const BinaryVisitor &amp;</paramtype>
  189. </parameter>
  190. <parameter name="operand1">
  191. <paramtype>Variant1&amp;&amp;</paramtype>
  192. </parameter>
  193. <parameter name="operand2">
  194. <paramtype>Variant2&amp;&amp;</paramtype>
  195. </parameter>
  196. </signature>
  197. <signature>
  198. <template>
  199. <template-type-parameter name="MultiVisitor"/>
  200. <template-type-parameter name="Variant1"/>
  201. <template-type-parameter name="Variant2"/>
  202. <template-type-parameter name="Variant3"/>
  203. </template>
  204. <type>typename MultiVisitor::result_type OR decltype(auto)</type>
  205. <parameter name="visitor">
  206. <paramtype>MultiVisitor &amp;</paramtype>
  207. </parameter>
  208. <parameter name="operand1">
  209. <paramtype>Variant1&amp;&amp;</paramtype>
  210. </parameter>
  211. <parameter name="operand2">
  212. <paramtype>Variant2&amp;&amp;</paramtype>
  213. </parameter>
  214. <parameter name="operand3">
  215. <paramtype>Variant3&amp;&amp;</paramtype>
  216. </parameter>
  217. <parameter name="other_operands">
  218. <paramtype>...</paramtype>
  219. </parameter>
  220. </signature>
  221. <signature>
  222. <template>
  223. <template-type-parameter name="MultiVisitor"/>
  224. <template-type-parameter name="Variant1"/>
  225. <template-type-parameter name="Variant2"/>
  226. <template-type-parameter name="Variant3"/>
  227. </template>
  228. <type>typename MultiVisitor::result_type OR decltype(auto)</type>
  229. <parameter name="visitor">
  230. <paramtype>const MultiVisitor &amp;</paramtype>
  231. </parameter>
  232. <parameter name="operand1">
  233. <paramtype>Variant1&amp;&amp;</paramtype>
  234. </parameter>
  235. <parameter name="operand2">
  236. <paramtype>Variant2&amp;&amp;</paramtype>
  237. </parameter>
  238. <parameter name="operand3">
  239. <paramtype>Variant3&amp;&amp;</paramtype>
  240. </parameter>
  241. <parameter name="other_operands">
  242. <paramtype>...</paramtype>
  243. </parameter>
  244. </signature>
  245. <signature>
  246. <template>
  247. <template-type-parameter name="Visitor"/>
  248. </template>
  249. <type><classname>apply_visitor_delayed_t</classname>&lt;Visitor&gt;</type>
  250. <parameter name="visitor">
  251. <paramtype>Visitor &amp;</paramtype>
  252. </parameter>
  253. </signature>
  254. <signature>
  255. <template>
  256. <template-type-parameter name="Visitor"/>
  257. </template>
  258. <type><classname>apply_visitor_delayed_cpp14_t</classname>&lt;Visitor&gt;</type>
  259. <parameter name="visitor">
  260. <paramtype>Visitor &amp;</paramtype>
  261. </parameter>
  262. </signature>
  263. <purpose>
  264. <simpara>Allows compile-time checked type-safe application of the
  265. given visitor to the content of the given variant, ensuring that all
  266. types are handled by the visitor.</simpara>
  267. </purpose>
  268. <description>
  269. <simpara>The behavior of <code>apply_visitor</code> is dependent on
  270. the number of arguments on which it operates (i.e., other than the
  271. visitor). If your compiler does not support the rvalue references or reference qualifiers then all the
  272. forwarding references from above degrade to non const lvalue reference. The function behaves as follows:
  273. <itemizedlist>
  274. <listitem>Overloads accepting one operand invoke the unary function
  275. call operator of the given visitor on the content of the given
  276. <code><classname>variant</classname></code> operand.</listitem>
  277. <listitem>Overloads accepting two operands invoke the binary
  278. function call operator of the given visitor on the content of
  279. the given <code><classname>variant</classname></code>
  280. operands.</listitem>
  281. <listitem>Overloads accepting three or more operands invoke the
  282. function call operator of the given visitor on the content of
  283. the given <code><classname>variant</classname></code>
  284. operands. Maximum amount of parameters controlled by
  285. <code><emphasis role="bold"><macroname>BOOST_VARAINT_MAX_MULTIVIZITOR_PARAMS</macroname></emphasis></code>
  286. macro. Those functions are actually defined in a header <code>boost/variant/multivisitors.hpp</code>
  287. (See <xref linkend="header.boost.variant.multivisitors_hpp"/>). That header must be manually included
  288. if multi visitors are meant for use.</listitem>
  289. <listitem>The overloads accepting only a visitor return a
  290. <classname alt="boost::apply_visitor_delayed_t">C++03 compatible generic function object</classname>
  291. or
  292. <classname alt="boost::apply_visitor_delayed_cpp14_t">C++14 compatible generic function object</classname>
  293. that accepts either one, two or arbitrary count of arguments and invoke
  294. <code><functionname>apply_visitor</functionname></code> using
  295. these arguments and <code>visitor</code>, thus behaving as
  296. specified above. (This behavior is particularly useful, for
  297. example, when one needs to operate on each element of a sequence
  298. of variant objects using a standard library
  299. algorithm.)</listitem>
  300. </itemizedlist>
  301. </simpara>
  302. </description>
  303. <returns>
  304. <simpara>The overloads acccepting operands return the result of
  305. applying the given visitor to the content of the given operands.
  306. The overload accepting only a visitor return a function object, thus
  307. delaying application of the visitor to any operands.</simpara>
  308. </returns>
  309. <requires>
  310. <simpara>The given visitor must fulfill the
  311. <link linkend="variant.concepts.static-visitor"><emphasis>StaticVisitor</emphasis></link>
  312. concept requirements with respect to each of the bounded types of the
  313. given <code>variant</code>.</simpara>
  314. </requires>
  315. <throws>
  316. <simpara>The overloads accepting operands throw only if the given
  317. visitor throws when applied. The overload accepting only a visitor
  318. will not throw. (Note, however, that the returned
  319. <classname alt="boost::apply_visitor_delayed_t">function object</classname>
  320. may throw when invoked.)</simpara>
  321. </throws>
  322. </overloaded-function>
  323. </namespace>
  324. </header>