File: polymorphic_get.xml

package info (click to toggle)
boost1.88 1.88.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 576,932 kB
  • sloc: cpp: 4,149,234; xml: 136,789; ansic: 35,092; python: 33,910; asm: 5,698; sh: 4,604; ada: 1,681; makefile: 1,633; pascal: 1,139; perl: 1,124; sql: 640; yacc: 478; ruby: 271; java: 77; lisp: 24; csh: 6
file content (326 lines) | stat: -rw-r--r-- 11,849 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE header PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
  "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
<!--
    Copyright 2013-2025 Antony Polukhin.

    Distributed under the Boost Software License, Version 1.0. (See accompanying
    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-->
<header name="boost/variant/polymorphic_get.hpp">
  <namespace name="boost">

    <class name="bad_polymorphic_get">
      <inherit access="public">
        <classname>boost::bad_get</classname>
      </inherit>

      <purpose>
        <simpara>The exception thrown in the event of a failed application of
        <code><functionname>boost::polymorphic_get</functionname></code> on the given
        operand value.</simpara>
      </purpose>

      <method name="what" specifiers="virtual" cv="const">
        <type>const char *</type>
      </method>
    </class>

    <overloaded-function name="polymorphic_relaxed_get">
      <signature>
        <template>
          <template-type-parameter name="U"/>
          <template-type-parameter name="T1"/>
          <template-type-parameter name="T2"/>
          <template-varargs/>
          <template-type-parameter name="TN"/>
        </template>

        <type>U *</type>

        <parameter name="operand">
          <paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; *</paramtype>
        </parameter>
      </signature>

      <signature>
        <template>
          <template-type-parameter name="U"/>
          <template-type-parameter name="T1"/>
          <template-type-parameter name="T2"/>
          <template-varargs/>
          <template-type-parameter name="TN"/>
        </template>

        <type>const U *</type>

        <parameter name="operand">
          <paramtype>const <classname>variant</classname>&lt;T1, T2, ..., TN&gt; *</paramtype>
        </parameter>
      </signature>

      <signature>
        <template>
          <template-type-parameter name="U"/>
          <template-type-parameter name="T1"/>
          <template-type-parameter name="T2"/>
          <template-varargs/>
          <template-type-parameter name="TN"/>
        </template>

        <type>U &amp;</type>

        <parameter name="operand">
          <paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;</paramtype>
        </parameter>
      </signature>

      <signature>
        <template>
          <template-type-parameter name="U"/>
          <template-type-parameter name="T1"/>
          <template-type-parameter name="T2"/>
          <template-varargs/>
          <template-type-parameter name="TN"/>
        </template>

        <type>const U &amp;</type>

        <parameter name="operand">
          <paramtype>const <classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;</paramtype>
        </parameter>
      </signature>

      <purpose>
        <simpara>Retrieves a value of a specified type from a given
          <code><classname>variant</classname></code>.</simpara>
        <simpara>Unlike <functionname>polymorphic_strict_get</functionname> does not assert at compile time
        that type <code>U</code> is one of the types that can be stored in variant.</simpara>
      </purpose>

      <description>
        <simpara>The <code>polymorphic_get</code> function allows run-time checked,
          type-safe retrieval of the content of the given
          <code><classname>variant</classname></code>. The function succeeds
          only if the content is of the specified type <code>U</code> or of type
          derived from type <code>U</code>, with
          failure indicated as described below.</simpara>
        <simpara><emphasis role="bold">Recomendation</emphasis>: Use
          <functionname>polymorphic_get</functionname> or <functionname>polymorphic_strict_get</functionname>
          in new code.
          <functionname>polymorphic_strict_get</functionname>
          provides more compile time checks and its behavior is closer to <code>std::get</code>
          from C++ Standard Library.</simpara>
        <simpara><emphasis role="bold">Warning</emphasis>: After either
          <code>operand</code> or its content is destroyed (e.g., when the
          given <code><classname>variant</classname></code> is assigned a
          value of different type), the returned reference is invalidated.
          Thus, significant care and caution must be extended when handling
          the returned reference.</simpara>
      </description>

      <notes>
        <simpara>As part of its guarantee of type-safety, <code>polymorphic_get</code>
        enforces <code>const</code>-correctness. Thus, the specified type
        <code>U</code> must be <code>const</code>-qualified whenever
        <code>operand</code> or its content is likewise
        <code>const</code>-qualified. The converse, however, is not required:
        that is, the specified type <code>U</code> may be
        <code>const</code>-qualified even when <code>operand</code> and its
        content are not.</simpara>
      </notes>

      <returns>
        <simpara>If passed a pointer, <code>polymorphic_get</code> returns a pointer to
        the value content if it is of the specified type <code>U</code> or of type
        derived from type <code>U</code>;
        otherwise, a null pointer is returned. If passed a reference,
        <code>polymorphic_get</code> returns a reference to the value content if it is of
        the specified type <code>U</code>  or of type
          derived from type <code>U</code>; otherwise, an exception is thrown
        (see below).</simpara>
      </returns>

      <throws>
        <simpara>Overloads taking a
        <code><classname>variant</classname></code> pointer will not
        throw; the overloads taking a
        <code><classname>variant</classname></code> reference throw
        <code><classname>bad_polymorphic_get</classname></code> if the content is not of
        the specified type <code>U</code>or of type
        derived from type <code>U</code>.</simpara>
      </throws>

      <rationale>
        <simpara>While visitation via
        <code><functionname>apply_visitor</functionname></code>
        is generally preferred due to its greater safety, <code>polymorphic_get</code> may
        may be more convenient in some cases due to its straightforward
        usage.</simpara>
      </rationale>
    </overloaded-function>



    <overloaded-function name="polymorphic_strict_get">
      <signature>
        <template>
          <template-type-parameter name="U"/>
          <template-type-parameter name="T1"/>
          <template-type-parameter name="T2"/>
          <template-varargs/>
          <template-type-parameter name="TN"/>
        </template>

        <type>U *</type>

        <parameter name="operand">
          <paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; *</paramtype>
        </parameter>
      </signature>

      <signature>
        <template>
          <template-type-parameter name="U"/>
          <template-type-parameter name="T1"/>
          <template-type-parameter name="T2"/>
          <template-varargs/>
          <template-type-parameter name="TN"/>
        </template>

        <type>const U *</type>

        <parameter name="operand">
          <paramtype>const <classname>variant</classname>&lt;T1, T2, ..., TN&gt; *</paramtype>
        </parameter>
      </signature>

      <signature>
        <template>
          <template-type-parameter name="U"/>
          <template-type-parameter name="T1"/>
          <template-type-parameter name="T2"/>
          <template-varargs/>
          <template-type-parameter name="TN"/>
        </template>

        <type>U &amp;</type>

        <parameter name="operand">
          <paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;</paramtype>
        </parameter>
      </signature>

      <signature>
        <template>
          <template-type-parameter name="U"/>
          <template-type-parameter name="T1"/>
          <template-type-parameter name="T2"/>
          <template-varargs/>
          <template-type-parameter name="TN"/>
        </template>

        <type>const U &amp;</type>

        <parameter name="operand">
          <paramtype>const <classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;</paramtype>
        </parameter>
      </signature>

      <purpose>
        <simpara>Retrieves a value of a specified type from a given
          <code><classname>variant</classname></code>.</simpara>
      </purpose>

      <description>
        <simpara>Acts exactly like <functionname>polymorphic_relaxed_get</functionname> but does a compile time check
        that type <code>U</code> is one of the types that can be stored in variant.</simpara>
      </description>
    </overloaded-function>

    <overloaded-function name="polymorphic_get">
      <signature>
        <template>
          <template-type-parameter name="U"/>
          <template-type-parameter name="T1"/>
          <template-type-parameter name="T2"/>
          <template-varargs/>
          <template-type-parameter name="TN"/>
        </template>

        <type>U *</type>

        <parameter name="operand">
          <paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; *</paramtype>
        </parameter>
      </signature>

      <signature>
        <template>
          <template-type-parameter name="U"/>
          <template-type-parameter name="T1"/>
          <template-type-parameter name="T2"/>
          <template-varargs/>
          <template-type-parameter name="TN"/>
        </template>

        <type>const U *</type>

        <parameter name="operand">
          <paramtype>const <classname>variant</classname>&lt;T1, T2, ..., TN&gt; *</paramtype>
        </parameter>
      </signature>

      <signature>
        <template>
          <template-type-parameter name="U"/>
          <template-type-parameter name="T1"/>
          <template-type-parameter name="T2"/>
          <template-varargs/>
          <template-type-parameter name="TN"/>
        </template>

        <type>U &amp;</type>

        <parameter name="operand">
          <paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;</paramtype>
        </parameter>
      </signature>

      <signature>
        <template>
          <template-type-parameter name="U"/>
          <template-type-parameter name="T1"/>
          <template-type-parameter name="T2"/>
          <template-varargs/>
          <template-type-parameter name="TN"/>
        </template>

        <type>const U &amp;</type>

        <parameter name="operand">
          <paramtype>const <classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;</paramtype>
        </parameter>
      </signature>

      <purpose>
        <simpara>Retrieves a value of a specified type from a given
          <code><classname>variant</classname></code>.</simpara>
      </purpose>

      <description>
        <simpara>Evaluates to <functionname>polymorphic_strict_get</functionname>
          if <code>BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT</code>
          is not defined. If <code>BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT</code>
          is defined then evaluates to <functionname>polymorphic_relaxed_get</functionname>. </simpara>

        <simpara><emphasis role="bold">Recomendation</emphasis>: Use
          <functionname>polymorphic_get</functionname> in new code without defining
          <code>BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT</code>. In that way
          <functionname>polymorphic_get</functionname>
          provides more compile time checks and its behavior is closer to <code>std::get</code>
          from C++ Standard Library.</simpara>
      </description>
    </overloaded-function>
  </namespace>
</header>