any.xml 35.2 KB
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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
  "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
<library name="Any" dirname="any" xmlns:xi="http://www.w3.org/2001/XInclude" 
         id="any" last-revision="$Date$">
  <libraryinfo>
    <author>
      <firstname>Kevlin</firstname>
      <surname>Henney</surname>
    </author>

    <copyright>
      <year>2001</year>
      <holder>Kevlin Henney</holder>
    </copyright>

    <copyright>
      <year>2013-2022</year>
      <holder>Antony Polukhin</holder>
    </copyright>

    <librarypurpose>
      Safe, generic container for single values of different value types
    </librarypurpose> 
    <librarycategory name="category:data-structures"/>

    <legalnotice>
      <para>Distributed under the Boost Software License, Version 1.0.
      (See accompanying file <filename>LICENSE_1_0.txt</filename> or copy at 
      <ulink
      url="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</ulink>)
      </para>
    </legalnotice>
  </libraryinfo>

  <title>Boost.Any</title>

  <section>
    <title>Introduction</title>

    <para>There are times when a generic (in the sense of
    <emphasis>general</emphasis> as opposed to
    <emphasis>template-based programming</emphasis>) type is needed:
    variables that are truly variable, accommodating values of many
    other more specific types rather than C++'s normal strict and
    static types. We can distinguish three basic kinds of generic
    type:</para>

    <itemizedlist>
      <listitem>
        <para>Converting types that can hold one of a number of
        possible value types, e.g. <code>int</code> and
        <code>string</code>, and freely convert between them, for
        instance interpreting <code>5</code> as <code>"5"</code> or
        vice-versa.  Such types are common in scripting and other
        interpreted
        languages. 
        <code><functionname>boost::lexical_cast</functionname></code>
        supports such conversion functionality.</para>
      </listitem>
      <listitem>
        <para>
        Discriminated types that contain values of different types but
        do not attempt conversion between them, i.e. <code>5</code> is
        held strictly as an <code>int</code> and is not implicitly
        convertible either to <code>"5"</code> or to
        <code>5.0</code>. Their indifference to interpretation but
        awareness of type effectively makes them safe, generic
        containers of single values, with no scope for surprises from
        ambiguous conversions.</para>
      </listitem>
      <listitem>
        <para>
        Indiscriminate types that can refer to anything but are
        oblivious to the actual underlying type, entrusting all forms
        of access and interpretation to the programmer. This niche is
        dominated by <code>void *</code>, which offers plenty of scope
        for surprising, undefined behavior.</para>
      </listitem>
    </itemizedlist>

    <para>The <code><classname>boost::any</classname></code> class
    (based on the class of the same name described in <ulink
    url="http://www.two-sdg.demon.co.uk/curbralan/papers/ValuedConversions.pdf">"Valued
    Conversions"</ulink> by Kevlin Henney, <emphasis>C++
    Report</emphasis> 12(7), July/August 2000) is a variant value type
    based on the second category. It supports copying of any value
    type and safe checked extraction of that value strictly against
    its type. A similar design, offering more appropriate operators,
    can be used for a generalized function adaptor,
    <code>any_function</code>, a generalized iterator adaptor,
    <code>any_iterator</code>, and other object types that need
    uniform runtime treatment but support only compile-time template
    parameter conformance.</para>
  </section>

  <section>
    <title>Examples</title>

    <using-namespace name="boost"/>
    <using-class name="boost::any"/>

    <para>The following code demonstrates the syntax for using
    implicit conversions to and copying of any objects:</para>

<programlisting name="any.example.first">
#include &lt;list&gt;
#include &lt;boost/any.hpp&gt;

using <functionname>boost::any_cast</functionname>;
typedef std::list&lt;<classname>boost::any</classname>&gt; many;

void append_int(many &amp; values, int value)
{
    <classname>boost::any</classname> to_append = value;
    values.push_back(to_append);
}

void append_string(many &amp; values, const std::string &amp; value)
{
    values.push_back(value);
}

void append_char_ptr(many &amp; values, const char * value)
{
    values.push_back(value);
}

void append_any(many &amp; values, const <classname>boost::any</classname> &amp; value)
{
    values.push_back(value);
}

void append_nothing(many &amp; values)
{
    values.push_back(<classname>boost::any</classname>());
}
</programlisting>

    <para>The following predicates follow on from the previous
    definitions and demonstrate the use of queries on any
    objects:</para>

<programlisting name="any.example.second">
bool is_empty(const <classname>boost::any</classname> &amp; operand)
{
    return operand.<methodname>empty</methodname>();
}

bool is_int(const <classname>boost::any</classname> &amp; operand)
{
    return operand.<methodname>type</methodname>() == typeid(int);
}

bool is_char_ptr(const <classname>boost::any</classname> &amp; operand)
{
    try
    {
        <functionname>any_cast</functionname>&lt;const char *&gt;(operand);
        return true;
    }
    catch(const <classname>boost::bad_any_cast</classname> &amp;)
    {
        return false;
    }
}

bool is_string(const <classname>boost::any</classname> &amp; operand)
{
    return <functionname>any_cast</functionname>&lt;std::string&gt;(&amp;operand);
}

void count_all(many &amp; values, std::ostream &amp; out)
{
    out &lt;&lt; "#empty == "
        &lt;&lt; std::count_if(values.begin(), values.end(), is_empty) &lt;&lt; std::endl;
    out &lt;&lt; "#int == "
        &lt;&lt; std::count_if(values.begin(), values.end(), is_int) &lt;&lt; std::endl;
    out &lt;&lt; "#const char * == "
        &lt;&lt; std::count_if(values.begin(), values.end(), is_char_ptr) &lt;&lt; std::endl;
    out &lt;&lt; "#string == "
        &lt;&lt; std::count_if(values.begin(), values.end(), is_string) &lt;&lt; std::endl;
}
</programlisting>

    <para>The following type, patterned after the OMG's Property Service, defines name-value pairs for arbitrary value types:</para>

<programlisting>
struct property
{
    property();
    property(const std::string &amp;, const <classname>boost::any</classname> &amp;);

    std::string name;
    <classname>boost::any</classname> value;
};

typedef std::list&lt;property&gt; properties;
</programlisting>

    <para>The following base class demonstrates one approach to
    runtime polymorphism based callbacks that also require arbitrary
    argument types. The absence of virtual member templates requires
    that different solutions have different trade-offs in terms of
    efficiency, safety, and generality. Using a checked variant type
    offers one approach:</para>

<programlisting>
class consumer
{
public:
    virtual void notify(const <classname>any</classname> &amp;) = 0;
    ...
};
</programlisting>
  </section>

  <library-reference>
    <section id="any.ValueType">
      <title><emphasis>ValueType</emphasis> requirements</title>

      <para>Values are strongly informational objects for which
      identity is not significant, i.e. the focus is principally on
      their state content and any behavior organized around
      that. Another distinguishing feature of values is their
      granularity: normally fine-grained objects representing simple
      concepts in the system such as quantities.</para>

      <para>As the emphasis of a value lies in its state not its
      identity, values can be copied and typically assigned one to
      another, requiring the explicit or implicit definition of a
      public copy constructor and public assignment operator. Values
      typically live within other scopes, i.e. within objects or
      blocks, rather than on the heap. Values are therefore normally
      passed around and manipulated directly as variables or through
      references, but not as pointers that emphasize identity and
      indirection.</para>

      <para>The specific requirements on value types to be used in an
      <code><classname>boost::any</classname></code> and
      <code><classname>boost::anys::basic_any</classname></code>
      are:</para>

      <itemizedlist spacing="compact">
        <listitem><simpara>A <emphasis>ValueType</emphasis> is
          <emphasis>CopyConstructible</emphasis> [20.1.3].</simpara>
        </listitem>
        
        <listitem><simpara>The destructor for a
        <emphasis>ValueType</emphasis> upholds the no-throw
        exception-safety guarantee.</simpara>
        </listitem>
      </itemizedlist>
    </section>

    <header name="boost/any.hpp">
      <namespace name="boost">
        <class name="any">
          <purpose>A class whose instances can hold instances of any
          type that satisfies <link
          linkend="any.ValueType">ValueType</link>
          requirements.</purpose>

          <constructor>
            <postconditions><simpara><code>this-&gt;<methodname>empty</methodname>()</code></simpara></postconditions>
          </constructor>

          <constructor>
            <parameter name="other">
              <paramtype>const <classname>any</classname> &amp;</paramtype>
            </parameter>

            <effects><simpara> Copy constructor that copies content of
            <code>other</code> into new instance, so that any content
            is equivalent in both type and value to the content of
            <code>other</code>, or empty if <code>other</code> is
            empty. </simpara></effects>

            <throws><simpara>May fail with a
            <code><classname>std::bad_alloc</classname></code>
            exception or any exceptions arising from the copy
            constructor of the contained type.</simpara></throws>
          </constructor>

          <constructor>
            <parameter name="other">
              <paramtype><classname>any</classname> &amp;&amp;</paramtype>
            </parameter>

            <effects><simpara> Move constructor that moves content of
            <code>other</code> into new instance and leaves <code>other</code>
            empty. </simpara></effects>
            <precondition>C++11 compatible compiler.</precondition>
            <postconditions><simpara><code>other-&gt;<methodname>empty</methodname>()</code></simpara></postconditions>
            <throws><simpara>Nothing.</simpara></throws>
          </constructor>

          <constructor>
            <template>
              <template-type-parameter name="ValueType"/>
            </template>

            <parameter name="value">
              <paramtype>const ValueType &amp;</paramtype>
            </parameter>

            <effects><simpara>Makes a copy of <code>value</code>, so
            that the initial content of the new instance is equivalent
            in both type and value to
            <code>value</code>.</simpara></effects>

            <throws><simpara><code><classname>std::bad_alloc</classname></code>
            or any exceptions arising from the copy constructor of the
            contained type.</simpara></throws>
          </constructor>

          <constructor>
            <template>
              <template-type-parameter name="ValueType"/>
            </template>

            <parameter name="value">
              <paramtype>ValueType &amp;&amp;</paramtype>
            </parameter>

            <effects><simpara>Forwards <code>value</code>, so
            that the initial content of the new instance is equivalent
            in both type and value to
            <code>value</code> before the forward.</simpara></effects>

            <precondition>C++11 compatible compiler.</precondition>
            <throws><simpara><code><classname>std::bad_alloc</classname></code>
            or any exceptions arising from the move or copy constructor of the
            contained type.</simpara></throws>
          </constructor>

          <destructor>
            <effects><simpara>Releases any and all resources used in
            management of instance.</simpara></effects>
            <throws><simpara>Nothing.</simpara></throws>
          </destructor>

          <copy-assignment>
            <type><classname>any</classname> &amp;</type>

            <parameter name="rhs">
              <paramtype>const <classname>any</classname> &amp;</paramtype>
            </parameter>

            <effects><simpara>Copies content of <code>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>rhs</code>, or empty if
            <code>rhs.<methodname>empty</methodname>()</code>.</simpara></effects>

            <throws><simpara><code><classname>std::bad_alloc</classname></code>
            or any exceptions arising from the copy constructor of the
            contained type. Assignment satisfies the strong guarantee
            of exception safety.</simpara></throws>
          </copy-assignment>

          <copy-assignment>
            <type><classname>any</classname> &amp;</type>

            <parameter name="rhs">
              <paramtype><classname>any</classname> &amp;&amp;</paramtype>
            </parameter>

            <effects><simpara>Moves content of <code>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>rhs</code> before move, or empty if
            <code>rhs.<methodname>empty</methodname>()</code>.</simpara></effects>

            <precondition>C++11 compatible compiler.</precondition>
            <postconditions><simpara><code>rhs-&gt;<methodname>empty</methodname>()</code></simpara></postconditions>
            <throws><simpara>Nothing.</simpara></throws>
          </copy-assignment>

          <copy-assignment>
             <template>
              <template-type-parameter name="ValueType"/>
            </template>

            <type><classname>any</classname> &amp;</type>

            <parameter name="rhs">
              <paramtype>const ValueType &amp;</paramtype>
            </parameter>

            <effects><simpara>Makes a copy of <code>rhs</code>,
            discarding previous content, so that the new content of is
            equivalent in both type and value to
            <code>rhs</code>.</simpara></effects>

            <throws><simpara><code><classname>std::bad_alloc</classname></code>
            or any exceptions arising from the copy constructor of the
            contained type. Assignment satisfies the strong guarantee
            of exception safety.</simpara></throws>
          </copy-assignment>

          <copy-assignment>
             <template>
              <template-type-parameter name="ValueType"/>
            </template>

            <type><classname>any</classname> &amp;</type>

            <parameter name="rhs">
              <paramtype>ValueType &amp;&amp;</paramtype>
            </parameter>

            <effects><simpara>Forwards <code>rhs</code>,
            discarding previous content, so that the new content of is
            equivalent in both type and value to
            <code>rhs</code> before forward.</simpara></effects>

            <precondition>C++11 compatible compiler.</precondition>
            <throws><simpara><code><classname>std::bad_alloc</classname></code>
            or any exceptions arising from the move or copy constructor of the
            contained type. Assignment satisfies the strong guarantee
            of exception safety.</simpara></throws>
          </copy-assignment>

          <method-group name="modifiers">
            <method name="swap">
              <type><classname>any</classname> &amp;</type>

              <parameter name="rhs">
                <paramtype><classname>any</classname> &amp;</paramtype>
              </parameter>

              <effects><simpara>Exchange of the contents of
              <code>*this</code> and
              <code>rhs</code>.</simpara></effects>

              <returns><simpara><code>*this</code></simpara></returns>

              <throws><simpara>Nothing.</simpara></throws>
            </method>
          </method-group>

          <method-group name="queries">
            <method name="empty" cv="const">
              <type>bool</type>

              <returns><simpara><code>true</code> if instance is
              empty, otherwise <code>false</code>.</simpara></returns>

              <throws><simpara>Nothing.</simpara></throws>
            </method>

            <method name="type" cv="const">
              <type>const <classname>std::type_info</classname> &amp;</type>

              <returns><simpara>the <code>typeid</code> of the
              contained value if instance is non-empty, otherwise
              <code>typeid(void)</code>.</simpara></returns>

              <notes><simpara>Useful for querying against types known
              either at compile time or only at
              runtime.</simpara></notes>
            </method>
          </method-group>
        </class>

        <function name="swap">
          <type>void</type>
          <parameter name="lhs">
            <paramtype><classname>any</classname> &amp;</paramtype>
          </parameter>
          <parameter name="rhs">
              <paramtype><classname>any</classname> &amp;</paramtype>
          </parameter>

            <effects><simpara>Exchange of the contents of
            <code>lhs</code> and
            <code>rhs</code>.</simpara></effects>

            <throws><simpara>Nothing.</simpara></throws>
        </function>

        <overloaded-function name="any_cast">
          <signature>
            <template>
              <template-type-parameter name="T"/>
            </template>

            <type>T</type>

            <parameter name="operand">
              <paramtype><classname>any</classname> &amp;</paramtype>
            </parameter>
          </signature>

          <signature>
            <template>
              <template-type-parameter name="T"/>
            </template>

            <type>T</type>

            <parameter name="operand">
              <paramtype><classname>any</classname> &amp;&amp;</paramtype>
            </parameter>
          </signature>

          <signature>
            <template>
              <template-type-parameter name="T"/>
            </template>

            <type>T</type>

            <parameter name="operand">
              <paramtype>const <classname>any</classname> &amp;</paramtype>
            </parameter>
          </signature>

          <signature>
            <template>
              <template-type-parameter name="ValueType"/>
            </template>

            <type>const ValueType *</type>

            <parameter name="operand">
              <paramtype>const <classname>any</classname> *</paramtype>
            </parameter>
          </signature>

          <signature>
            <template>
              <template-type-parameter name="ValueType"/>
            </template>

            <type>ValueType *</type>

            <parameter name="operand">
              <paramtype><classname>any</classname> *</paramtype>
            </parameter>
          </signature>

          <purpose><simpara>Custom keyword cast for extracting a value
          of a given type from an
          <code><classname>any</classname></code>.</simpara></purpose>

          <returns><simpara> If passed a pointer, it returns a
          similarly qualified pointer to the value content if
	  successful, otherwise null is returned.
	  If T is ValueType, it returns a copy of the held value, otherwise, if T is a reference 
	  to (possibly const qualified) ValueType, it returns a reference to the held 
	  value.</simpara></returns>

          <throws><simpara>Overloads taking an
          <code><classname>any</classname></code> pointer do not
          throw; overloads taking an
          <code><classname>any</classname></code> value or reference
          throws <code><classname>bad_any_cast</classname></code> if
          unsuccessful.</simpara></throws>

        </overloaded-function>
      </namespace>
    </header>

    <header name="boost/any/bad_any_cast.hpp">
      <namespace name="boost">
        <class name="bad_any_cast">
          <inherit access="public">
            <classname>std::bad_cast</classname>
          </inherit>
          <purpose>The exception thrown in the event of a failed
          <code><functionname>any_cast</functionname></code> of an
          <code><classname>any</classname></code> value.</purpose>

          <method name="what" specifiers="virtual" cv="const">
            <type>const char *</type>
          </method>
        </class>
      </namespace>
    </header>

    <header name="boost/any/basic_any.hpp">
      <namespace name="boost"><namespace name="anys">
        <class name="basic_any">
          <purpose>A class with customizable Small Object Optimization whose instances can hold instances of any
          type that satisfies <link
          linkend="any.ValueType">ValueType</link>
          requirements. Use <code><classname>boost::any</classname></code> instead if not sure.</purpose>

          <description>
              <para><code><classname>boost::anys::basic_any</classname></code> is the drop-in replacement for
              <code><classname>boost::any</classname></code> that provides controll over Small Object
              Optimization via <code>OptimizeForSize</code> and <code>OptimizeForAlignment</code> template
              parameters.</para>

              <para>There are certain applications that require <code><classname>boost::any</classname></code>
              functionality, do know the typical/maximal size of the stored object and wish to avoid dynamic memory
              allocation overhead. For the convenience such applications may create a typedef for <code>basic_any</code>
              with the <code>OptimizeForSize</code> and <code>OptimizeForAlignment</code> template parameters set to
              typical/maximal size and alignment of types respectively. Memory allocation would be avoided
              for storing nothrow move constructible types with size and alignment less than or
              equal to the <code>OptimizeForSize</code> and <code>OptimizeForAlignment</code> values.</para>

              <para>Otherwise just use <code><classname>boost::any</classname></code>.</para>
          </description>

          <template>
            <template-nontype-parameter name="OptimizeForSize">
              <type>std::size_t</type>
            </template-nontype-parameter>
            <template-nontype-parameter name="OptimizeForAlignment">
              <type>std::size_t</type>
            </template-nontype-parameter>
          </template>

          <constructor>
            <postconditions><simpara><code>this-&gt;<methodname>empty</methodname>()</code></simpara></postconditions>
          </constructor>

          <constructor>
            <parameter name="other">
              <paramtype>const <classname>basic_any</classname> &amp;</paramtype>
            </parameter>

            <effects><simpara> Copy constructor that copies content of
            <code>other</code> into new instance, so that any content
            is equivalent in both type and value to the content of
            <code>other</code>, or empty if <code>other</code> is
            empty. </simpara></effects>

            <throws><simpara>May fail with a
            <code><classname>std::bad_alloc</classname></code>
            exception or any exceptions arising from the copy
            constructor of the contained type.</simpara></throws>
          </constructor>
          <constructor>
            <parameter name="other">
              <paramtype><classname>basic_any</classname> &amp;&amp;</paramtype>
            </parameter>

            <effects><simpara> Move constructor that moves content of
            <code>other</code> into new instance and leaves <code>other</code>
            empty. </simpara></effects>
            <precondition>C++11 compatible compiler.</precondition>
            <postconditions><simpara><code>other-&gt;<methodname>empty</methodname>()</code></simpara></postconditions>
            <throws><simpara>Nothing.</simpara></throws>
          </constructor>

          <constructor>
            <template>
              <template-type-parameter name="ValueType"/>
            </template>

            <parameter name="value">
              <paramtype>const ValueType &amp;</paramtype>
            </parameter>

            <effects><simpara>Makes a copy of <code>value</code>, so
            that the initial content of the new instance is equivalent
            in both type and value to
            <code>value</code>.</simpara>

            <simpara>Does not dynamically allocate if <code>ValueType</code> is nothrow
            move constructible and <code>sizeof(value) &lt;= OptimizeForSize
            &amp;&amp; alignof(value) &lt;=OptimizeForAlignment</code>.</simpara>
            </effects>

            <throws><simpara><code><classname>std::bad_alloc</classname></code>
            or any exceptions arising from the copy constructor of the
            contained type.</simpara></throws>
          </constructor>

          <constructor>
            <template>
              <template-type-parameter name="ValueType"/>
            </template>

            <parameter name="value">
              <paramtype>ValueType &amp;&amp;</paramtype>
            </parameter>

            <effects><simpara>Forwards <code>value</code>, so
            that the initial content of the new instance is equivalent
            in both type and value to
            <code>value</code> before the forward.</simpara>

            <simpara>Does not dynamically allocate if <code>ValueType</code> is nothrow
            move constructible and <code>sizeof(value) &lt;= OptimizeForSize
            &amp;&amp; alignof(value) &lt;=OptimizeForAlignment</code>.</simpara>
            </effects>

            <precondition>C++11 compatible compiler.</precondition>
            <throws><simpara><code><classname>std::bad_alloc</classname></code>
            or any exceptions arising from the move or copy constructor of the
            contained type.</simpara></throws>
          </constructor>

          <destructor>
            <effects><simpara>Releases any and all resources used in
            management of instance.</simpara></effects>
            <throws><simpara>Nothing.</simpara></throws>
          </destructor>

          <copy-assignment>
            <type><classname>basic_any</classname> &amp;</type>

            <parameter name="rhs">
              <paramtype>const <classname>basic_any</classname> &amp;</paramtype>
            </parameter>

            <effects><simpara>Copies content of <code>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>rhs</code>, or empty if
            <code>rhs.<methodname>empty</methodname>()</code>.</simpara></effects>

            <throws><simpara><code><classname>std::bad_alloc</classname></code>
            or any exceptions arising from the copy constructor of the
            contained type. Assignment satisfies the strong guarantee
            of exception safety.</simpara></throws>
          </copy-assignment>

          <copy-assignment>
            <type><classname>basic_any</classname> &amp;</type>

            <parameter name="rhs">
              <paramtype><classname>basic_any</classname> &amp;&amp;</paramtype>
            </parameter>

            <effects><simpara>Moves content of <code>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>rhs</code> before move, or empty if
            <code>rhs.<methodname>empty</methodname>()</code>.</simpara></effects>

            <precondition>C++11 compatible compiler.</precondition>
            <postconditions><simpara><code>rhs-&gt;<methodname>empty</methodname>()</code></simpara></postconditions>
            <throws><simpara>Nothing.</simpara></throws>
          </copy-assignment>

          <copy-assignment>
             <template>
              <template-type-parameter name="ValueType"/>
            </template>

            <type><classname>basic_any</classname> &amp;</type>

            <parameter name="rhs">
              <paramtype>const ValueType &amp;</paramtype>
            </parameter>

            <effects><simpara>Makes a copy of <code>rhs</code>,
            discarding previous content, so that the new content of is
            equivalent in both type and value to
            <code>rhs</code>.</simpara>

            <simpara>Does not dynamically allocate if <code>ValueType</code> is nothrow
            move constructible and <code>sizeof(value) &lt;= OptimizeForSize
            &amp;&amp; alignof(value) &lt;=OptimizeForAlignment</code>.</simpara>
            </effects>

            <throws><simpara><code><classname>std::bad_alloc</classname></code>
            or any exceptions arising from the copy constructor of the
            contained type. Assignment satisfies the strong guarantee
            of exception safety.</simpara></throws>
          </copy-assignment>

          <copy-assignment>
             <template>
              <template-type-parameter name="ValueType"/>
            </template>

            <type><classname>basic_any</classname> &amp;</type>

            <parameter name="rhs">
              <paramtype>ValueType &amp;&amp;</paramtype>
            </parameter>

            <effects><simpara>Forwards <code>rhs</code>,
            discarding previous content, so that the new content of is
            equivalent in both type and value to
            <code>rhs</code> before forward.</simpara>

            <simpara>Does not dynamically allocate if <code>ValueType</code> is nothrow
            move constructible and <code>sizeof(value) &lt;= OptimizeForSize
            &amp;&amp; alignof(value) &lt;=OptimizeForAlignment</code>.</simpara>
            </effects>

            <precondition>C++11 compatible compiler.</precondition>
            <throws><simpara><code><classname>std::bad_alloc</classname></code>
            or any exceptions arising from the move or copy constructor of the
            contained type. Assignment satisfies the strong guarantee
            of exception safety.</simpara></throws>
          </copy-assignment>

          <method-group name="modifiers">
            <method name="swap">
              <type><classname>basic_any</classname> &amp;</type>

              <parameter name="rhs">
                <paramtype><classname>basic_any</classname> &amp;</paramtype>
              </parameter>

              <effects><simpara>Exchange of the contents of
              <code>*this</code> and
              <code>rhs</code>.</simpara></effects>

              <returns><simpara><code>*this</code></simpara></returns>

              <throws><simpara>Nothing.</simpara></throws>
            </method>
          </method-group>

          <method-group name="queries">
            <method name="empty" cv="const">
              <type>bool</type>

              <returns><simpara><code>true</code> if instance is
              empty, otherwise <code>false</code>.</simpara></returns>

              <throws><simpara>Nothing.</simpara></throws>
            </method>

            <method name="type" cv="const">
              <type>const <classname>std::type_info</classname> &amp;</type>

              <returns><simpara>the <code>typeid</code> of the
              contained value if instance is non-empty, otherwise
              <code>typeid(void)</code>.</simpara></returns>

              <notes><simpara>Useful for querying against types known
              either at compile time or only at
              runtime.</simpara></notes>
            </method>
          </method-group>
        </class>

        <function name="swap">
          <type>void</type>
          <parameter name="lhs">
            <paramtype><classname>basic_any</classname> &amp;</paramtype>
          </parameter>
          <parameter name="rhs">
              <paramtype><classname>basic_any</classname> &amp;</paramtype>
          </parameter>

            <effects><simpara>Exchange of the contents of
            <code>lhs</code> and
            <code>rhs</code>.</simpara></effects>

            <throws><simpara>Nothing.</simpara></throws>
        </function>

        <overloaded-function name="any_cast">
          <signature>
            <template>
              <template-type-parameter name="T"/>
            </template>

            <type>T</type>

            <parameter name="operand">
              <paramtype><classname>basic_any</classname> &amp;</paramtype>
            </parameter>
          </signature>

          <signature>
            <template>
              <template-type-parameter name="T"/>
            </template>

            <type>T</type>

            <parameter name="operand">
              <paramtype><classname>basic_any</classname> &amp;&amp;</paramtype>
            </parameter>
          </signature>

          <signature>
            <template>
              <template-type-parameter name="T"/>
            </template>

            <type>T</type>

            <parameter name="operand">
              <paramtype>const <classname>basic_any</classname> &amp;</paramtype>
            </parameter>
          </signature>

          <signature>
            <template>
              <template-type-parameter name="ValueType"/>
            </template>

            <type>const ValueType *</type>

            <parameter name="operand">
              <paramtype>const <classname>basic_any</classname> *</paramtype>
            </parameter>
          </signature>

          <signature>
            <template>
              <template-type-parameter name="ValueType"/>
            </template>

            <type>ValueType *</type>

            <parameter name="operand">
              <paramtype><classname>basic_any</classname> *</paramtype>
            </parameter>
          </signature>

          <purpose><simpara>Custom keyword cast for extracting a value
          of a given type from an
          <code><classname>basic_any</classname></code>. Also available from <code>boost</code> namespace.</simpara></purpose>

          <returns><simpara> If passed a pointer, it returns a
          similarly qualified pointer to the value content if
	  successful, otherwise null is returned.
	  If T is ValueType, it returns a copy of the held value, otherwise, if T is a reference
	  to (possibly const qualified) ValueType, it returns a reference to the held
	  value.</simpara></returns>

          <throws><simpara>Overloads taking an
          <code><classname>basic_any</classname></code> pointer do not
          throw; overloads taking an
          <code><classname>basic_any</classname></code> value or reference
          throw <code><classname>bad_any_cast</classname></code> if
          unsuccessful.</simpara></throws>

        </overloaded-function>
      </namespace></namespace>
    </header>
  </library-reference>

  <section>
    <title>Acknowledgements</title>

    <para>Doug Gregor ported the documentation to the BoostBook format.</para>
  </section>
</library>