get.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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. 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/get.hpp">
  10. <namespace name="boost">
  11. <class name="bad_get">
  12. <inherit access="public">
  13. <classname>std::exception</classname>
  14. </inherit>
  15. <purpose>
  16. <simpara>The exception thrown in the event of a failed application of
  17. <code><functionname>boost::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="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. <signature>
  78. <template>
  79. <template-type-parameter name="U"/>
  80. <template-type-parameter name="T1"/>
  81. <template-type-parameter name="T2"/>
  82. <template-varargs/>
  83. <template-type-parameter name="TN"/>
  84. </template>
  85. <type>U &amp;&amp;</type>
  86. <parameter name="operand">
  87. <paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;&amp;</paramtype>
  88. </parameter>
  89. </signature>
  90. <purpose>
  91. <simpara>Retrieves a value of a specified type from a given
  92. <code><classname>variant</classname></code>. </simpara>
  93. <simpara>Unlike <functionname>strict_get</functionname> does not assert at compile time
  94. that type <code>U</code> is one of the types that can be stored in variant.</simpara>
  95. </purpose>
  96. <description>
  97. <simpara>The <code>get</code> function allows run-time checked,
  98. type-safe retrieval of the content of the given
  99. <code><classname>variant</classname></code>. The function succeeds
  100. only if the content is of the specified type <code>U</code>, with
  101. failure indicated as described below.</simpara>
  102. <simpara><emphasis role="bold">Recomendation</emphasis>: Use
  103. <functionname>get</functionname> or <functionname>strict_get</functionname> in new code.
  104. <functionname>strict_get</functionname>
  105. provides more compile time checks and its behavior is closer to <code>std::get</code>
  106. from C++ Standard Library.</simpara>
  107. <simpara><emphasis role="bold">Warning</emphasis>: After either
  108. <code>operand</code> or its content is destroyed (e.g., when the
  109. given <code><classname>variant</classname></code> is assigned a
  110. value of different type), the returned reference is invalidated.
  111. Thus, significant care and caution must be extended when handling
  112. the returned reference.</simpara>
  113. </description>
  114. <notes>
  115. <simpara>As part of its guarantee of type-safety, <code>get</code>
  116. enforces <code>const</code>-correctness. Thus, the specified type
  117. <code>U</code> must be <code>const</code>-qualified whenever
  118. <code>operand</code> or its content is likewise
  119. <code>const</code>-qualified. The converse, however, is not required:
  120. that is, the specified type <code>U</code> may be
  121. <code>const</code>-qualified even when <code>operand</code> and its
  122. content are not.</simpara>
  123. </notes>
  124. <returns>
  125. <simpara>If passed a pointer, <code>get</code> returns a pointer to
  126. the value content if it is of the specified type <code>U</code>;
  127. otherwise, a null pointer is returned. If passed a reference,
  128. <code>get</code> returns a reference to the value content if it is of
  129. the specified type <code>U</code>; otherwise, an exception is thrown
  130. (see below).</simpara>
  131. </returns>
  132. <throws>
  133. <simpara>Overloads taking a
  134. <code><classname>variant</classname></code> pointer will not
  135. throw; the overloads taking a
  136. <code><classname>variant</classname></code> reference throw
  137. <code><classname>bad_get</classname></code> if the content is not of
  138. the specified type <code>U</code>.</simpara>
  139. </throws>
  140. <rationale>
  141. <simpara>While visitation via
  142. <code><functionname>apply_visitor</functionname></code>
  143. is generally preferred due to its greater safety, <code>get</code> may
  144. may be more convenient in some cases due to its straightforward
  145. usage.</simpara>
  146. </rationale>
  147. </overloaded-function>
  148. <overloaded-function name="strict_get">
  149. <signature>
  150. <template>
  151. <template-type-parameter name="U"/>
  152. <template-type-parameter name="T1"/>
  153. <template-type-parameter name="T2"/>
  154. <template-varargs/>
  155. <template-type-parameter name="TN"/>
  156. </template>
  157. <type>U *</type>
  158. <parameter name="operand">
  159. <paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; *</paramtype>
  160. </parameter>
  161. </signature>
  162. <signature>
  163. <template>
  164. <template-type-parameter name="U"/>
  165. <template-type-parameter name="T1"/>
  166. <template-type-parameter name="T2"/>
  167. <template-varargs/>
  168. <template-type-parameter name="TN"/>
  169. </template>
  170. <type>const U *</type>
  171. <parameter name="operand">
  172. <paramtype>const <classname>variant</classname>&lt;T1, T2, ..., TN&gt; *</paramtype>
  173. </parameter>
  174. </signature>
  175. <signature>
  176. <template>
  177. <template-type-parameter name="U"/>
  178. <template-type-parameter name="T1"/>
  179. <template-type-parameter name="T2"/>
  180. <template-varargs/>
  181. <template-type-parameter name="TN"/>
  182. </template>
  183. <type>U &amp;</type>
  184. <parameter name="operand">
  185. <paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;</paramtype>
  186. </parameter>
  187. </signature>
  188. <signature>
  189. <template>
  190. <template-type-parameter name="U"/>
  191. <template-type-parameter name="T1"/>
  192. <template-type-parameter name="T2"/>
  193. <template-varargs/>
  194. <template-type-parameter name="TN"/>
  195. </template>
  196. <type>const U &amp;</type>
  197. <parameter name="operand">
  198. <paramtype>const <classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;</paramtype>
  199. </parameter>
  200. </signature>
  201. <signature>
  202. <template>
  203. <template-type-parameter name="U"/>
  204. <template-type-parameter name="T1"/>
  205. <template-type-parameter name="T2"/>
  206. <template-varargs/>
  207. <template-type-parameter name="TN"/>
  208. </template>
  209. <type>U &amp;&amp;</type>
  210. <parameter name="operand">
  211. <paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;&amp;</paramtype>
  212. </parameter>
  213. </signature>
  214. <purpose>
  215. <simpara>Retrieves a value of a specified type from a given
  216. <code><classname>variant</classname></code>.</simpara>
  217. </purpose>
  218. <description>
  219. <simpara>Acts exactly like <functionname>relaxed_get</functionname> but does a compile time check
  220. that type <code>U</code> is one of the types that can be stored in variant.</simpara>
  221. </description>
  222. </overloaded-function>
  223. <overloaded-function name="get">
  224. <signature>
  225. <template>
  226. <template-type-parameter name="U"/>
  227. <template-type-parameter name="T1"/>
  228. <template-type-parameter name="T2"/>
  229. <template-varargs/>
  230. <template-type-parameter name="TN"/>
  231. </template>
  232. <type>U *</type>
  233. <parameter name="operand">
  234. <paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; *</paramtype>
  235. </parameter>
  236. </signature>
  237. <signature>
  238. <template>
  239. <template-type-parameter name="U"/>
  240. <template-type-parameter name="T1"/>
  241. <template-type-parameter name="T2"/>
  242. <template-varargs/>
  243. <template-type-parameter name="TN"/>
  244. </template>
  245. <type>const U *</type>
  246. <parameter name="operand">
  247. <paramtype>const <classname>variant</classname>&lt;T1, T2, ..., TN&gt; *</paramtype>
  248. </parameter>
  249. </signature>
  250. <signature>
  251. <template>
  252. <template-type-parameter name="U"/>
  253. <template-type-parameter name="T1"/>
  254. <template-type-parameter name="T2"/>
  255. <template-varargs/>
  256. <template-type-parameter name="TN"/>
  257. </template>
  258. <type>U &amp;</type>
  259. <parameter name="operand">
  260. <paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;</paramtype>
  261. </parameter>
  262. </signature>
  263. <signature>
  264. <template>
  265. <template-type-parameter name="U"/>
  266. <template-type-parameter name="T1"/>
  267. <template-type-parameter name="T2"/>
  268. <template-varargs/>
  269. <template-type-parameter name="TN"/>
  270. </template>
  271. <type>const U &amp;</type>
  272. <parameter name="operand">
  273. <paramtype>const <classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;</paramtype>
  274. </parameter>
  275. </signature>
  276. <signature>
  277. <template>
  278. <template-type-parameter name="U"/>
  279. <template-type-parameter name="T1"/>
  280. <template-type-parameter name="T2"/>
  281. <template-varargs/>
  282. <template-type-parameter name="TN"/>
  283. </template>
  284. <type>U &amp;&amp;</type>
  285. <parameter name="operand">
  286. <paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;&amp;</paramtype>
  287. </parameter>
  288. </signature>
  289. <purpose>
  290. <simpara>Retrieves a value of a specified type from a given
  291. <code><classname>variant</classname></code>.</simpara>
  292. </purpose>
  293. <description>
  294. <simpara>Evaluates to <functionname>strict_get</functionname> if <code>BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT</code>
  295. is not defined. If <code>BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT</code>
  296. is defined then evaluates to <functionname>relaxed_get</functionname>. </simpara>
  297. <simpara><emphasis role="bold">Recomendation</emphasis>: Use
  298. <functionname>get</functionname> in new code without defining
  299. <code>BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT</code>. In that way <functionname>get</functionname>
  300. provides more compile time checks and its behavior is closer to <code>std::get</code>
  301. from C++ Standard Library.</simpara>
  302. </description>
  303. </overloaded-function>
  304. </namespace>
  305. </header>