polymorphic_get.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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 2013-2019 Antony Polukhin.
  6. Distributed under the Boost Software License, Version 1.0. (See accompanying
  7. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  8. -->
  9. <header name="boost/variant/polymorphic_get.hpp">
  10. <namespace name="boost">
  11. <class name="bad_polymorphic_get">
  12. <inherit access="public">
  13. <classname>boost::bad_get</classname>
  14. </inherit>
  15. <purpose>
  16. <simpara>The exception thrown in the event of a failed application of
  17. <code><functionname>boost::polymorphic_get</functionname></code> on the given
  18. operand value.</simpara>
  19. </purpose>
  20. <method name="what" specifiers="virtual" cv="const">
  21. <type>const char *</type>
  22. </method>
  23. </class>
  24. <overloaded-function name="polymorphic_relaxed_get">
  25. <signature>
  26. <template>
  27. <template-type-parameter name="U"/>
  28. <template-type-parameter name="T1"/>
  29. <template-type-parameter name="T2"/>
  30. <template-varargs/>
  31. <template-type-parameter name="TN"/>
  32. </template>
  33. <type>U *</type>
  34. <parameter name="operand">
  35. <paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; *</paramtype>
  36. </parameter>
  37. </signature>
  38. <signature>
  39. <template>
  40. <template-type-parameter name="U"/>
  41. <template-type-parameter name="T1"/>
  42. <template-type-parameter name="T2"/>
  43. <template-varargs/>
  44. <template-type-parameter name="TN"/>
  45. </template>
  46. <type>const U *</type>
  47. <parameter name="operand">
  48. <paramtype>const <classname>variant</classname>&lt;T1, T2, ..., TN&gt; *</paramtype>
  49. </parameter>
  50. </signature>
  51. <signature>
  52. <template>
  53. <template-type-parameter name="U"/>
  54. <template-type-parameter name="T1"/>
  55. <template-type-parameter name="T2"/>
  56. <template-varargs/>
  57. <template-type-parameter name="TN"/>
  58. </template>
  59. <type>U &amp;</type>
  60. <parameter name="operand">
  61. <paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;</paramtype>
  62. </parameter>
  63. </signature>
  64. <signature>
  65. <template>
  66. <template-type-parameter name="U"/>
  67. <template-type-parameter name="T1"/>
  68. <template-type-parameter name="T2"/>
  69. <template-varargs/>
  70. <template-type-parameter name="TN"/>
  71. </template>
  72. <type>const U &amp;</type>
  73. <parameter name="operand">
  74. <paramtype>const <classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;</paramtype>
  75. </parameter>
  76. </signature>
  77. <purpose>
  78. <simpara>Retrieves a value of a specified type from a given
  79. <code><classname>variant</classname></code>.</simpara>
  80. <simpara>Unlike <functionname>polymorphic_strict_get</functionname> does not assert at compile time
  81. that type <code>U</code> is one of the types that can be stored in variant.</simpara>
  82. </purpose>
  83. <description>
  84. <simpara>The <code>polymorphic_get</code> function allows run-time checked,
  85. type-safe retrieval of the content of the given
  86. <code><classname>variant</classname></code>. The function succeeds
  87. only if the content is of the specified type <code>U</code> or of type
  88. derived from type <code>U</code>, with
  89. failure indicated as described below.</simpara>
  90. <simpara><emphasis role="bold">Recomendation</emphasis>: Use
  91. <functionname>polymorphic_get</functionname> or <functionname>polymorphic_strict_get</functionname>
  92. in new code.
  93. <functionname>polymorphic_strict_get</functionname>
  94. provides more compile time checks and its behavior is closer to <code>std::get</code>
  95. from C++ Standard Library.</simpara>
  96. <simpara><emphasis role="bold">Warning</emphasis>: After either
  97. <code>operand</code> or its content is destroyed (e.g., when the
  98. given <code><classname>variant</classname></code> is assigned a
  99. value of different type), the returned reference is invalidated.
  100. Thus, significant care and caution must be extended when handling
  101. the returned reference.</simpara>
  102. </description>
  103. <notes>
  104. <simpara>As part of its guarantee of type-safety, <code>polymorphic_get</code>
  105. enforces <code>const</code>-correctness. Thus, the specified type
  106. <code>U</code> must be <code>const</code>-qualified whenever
  107. <code>operand</code> or its content is likewise
  108. <code>const</code>-qualified. The converse, however, is not required:
  109. that is, the specified type <code>U</code> may be
  110. <code>const</code>-qualified even when <code>operand</code> and its
  111. content are not.</simpara>
  112. </notes>
  113. <returns>
  114. <simpara>If passed a pointer, <code>polymorphic_get</code> returns a pointer to
  115. the value content if it is of the specified type <code>U</code> or of type
  116. derived from type <code>U</code>;
  117. otherwise, a null pointer is returned. If passed a reference,
  118. <code>polymorphic_get</code> returns a reference to the value content if it is of
  119. the specified type <code>U</code> or of type
  120. derived from type <code>U</code>; otherwise, an exception is thrown
  121. (see below).</simpara>
  122. </returns>
  123. <throws>
  124. <simpara>Overloads taking a
  125. <code><classname>variant</classname></code> pointer will not
  126. throw; the overloads taking a
  127. <code><classname>variant</classname></code> reference throw
  128. <code><classname>bad_polymorphic_get</classname></code> if the content is not of
  129. the specified type <code>U</code>or of type
  130. derived from type <code>U</code>.</simpara>
  131. </throws>
  132. <rationale>
  133. <simpara>While visitation via
  134. <code><functionname>apply_visitor</functionname></code>
  135. is generally preferred due to its greater safety, <code>polymorphic_get</code> may
  136. may be more convenient in some cases due to its straightforward
  137. usage.</simpara>
  138. </rationale>
  139. </overloaded-function>
  140. <overloaded-function name="polymorphic_strict_get">
  141. <signature>
  142. <template>
  143. <template-type-parameter name="U"/>
  144. <template-type-parameter name="T1"/>
  145. <template-type-parameter name="T2"/>
  146. <template-varargs/>
  147. <template-type-parameter name="TN"/>
  148. </template>
  149. <type>U *</type>
  150. <parameter name="operand">
  151. <paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; *</paramtype>
  152. </parameter>
  153. </signature>
  154. <signature>
  155. <template>
  156. <template-type-parameter name="U"/>
  157. <template-type-parameter name="T1"/>
  158. <template-type-parameter name="T2"/>
  159. <template-varargs/>
  160. <template-type-parameter name="TN"/>
  161. </template>
  162. <type>const U *</type>
  163. <parameter name="operand">
  164. <paramtype>const <classname>variant</classname>&lt;T1, T2, ..., TN&gt; *</paramtype>
  165. </parameter>
  166. </signature>
  167. <signature>
  168. <template>
  169. <template-type-parameter name="U"/>
  170. <template-type-parameter name="T1"/>
  171. <template-type-parameter name="T2"/>
  172. <template-varargs/>
  173. <template-type-parameter name="TN"/>
  174. </template>
  175. <type>U &amp;</type>
  176. <parameter name="operand">
  177. <paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;</paramtype>
  178. </parameter>
  179. </signature>
  180. <signature>
  181. <template>
  182. <template-type-parameter name="U"/>
  183. <template-type-parameter name="T1"/>
  184. <template-type-parameter name="T2"/>
  185. <template-varargs/>
  186. <template-type-parameter name="TN"/>
  187. </template>
  188. <type>const U &amp;</type>
  189. <parameter name="operand">
  190. <paramtype>const <classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;</paramtype>
  191. </parameter>
  192. </signature>
  193. <purpose>
  194. <simpara>Retrieves a value of a specified type from a given
  195. <code><classname>variant</classname></code>.</simpara>
  196. </purpose>
  197. <description>
  198. <simpara>Acts exactly like <functionname>polymorphic_relaxed_get</functionname> but does a compile time check
  199. that type <code>U</code> is one of the types that can be stored in variant.</simpara>
  200. </description>
  201. </overloaded-function>
  202. <overloaded-function name="polymorphic_get">
  203. <signature>
  204. <template>
  205. <template-type-parameter name="U"/>
  206. <template-type-parameter name="T1"/>
  207. <template-type-parameter name="T2"/>
  208. <template-varargs/>
  209. <template-type-parameter name="TN"/>
  210. </template>
  211. <type>U *</type>
  212. <parameter name="operand">
  213. <paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; *</paramtype>
  214. </parameter>
  215. </signature>
  216. <signature>
  217. <template>
  218. <template-type-parameter name="U"/>
  219. <template-type-parameter name="T1"/>
  220. <template-type-parameter name="T2"/>
  221. <template-varargs/>
  222. <template-type-parameter name="TN"/>
  223. </template>
  224. <type>const U *</type>
  225. <parameter name="operand">
  226. <paramtype>const <classname>variant</classname>&lt;T1, T2, ..., TN&gt; *</paramtype>
  227. </parameter>
  228. </signature>
  229. <signature>
  230. <template>
  231. <template-type-parameter name="U"/>
  232. <template-type-parameter name="T1"/>
  233. <template-type-parameter name="T2"/>
  234. <template-varargs/>
  235. <template-type-parameter name="TN"/>
  236. </template>
  237. <type>U &amp;</type>
  238. <parameter name="operand">
  239. <paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;</paramtype>
  240. </parameter>
  241. </signature>
  242. <signature>
  243. <template>
  244. <template-type-parameter name="U"/>
  245. <template-type-parameter name="T1"/>
  246. <template-type-parameter name="T2"/>
  247. <template-varargs/>
  248. <template-type-parameter name="TN"/>
  249. </template>
  250. <type>const U &amp;</type>
  251. <parameter name="operand">
  252. <paramtype>const <classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;</paramtype>
  253. </parameter>
  254. </signature>
  255. <purpose>
  256. <simpara>Retrieves a value of a specified type from a given
  257. <code><classname>variant</classname></code>.</simpara>
  258. </purpose>
  259. <description>
  260. <simpara>Evaluates to <functionname>polymorphic_strict_get</functionname>
  261. if <code>BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT</code>
  262. is not defined. If <code>BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT</code>
  263. is defined then evaluates to <functionname>polymorphic_relaxed_get</functionname>. </simpara>
  264. <simpara><emphasis role="bold">Recomendation</emphasis>: Use
  265. <functionname>polymorphic_get</functionname> in new code without defining
  266. <code>BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT</code>. In that way
  267. <functionname>polymorphic_get</functionname>
  268. provides more compile time checks and its behavior is closer to <code>std::get</code>
  269. from C++ Standard Library.</simpara>
  270. </description>
  271. </overloaded-function>
  272. </namespace>
  273. </header>