<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> <title>Class any</title> <link rel="stylesheet" href="../boostbook.css" type="text/css"> <meta name="generator" content="DocBook XSL Stylesheets V1.75.2"> <link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset"> <link rel="up" href="../any/reference.html#header.boost.any_hpp" title="Header <boost/any.hpp>"> <link rel="prev" href="bad_any_cast.html" title="Class bad_any_cast"> <link rel="next" href="any_cast.html" title="Function any_cast"> </head> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <table cellpadding="2" width="100%"><tr> <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td> <td align="center"><a href="../../../index.html">Home</a></td> <td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td> <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> <td align="center"><a href="../../../more/index.htm">More</a></td> </tr></table> <hr> <div class="spirit-nav"> <a accesskey="p" href="bad_any_cast.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../any/reference.html#header.boost.any_hpp"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="any_cast.html"><img src="../../../doc/html/images/next.png" alt="Next"></a> </div> <div class="refentry" title="Class any"> <a name="boost.any"></a><div class="titlepage"></div> <div class="refnamediv"> <h2><span class="refentrytitle">Class any</span></h2> <p>boost::any — A class whose instances can hold instances of any type that satisfies <a class="link" href="../any/reference.html#any.ValueType" title="ValueType requirements">ValueType</a> requirements.</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="emphasis"><em>// In header: <<a class="link" href="../any/reference.html#header.boost.any_hpp" title="Header <boost/any.hpp>">boost/any.hpp</a>> </em></span> <span class="bold"><strong>class</strong></span> <a class="link" href="any.html" title="Class any">any</a> { <span class="bold"><strong>public</strong></span>: <span class="emphasis"><em>// <a class="link" href="any.html#boost.anyconstruct-copy-destruct">construct/copy/destruct</a></em></span> <a class="link" href="any.html#id420000-bb">any</a>(); <a class="link" href="any.html#id420012-bb">any</a>(<span class="bold"><strong>const</strong></span> <a class="link" href="any.html" title="Class any">any</a> &); <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> ValueType> <a class="link" href="any.html#id420054-bb">any</a>(<span class="bold"><strong>const</strong></span> ValueType &); <span class="type"><a class="link" href="any.html" title="Class any">any</a> &</span> <a class="link" href="any.html#id420108-bb"><span class="bold"><strong>operator</strong></span>=</a>(<span class="bold"><strong>const</strong></span> <a class="link" href="any.html" title="Class any">any</a> &); <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> ValueType> <span class="type"><a class="link" href="any.html" title="Class any">any</a> &</span> <a class="link" href="any.html#id420158-bb"><span class="bold"><strong>operator</strong></span>=</a>(<span class="bold"><strong>const</strong></span> ValueType &); <a class="link" href="any.html#id420095-bb">~any</a>(); <span class="emphasis"><em>// <a class="link" href="any.html#id420206-bb">modifiers</a></em></span> <span class="type"><a class="link" href="any.html" title="Class any">any</a> &</span> <a class="link" href="any.html#id420210-bb">swap</a>(<a class="link" href="any.html" title="Class any">any</a> &); <span class="emphasis"><em>// <a class="link" href="any.html#id420253-bb">queries</a></em></span> <span class="type"><span class="bold"><strong>bool</strong></span></span> <a class="link" href="any.html#id420257-bb">empty</a>() <span class="bold"><strong>const</strong></span>; <span class="type"><span class="bold"><strong>const</strong></span> std::type_info &</span> <a class="link" href="any.html#id420281-bb">type</a>() <span class="bold"><strong>const</strong></span>; };</pre></div> <div class="refsect1" title="Description"> <a name="id724019"></a><h2>Description</h2> <div class="refsect2" title="any public construct/copy/destruct"> <a name="id724022"></a><h3> <a name="boost.anyconstruct-copy-destruct"></a><code class="computeroutput">any</code> public construct/copy/destruct</h3> <div class="orderedlist"><ol class="orderedlist" type="1"> <li class="listitem"> <pre class="literallayout"><a name="id420000-bb"></a>any();</pre> <div class="variablelist"><table border="0"> <col align="left" valign="top"> <tbody><tr> <td><p><span class="term">Postconditions:</span></p></td> <td><code class="computeroutput">this-><a class="link" href="any.html#id420257-bb">empty</a>()</code></td> </tr></tbody> </table></div> </li> <li class="listitem"> <pre class="literallayout"><a name="id420012-bb"></a>any(<span class="bold"><strong>const</strong></span> <a class="link" href="any.html" title="Class any">any</a> & other);</pre> <div class="variablelist"><table border="0"> <col align="left" valign="top"> <tbody> <tr> <td><p><span class="term">Effects:</span></p></td> <td> Copy constructor that copies content of <code class="computeroutput">other</code> into new instance, so that any content is equivalent in both type and value to the content of <code class="computeroutput">other</code>, or empty if <code class="computeroutput">other</code> is empty. </td> </tr> <tr> <td><p><span class="term">Throws:</span></p></td> <td>May fail with a <code class="computeroutput">std::bad_alloc</code> exception or any exceptions arising from the copy constructor of the contained type.</td> </tr> </tbody> </table></div> </li> <li class="listitem"> <pre class="literallayout"><span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> ValueType> <a name="id420054-bb"></a>any(<span class="bold"><strong>const</strong></span> ValueType & value);</pre> <div class="variablelist"><table border="0"> <col align="left" valign="top"> <tbody> <tr> <td><p><span class="term">Effects:</span></p></td> <td>Makes a copy of <code class="computeroutput">value</code>, so that the initial content of the new instance is equivalent in both type and value to <code class="computeroutput">value</code>.</td> </tr> <tr> <td><p><span class="term">Throws:</span></p></td> <td> <code class="computeroutput">std::bad_alloc</code> or any exceptions arising from the copy constructor of the contained type.</td> </tr> </tbody> </table></div> </li> <li class="listitem"> <pre class="literallayout"><span class="type"><a class="link" href="any.html" title="Class any">any</a> &</span> <a name="id420108-bb"></a><span class="bold"><strong>operator</strong></span>=(<span class="bold"><strong>const</strong></span> <a class="link" href="any.html" title="Class any">any</a> & rhs);</pre> <div class="variablelist"><table border="0"> <col align="left" valign="top"> <tbody> <tr> <td><p><span class="term">Effects:</span></p></td> <td>Copies content of <code class="computeroutput">rhs</code> into current instance, discarding previous content, so that the new content is equivalent in both type and value to the content of <code class="computeroutput">rhs</code>, or empty if <code class="computeroutput">rhs.<a class="link" href="any.html#id420257-bb">empty</a>()</code>.</td> </tr> <tr> <td><p><span class="term">Throws:</span></p></td> <td> <code class="computeroutput">std::bad_alloc</code> or any exceptions arising from the copy constructor of the contained type. Assignment satisfies the strong guarantee of exception safety.</td> </tr> </tbody> </table></div> </li> <li class="listitem"> <pre class="literallayout"><span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> ValueType> <span class="type"><a class="link" href="any.html" title="Class any">any</a> &</span> <a name="id420158-bb"></a><span class="bold"><strong>operator</strong></span>=(<span class="bold"><strong>const</strong></span> ValueType & rhs);</pre> <div class="variablelist"><table border="0"> <col align="left" valign="top"> <tbody> <tr> <td><p><span class="term">Effects:</span></p></td> <td>Makes a copy of <code class="computeroutput">rhs</code>, discarding previous content, so that the new content of is equivalent in both type and value to <code class="computeroutput">rhs</code>.</td> </tr> <tr> <td><p><span class="term">Throws:</span></p></td> <td> <code class="computeroutput">std::bad_alloc</code> or any exceptions arising from the copy constructor of the contained type. Assignment satisfies the strong guarantee of exception safety.</td> </tr> </tbody> </table></div> </li> <li class="listitem"> <pre class="literallayout"><a name="id420095-bb"></a>~any();</pre> <div class="variablelist"><table border="0"> <col align="left" valign="top"> <tbody> <tr> <td><p><span class="term">Effects:</span></p></td> <td>Releases any and all resources used in management of instance.</td> </tr> <tr> <td><p><span class="term">Throws:</span></p></td> <td>Nothing.</td> </tr> </tbody> </table></div> </li> </ol></div> </div> <div class="refsect2" title="any modifiers"> <a name="id724429"></a><h3> <a name="id420206-bb"></a><code class="computeroutput">any</code> modifiers</h3> <div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem"> <pre class="literallayout"><span class="type"><a class="link" href="any.html" title="Class any">any</a> &</span> <a name="id420210-bb"></a>swap(<a class="link" href="any.html" title="Class any">any</a> & rhs);</pre> <div class="variablelist"><table border="0"> <col align="left" valign="top"> <tbody> <tr> <td><p><span class="term">Effects:</span></p></td> <td>Exchange of the contents of <code class="computeroutput">*this</code> and <code class="computeroutput">rhs</code>.</td> </tr> <tr> <td><p><span class="term">Returns:</span></p></td> <td><code class="computeroutput">*this</code></td> </tr> <tr> <td><p><span class="term">Throws:</span></p></td> <td>Nothing.</td> </tr> </tbody> </table></div> </li></ol></div> </div> <div class="refsect2" title="any queries"> <a name="id724516"></a><h3> <a name="id420253-bb"></a><code class="computeroutput">any</code> queries</h3> <div class="orderedlist"><ol class="orderedlist" type="1"> <li class="listitem"> <pre class="literallayout"><span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id420257-bb"></a>empty() <span class="bold"><strong>const</strong></span>;</pre> <div class="variablelist"><table border="0"> <col align="left" valign="top"> <tbody> <tr> <td><p><span class="term">Returns:</span></p></td> <td> <code class="computeroutput">true</code> if instance is empty, otherwise <code class="computeroutput">false</code>.</td> </tr> <tr> <td><p><span class="term">Throws:</span></p></td> <td>Will not throw.</td> </tr> </tbody> </table></div> </li> <li class="listitem"> <pre class="literallayout"><span class="type"><span class="bold"><strong>const</strong></span> std::type_info &</span> <a name="id420281-bb"></a>type() <span class="bold"><strong>const</strong></span>;</pre> <div class="variablelist"><table border="0"> <col align="left" valign="top"> <tbody> <tr> <td><p><span class="term">Returns:</span></p></td> <td>the <code class="computeroutput">typeid</code> of the contained value if instance is non-empty, otherwise <code class="computeroutput">typeid(void)</code>.</td> </tr> <tr> <td><p><span class="term">Notes:</span></p></td> <td>Useful for querying against types known either at compile time or only at runtime.</td> </tr> </tbody> </table></div> </li> </ol></div> </div> </div> </div> <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> <td align="left"></td> <td align="right"><div class="copyright-footer">Copyright © 2001 Kevlin Henney<p>Distributed under the Boost Software License, Version 1.0. (See accompanying file <code class="filename">LICENSE_1_0.txt</code> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) </p> </div></td> </tr></table> <hr> <div class="spirit-nav"> <a accesskey="p" href="bad_any_cast.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../any/reference.html#header.boost.any_hpp"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="any_cast.html"><img src="../../../doc/html/images/next.png" alt="Next"></a> </div> </body> </html>