1 | <html> |
---|
2 | <head> |
---|
3 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
---|
4 | <title>Function get</title> |
---|
5 | <link rel="stylesheet" href="boostbook.css" type="text/css"> |
---|
6 | <meta name="generator" content="DocBook XSL Stylesheets V1.69.1"> |
---|
7 | <link rel="start" href="index.html" title="The Boost C++ Libraries"> |
---|
8 | <link rel="up" href="variant/reference.html#id2588868" title="Header <boost/variant/get.hpp>"> |
---|
9 | <link rel="prev" href="bad_get.html" title="Class bad_get"> |
---|
10 | <link rel="next" href="bad_visit.html" title="Class bad_visit"> |
---|
11 | </head> |
---|
12 | <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> |
---|
13 | <table cellpadding="2" width="100%"> |
---|
14 | <td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../boost.png"></td> |
---|
15 | <td align="center"><a href="../../index.htm">Home</a></td> |
---|
16 | <td align="center"><a href="../../libs/libraries.htm">Libraries</a></td> |
---|
17 | <td align="center"><a href="../../people/people.htm">People</a></td> |
---|
18 | <td align="center"><a href="../../more/faq.htm">FAQ</a></td> |
---|
19 | <td align="center"><a href="../../more/index.htm">More</a></td> |
---|
20 | </table> |
---|
21 | <hr> |
---|
22 | <div class="spirit-nav"> |
---|
23 | <a accesskey="p" href="bad_get.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="variant/reference.html#id2588868"><img src="images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a><a accesskey="n" href="bad_visit.html"><img src="images/next.png" alt="Next"></a> |
---|
24 | </div> |
---|
25 | <div class="refentry" lang="en"> |
---|
26 | <a name="get"></a><div class="titlepage"></div> |
---|
27 | <div class="refnamediv"> |
---|
28 | <h2><span class="refentrytitle">Function get</span></h2> |
---|
29 | <p>boost::get — <p>Retrieves a value of a specified type from a given |
---|
30 | <code class="computeroutput"><a href="boost/variant.html" title="Class template variant">variant</a></code>.</p></p> |
---|
31 | </div> |
---|
32 | <h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2> |
---|
33 | <div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"> |
---|
34 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> U, <span class="bold"><strong>typename</strong></span> T1, <span class="bold"><strong>typename</strong></span> T2, ..., <span class="bold"><strong>typename</strong></span> TN> |
---|
35 | <span class="type">U *</span> get(<a href="boost/variant.html" title="Class template variant">variant</a><T1, T2, ..., TN> * operand); |
---|
36 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> U, <span class="bold"><strong>typename</strong></span> T1, <span class="bold"><strong>typename</strong></span> T2, ..., <span class="bold"><strong>typename</strong></span> TN> |
---|
37 | <span class="type"><span class="bold"><strong>const</strong></span> U *</span> get(<span class="bold"><strong>const</strong></span> <a href="boost/variant.html" title="Class template variant">variant</a><T1, T2, ..., TN> * operand); |
---|
38 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> U, <span class="bold"><strong>typename</strong></span> T1, <span class="bold"><strong>typename</strong></span> T2, ..., <span class="bold"><strong>typename</strong></span> TN> |
---|
39 | <span class="type">U &</span> get(<a href="boost/variant.html" title="Class template variant">variant</a><T1, T2, ..., TN> & operand); |
---|
40 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> U, <span class="bold"><strong>typename</strong></span> T1, <span class="bold"><strong>typename</strong></span> T2, ..., <span class="bold"><strong>typename</strong></span> TN> |
---|
41 | <span class="type"><span class="bold"><strong>const</strong></span> U &</span> get(<span class="bold"><strong>const</strong></span> <a href="boost/variant.html" title="Class template variant">variant</a><T1, T2, ..., TN> & operand);</pre></div> |
---|
42 | <div class="refsect1" lang="en"> |
---|
43 | <a name="id2839339"></a><h2>Description</h2> |
---|
44 | <p>The <code class="computeroutput">get</code> function allows run-time checked, |
---|
45 | type-safe retrieval of the content of the given |
---|
46 | <code class="computeroutput"><a href="boost/variant.html" title="Class template variant">variant</a></code>. The function succeeds |
---|
47 | only if the content is of the specified type <code class="computeroutput">U</code>, with |
---|
48 | failure indicated as described below.</p> |
---|
49 | <p><span class="bold"><strong>Warning</strong></span>: After either |
---|
50 | <code class="computeroutput">operand</code> or its content is destroyed (e.g., when the |
---|
51 | given <code class="computeroutput"><a href="boost/variant.html" title="Class template variant">variant</a></code> is assigned a |
---|
52 | value of different type), the returned reference is invalidated. |
---|
53 | Thus, significant care and caution must be extended when handling |
---|
54 | the returned reference.</p> |
---|
55 | <p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Notes</span></b>: |
---|
56 | |
---|
57 | As part of its guarantee of type-safety, <code class="computeroutput">get</code> |
---|
58 | enforces <code class="computeroutput">const</code>-correctness. Thus, the specified type |
---|
59 | <code class="computeroutput">U</code> must be <code class="computeroutput">const</code>-qualified whenever |
---|
60 | <code class="computeroutput">operand</code> or its content is likewise |
---|
61 | <code class="computeroutput">const</code>-qualified. The converse, however, is not required: |
---|
62 | that is, the specified type <code class="computeroutput">U</code> may be |
---|
63 | <code class="computeroutput">const</code>-qualified even when <code class="computeroutput">operand</code> and its |
---|
64 | content are not.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Returns</span></b>: |
---|
65 | |
---|
66 | If passed a pointer, <code class="computeroutput">get</code> returns a pointer to |
---|
67 | the value content if it is of the specified type <code class="computeroutput">U</code>; |
---|
68 | otherwise, a null pointer is returned. If passed a reference, |
---|
69 | <code class="computeroutput">get</code> returns a reference to the value content if it is of |
---|
70 | the specified type <code class="computeroutput">U</code>; otherwise, an exception is thrown |
---|
71 | (see below).<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Throws</span></b>: |
---|
72 | |
---|
73 | Overloads taking a |
---|
74 | <code class="computeroutput"><a href="boost/variant.html" title="Class template variant">variant</a></code> pointer will not |
---|
75 | throw; the overloads taking a |
---|
76 | <code class="computeroutput"><a href="boost/variant.html" title="Class template variant">variant</a></code> reference throw |
---|
77 | <code class="computeroutput"><a href="bad_get.html" title="Class bad_get">bad_get</a></code> if the content is not of |
---|
78 | the specified type <code class="computeroutput">U</code>.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Rationale</span></b>: |
---|
79 | |
---|
80 | While visitation via |
---|
81 | <code class="computeroutput"><a href="apply_visitor.html" title="Function apply_visitor">apply_visitor</a></code> |
---|
82 | is generally prefered due to its greater safety, <code class="computeroutput">get</code> may |
---|
83 | may be more convenient in some cases due to its straightforward |
---|
84 | usage.</p> |
---|
85 | </div> |
---|
86 | </div> |
---|
87 | <table width="100%"><tr> |
---|
88 | <td align="left"></td> |
---|
89 | <td align="right"><small>Copyright © 2002, 2003 Eric Friedman, Itay Maman</small></td> |
---|
90 | </tr></table> |
---|
91 | <hr> |
---|
92 | <div class="spirit-nav"> |
---|
93 | <a accesskey="p" href="bad_get.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="variant/reference.html#id2588868"><img src="images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a><a accesskey="n" href="bad_visit.html"><img src="images/next.png" alt="Next"></a> |
---|
94 | </div> |
---|
95 | </body> |
---|
96 | </html> |
---|