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