Imported Upstream version 1.57.0
[platform/upstream/boost.git] / doc / html / boost / get_idp94543392.html
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Function get</title>
5 <link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
6 <meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
7 <link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
8 <link rel="up" href="../variant/reference.html#header.boost.variant.get_hpp" title="Header &lt;boost/variant/get.hpp&gt;">
9 <link rel="prev" href="bad_get.html" title="Class bad_get">
10 <link rel="next" href="bad_polymorphic_get.html" title="Class bad_polymorphic_get">
11 </head>
12 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13 <table cellpadding="2" width="100%"><tr>
14 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
15 <td align="center"><a href="../../../index.html">Home</a></td>
16 <td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
17 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19 <td align="center"><a href="../../../more/index.htm">More</a></td>
20 </tr></table>
21 <hr>
22 <div class="spirit-nav">
23 <a accesskey="p" href="bad_get.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../variant/reference.html#header.boost.variant.get_hpp"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="bad_polymorphic_get.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
24 </div>
25 <div class="refentry">
26 <a name="boost.get_idp94543392"></a><div class="titlepage"></div>
27 <div class="refnamediv">
28 <h2><span class="refentrytitle">Function get</span></h2>
29 <p>boost::get &#8212; Retrieves a value of a specified type from a given
30           <code class="computeroutput"><a class="link" href="variant.html" title="Class template variant">variant</a></code>.</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"><span class="comment">// In header: &lt;<a class="link" href="../variant/reference.html#header.boost.variant.get_hpp" title="Header &lt;boost/variant/get.hpp&gt;">boost/variant/get.hpp</a>&gt;
34
35 </span>
36 <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> U<span class="special">,</span> <span class="keyword">typename</span> T1<span class="special">,</span> <span class="keyword">typename</span> T2<span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="keyword">typename</span> TN<span class="special">&gt;</span> 
37   <span class="identifier">U</span> <span class="special">*</span> <span class="identifier">get</span><span class="special">(</span><a class="link" href="variant.html" title="Class template variant">variant</a><span class="special">&lt;</span><span class="identifier">T1</span><span class="special">,</span> <span class="identifier">T2</span><span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="identifier">TN</span><span class="special">&gt;</span> <span class="special">*</span> operand<span class="special">)</span><span class="special">;</span>
38 <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> U<span class="special">,</span> <span class="keyword">typename</span> T1<span class="special">,</span> <span class="keyword">typename</span> T2<span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="keyword">typename</span> TN<span class="special">&gt;</span> 
39   <span class="keyword">const</span> <span class="identifier">U</span> <span class="special">*</span> <span class="identifier">get</span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="variant.html" title="Class template variant">variant</a><span class="special">&lt;</span><span class="identifier">T1</span><span class="special">,</span> <span class="identifier">T2</span><span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="identifier">TN</span><span class="special">&gt;</span> <span class="special">*</span> operand<span class="special">)</span><span class="special">;</span>
40 <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> U<span class="special">,</span> <span class="keyword">typename</span> T1<span class="special">,</span> <span class="keyword">typename</span> T2<span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="keyword">typename</span> TN<span class="special">&gt;</span> 
41   <span class="identifier">U</span> <span class="special">&amp;</span> <span class="identifier">get</span><span class="special">(</span><a class="link" href="variant.html" title="Class template variant">variant</a><span class="special">&lt;</span><span class="identifier">T1</span><span class="special">,</span> <span class="identifier">T2</span><span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="identifier">TN</span><span class="special">&gt;</span> <span class="special">&amp;</span> operand<span class="special">)</span><span class="special">;</span>
42 <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> U<span class="special">,</span> <span class="keyword">typename</span> T1<span class="special">,</span> <span class="keyword">typename</span> T2<span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="keyword">typename</span> TN<span class="special">&gt;</span> 
43   <span class="keyword">const</span> <span class="identifier">U</span> <span class="special">&amp;</span> <span class="identifier">get</span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="variant.html" title="Class template variant">variant</a><span class="special">&lt;</span><span class="identifier">T1</span><span class="special">,</span> <span class="identifier">T2</span><span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="identifier">TN</span><span class="special">&gt;</span> <span class="special">&amp;</span> operand<span class="special">)</span><span class="special">;</span></pre></div>
44 <div class="refsect1">
45 <a name="idp524859824"></a><h2>Description</h2>
46 <p>The <code class="computeroutput">get</code> function allows run-time checked,
47           type-safe retrieval of the content of the given
48           <code class="computeroutput"><a class="link" href="variant.html" title="Class template variant">variant</a></code>. The function succeeds
49           only if the content is of the specified type <code class="computeroutput">U</code>, with
50           failure indicated as described below.</p>
51 <p><span class="bold"><strong>Warning</strong></span>: After either
52           <code class="computeroutput">operand</code> or its content is destroyed (e.g., when the
53           given <code class="computeroutput"><a class="link" href="variant.html" title="Class template variant">variant</a></code> is assigned a
54           value of different type), the returned reference is invalidated.
55           Thus, significant care and caution must be extended when handling
56           the returned reference.</p>
57 <div class="variablelist"><table border="0" class="variablelist compact">
58 <colgroup>
59 <col align="left" valign="top">
60 <col>
61 </colgroup>
62 <tbody>
63 <tr>
64 <td><p><span class="term">Notes:</span></p></td>
65 <td>As part of its guarantee of type-safety, <code class="computeroutput">get</code>
66         enforces <code class="computeroutput">const</code>-correctness. Thus, the specified type
67         <code class="computeroutput">U</code> must be <code class="computeroutput">const</code>-qualified whenever
68         <code class="computeroutput">operand</code> or its content is likewise
69         <code class="computeroutput">const</code>-qualified. The converse, however, is not required:
70         that is, the specified type <code class="computeroutput">U</code> may be
71         <code class="computeroutput">const</code>-qualified even when <code class="computeroutput">operand</code> and its
72         content are not.</td>
73 </tr>
74 <tr>
75 <td><p><span class="term">Returns:</span></p></td>
76 <td>If passed a pointer, <code class="computeroutput">get</code> returns a pointer to
77         the value content if it is of the specified type <code class="computeroutput">U</code>;
78         otherwise, a null pointer is returned. If passed a reference,
79         <code class="computeroutput">get</code> returns a reference to the value content if it is of
80         the specified type <code class="computeroutput">U</code>; otherwise, an exception is thrown
81         (see below).</td>
82 </tr>
83 <tr>
84 <td><p><span class="term">Throws:</span></p></td>
85 <td>Overloads taking a
86         <code class="computeroutput"><a class="link" href="variant.html" title="Class template variant">variant</a></code> pointer will not
87         throw; the overloads taking a
88         <code class="computeroutput"><a class="link" href="variant.html" title="Class template variant">variant</a></code> reference throw
89         <code class="computeroutput"><a class="link" href="bad_get.html" title="Class bad_get">bad_get</a></code> if the content is not of
90         the specified type <code class="computeroutput">U</code>.</td>
91 </tr>
92 <tr>
93 <td><p><span class="term">Rationale:</span></p></td>
94 <td>While visitation via
95         <code class="computeroutput"><a class="link" href="apply_visitor.html" title="Function apply_visitor">apply_visitor</a></code>
96         is generally preferred due to its greater safety, <code class="computeroutput">get</code> may
97         may be more convenient in some cases due to its straightforward
98         usage.</td>
99 </tr>
100 </tbody>
101 </table></div>
102 </div>
103 </div>
104 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
105 <td align="left"></td>
106 <td align="right"><div class="copyright-footer">Copyright &#169; 2002, 2003 Eric Friedman, Itay Maman<p>Distributed under the Boost Software License, Version 1.0.
107     (See accompanying file <code class="filename">LICENSE_1_0.txt</code> or copy at 
108     <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
109     </p>
110 </div></td>
111 </tr></table>
112 <hr>
113 <div class="spirit-nav">
114 <a accesskey="p" href="bad_get.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../variant/reference.html#header.boost.variant.get_hpp"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="bad_polymorphic_get.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
115 </div>
116 </body>
117 </html>