summaryrefslogtreecommitdiff
path: root/doc/html/get.html
blob: 62e0c55cc7d0ed865d0f61c52182bdeb71f88d48 (plain)
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
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Function get</title>
<link rel="stylesheet" href="boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.69.1">
<link rel="start" href="index.html" title="The Boost C++ Libraries">
<link rel="up" href="variant/reference.html#id2588868" title="Header &lt;boost/variant/get.hpp&gt;">
<link rel="prev" href="bad_get.html" title="Class bad_get">
<link rel="next" href="bad_visit.html" title="Class bad_visit">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%">
<td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../boost.png"></td>
<td align="center"><a href="../../index.htm">Home</a></td>
<td align="center"><a href="../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="../../people/people.htm">People</a></td>
<td align="center"><a href="../../more/faq.htm">FAQ</a></td>
<td align="center"><a href="../../more/index.htm">More</a></td>
</table>
<hr>
<div class="spirit-nav">
<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>
</div>
<div class="refentry" lang="en">
<a name="get"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2><span class="refentrytitle">Function get</span></h2>
<p>boost::get &#8212; <p>Retrieves a value of a specified type from a given
          <code class="computeroutput"><a href="boost/variant.html" title="Class template variant">variant</a></code>.</p></p>
</div>
<h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2>
<div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis">
<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; 
  <span class="type">U *</span> get(<a href="boost/variant.html" title="Class template variant">variant</a>&lt;T1, T2, ..., TN&gt; * operand);
<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; 
  <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>&lt;T1, T2, ..., TN&gt; * operand);
<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; 
  <span class="type">U &amp;</span> get(<a href="boost/variant.html" title="Class template variant">variant</a>&lt;T1, T2, ..., TN&gt; &amp; operand);
<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; 
  <span class="type"><span class="bold"><strong>const</strong></span> U &amp;</span> get(<span class="bold"><strong>const</strong></span> <a href="boost/variant.html" title="Class template variant">variant</a>&lt;T1, T2, ..., TN&gt; &amp; operand);</pre></div>
<div class="refsect1" lang="en">
<a name="id2839339"></a><h2>Description</h2>
<p>The <code class="computeroutput">get</code> function allows run-time checked,
          type-safe retrieval of the content of the given
          <code class="computeroutput"><a href="boost/variant.html" title="Class template variant">variant</a></code>. The function succeeds
          only if the content is of the specified type <code class="computeroutput">U</code>, with
          failure indicated as described below.</p>
<p><span class="bold"><strong>Warning</strong></span>: After either
          <code class="computeroutput">operand</code> or its content is destroyed (e.g., when the
          given <code class="computeroutput"><a href="boost/variant.html" title="Class template variant">variant</a></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.</p>
<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Notes</span></b>:

    As part of its guarantee of type-safety, <code class="computeroutput">get</code>
        enforces <code class="computeroutput">const</code>-correctness. Thus, the specified type
        <code class="computeroutput">U</code> must be <code class="computeroutput">const</code>-qualified whenever
        <code class="computeroutput">operand</code> or its content is likewise
        <code class="computeroutput">const</code>-qualified. The converse, however, is not required:
        that is, the specified type <code class="computeroutput">U</code> may be
        <code class="computeroutput">const</code>-qualified even when <code class="computeroutput">operand</code> and its
        content are not.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Returns</span></b>:

    If passed a pointer, <code class="computeroutput">get</code> returns a pointer to
        the value content if it is of the specified type <code class="computeroutput">U</code>;
        otherwise, a null pointer is returned. If passed a reference,
        <code class="computeroutput">get</code> returns a reference to the value content if it is of
        the specified type <code class="computeroutput">U</code>; otherwise, an exception is thrown
        (see below).<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Throws</span></b>:

    Overloads taking a
        <code class="computeroutput"><a href="boost/variant.html" title="Class template variant">variant</a></code> pointer will not
        throw; the overloads taking a
        <code class="computeroutput"><a href="boost/variant.html" title="Class template variant">variant</a></code> reference throw
        <code class="computeroutput"><a href="bad_get.html" title="Class bad_get">bad_get</a></code> if the content is not of
        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>:

    While visitation via
        <code class="computeroutput"><a href="apply_visitor.html" title="Function apply_visitor">apply_visitor</a></code>
        is generally prefered due to its greater safety, <code class="computeroutput">get</code> may
        may be more convenient in some cases due to its straightforward
        usage.</p>
</div>
</div>
<table width="100%"><tr>
<td align="left"></td>
<td align="right"><small>Copyright © 2002, 2003 Eric Friedman, Itay Maman</small></td>
</tr></table>
<hr>
<div class="spirit-nav">
<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>
</div>
</body>
</html>