Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/doc/html/boost/get.html @ 29

Last change on this file since 29 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 7.9 KB
Line 
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.68.1">
7<link rel="start" 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_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 C++ Libraries" 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#header.boost.variant.get.hpp"><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="boost.get"></a><div class="titlepage"></div>
27<div class="refnamediv">
28<h2><span class="refentrytitle">Function get</span></h2>
29<p>boost::get &#8212; <p>Retrieves a value of a specified type from a given
30          <code class="computeroutput"><a href="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>&lt;<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&gt; 
35  <span class="type">U *</span> get(<a href="variant.html" title="Class template variant">variant</a>&lt;T1, T2, ..., TN&gt; * operand);
36<span class="bold"><strong>template</strong></span>&lt;<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&gt; 
37  <span class="type"><span class="bold"><strong>const</strong></span> U *</span> get(<span class="bold"><strong>const</strong></span> <a href="variant.html" title="Class template variant">variant</a>&lt;T1, T2, ..., TN&gt; * operand);
38<span class="bold"><strong>template</strong></span>&lt;<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&gt; 
39  <span class="type">U &amp;</span> get(<a href="variant.html" title="Class template variant">variant</a>&lt;T1, T2, ..., TN&gt; &amp; operand);
40<span class="bold"><strong>template</strong></span>&lt;<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&gt; 
41  <span class="type"><span class="bold"><strong>const</strong></span> U &amp;</span> get(<span class="bold"><strong>const</strong></span> <a href="variant.html" title="Class template variant">variant</a>&lt;T1, T2, ..., TN&gt; &amp; operand);</pre></div>
42<div class="refsect1" lang="en">
43<a name="id1950502"></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="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="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<div class="variablelist"><table border="0">
56<col align="left" valign="top">
57<tbody>
58<tr>
59<td>
60<span class="term">Notes:</span></td>
61<td>As part of its guarantee of type-safety, <code class="computeroutput">get</code>
62        enforces <code class="computeroutput">const</code>-correctness. Thus, the specified type
63        <code class="computeroutput">U</code> must be <code class="computeroutput">const</code>-qualified whenever
64        <code class="computeroutput">operand</code> or its content is likewise
65        <code class="computeroutput">const</code>-qualified. The converse, however, is not required:
66        that is, the specified type <code class="computeroutput">U</code> may be
67        <code class="computeroutput">const</code>-qualified even when <code class="computeroutput">operand</code> and its
68        content are not.</td>
69</tr>
70<tr>
71<td>
72<span class="term">Returns:</span></td>
73<td>If passed a pointer, <code class="computeroutput">get</code> returns a pointer to
74        the value content if it is of the specified type <code class="computeroutput">U</code>;
75        otherwise, a null pointer is returned. If passed a reference,
76        <code class="computeroutput">get</code> returns a reference to the value content if it is of
77        the specified type <code class="computeroutput">U</code>; otherwise, an exception is thrown
78        (see below).</td>
79</tr>
80<tr>
81<td>
82<span class="term">Throws:</span></td>
83<td>Overloads taking a
84        <code class="computeroutput"><a href="variant.html" title="Class template variant">variant</a></code> pointer will not
85        throw; the overloads taking a
86        <code class="computeroutput"><a href="variant.html" title="Class template variant">variant</a></code> reference throw
87        <code class="computeroutput"><a href="bad_get.html" title="Class bad_get">bad_get</a></code> if the content is not of
88        the specified type <code class="computeroutput">U</code>.</td>
89</tr>
90<tr>
91<td>
92<span class="term">Rationale:</span></td>
93<td>While visitation via
94        <code class="computeroutput"><a href="apply_visitor.html" title="Function apply_visitor">apply_visitor</a></code>
95        is generally preferred due to its greater safety, <code class="computeroutput">get</code> may
96        may be more convenient in some cases due to its straightforward
97        usage.</td>
98</tr>
99</tbody>
100</table></div>
101</div>
102</div>
103<table width="100%"><tr>
104<td align="left"></td>
105<td align="right"><small>Copyright © 2002, 2003 Eric Friedman, Itay Maman</small></td>
106</tr></table>
107<hr>
108<div class="spirit-nav">
109<a accesskey="p" href="bad_get.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../variant/reference.html#header.boost.variant.get.hpp"><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>
110</div>
111</body>
112</html>
Note: See TracBrowser for help on using the repository browser.