|
1 |
| -.. |any| replace:: :class:`any <core::any>` |
2 |
| - |
3 |
| -.. _core-any-component: |
4 |
| - |
5 | 1 | Any Component
|
6 | 2 | =============
|
7 | 3 |
|
8 |
| -The |any| component is currently available in Boost (and has been for |
9 |
| -quite some time). The |any| component follows the Library Technical |
| 4 | +.. namespace:: core |
| 5 | + |
| 6 | +The :any:`any` component is currently available in Boost (and has been for |
| 7 | +quite some time). The :any:`any` component follows the Library Technical |
10 | 8 | Specification to the letter, and even performs the *small object optimization*.
|
11 |
| -This means that for types whose size are less than (or equal to) a ``void*``, |
12 |
| -no allocation will take place. |
| 9 | +This means that for types whose size are less than (or equal to) a |
| 10 | +:cxx:`void*`, no allocation will take place. |
13 | 11 |
|
14 |
| -The any component resides in ``<core/any.hpp>``. |
| 12 | +The any component resides in :file:`<core/any.hpp>`. |
15 | 13 |
|
16 |
| -.. namespace:: core |
| 14 | +This component is unavailable if :c:macro:`CORE_NO_RTTI` is defined. |
17 | 15 |
|
18 | 16 | .. class:: bad_any_cast
|
19 | 17 |
|
20 | 18 | :inherits: std::bad_cast
|
21 | 19 |
|
22 |
| - This is the exception thrown when :func:`any_cast` fails. |
23 |
| - It inherits from ``std::bad_cast``. |
| 20 | + This is the exception thrown when :any:`any_cast` fails. It inherits from |
| 21 | + :cxx:`std::bad_cast`. |
24 | 22 |
|
25 |
| -.. function:: char const* bad_any_cast::what () const noexcept |
| 23 | + This type is unavailable if :c:macro:`CORE_NO_EXCEPTIONS` is defined. |
26 | 24 |
|
27 |
| - Returns the string "bad any cast". At some point in the future a more |
28 |
| - descriptive error may be given. |
| 25 | + .. function:: char const* what () const noexcept |
| 26 | + |
| 27 | + Returns the string "bad any cast". If :cxx:`typeid(T).name()` was |
| 28 | + standardized, this would be added to the error message |
29 | 29 |
|
30 | 30 | .. class:: any
|
31 | 31 |
|
32 |
| -.. function:: any::any (any const&) |
33 |
| - any::any (any&&) noexcept |
34 |
| - any::any () noexcept |
35 |
| - |
36 |
| - .. versionadded:: 1.2 |
37 |
| - |
38 |
| - The behavior regarding the move constructor has changed to follow |
39 |
| - the specification. It will now construct a value of the same type |
40 |
| - as contained in the incoming |any| and use the move constructor of |
41 |
| - the type. If the incoming |any| is empty, the newly constructed |
42 |
| - |any| will be as well. Before 1.2, the move constructor would simply |
43 |
| - result in a state change. |
44 |
| - |
45 |
| - The default set of constructors work as one might imagine. The copy |
46 |
| - constructor is not marked as noexcept as the underlying type *may* |
47 |
| - throw an exception, and due to the type erasure performed, the |any| has |
48 |
| - no way of enforcing this at compile time. |
49 |
| - |
50 |
| -.. function:: any::any (ValueType&& value) |
51 |
| - |
52 |
| - When constructing an |any| with a given :cxx:`ValueType`, it will perform a |
53 |
| - series of compile time checks to see whether it should perform the small |
54 |
| - object optimization. If the object is deemed small enough, it will not |
55 |
| - allocate memory. Otherwise, a new :cxx:`ValueType` will be allocated via |
56 |
| - :cxx:`operator new`, and constructed with the given *value*. |
57 |
| - |
58 |
| - :raises: Any exceptions thrown by the copy or move constructor |
59 |
| - of the given ValueType. |
60 |
| - |
61 |
| -.. function:: any& any::operator = (any const&) |
62 |
| - any& any::operator = (any&&) noexcept |
63 |
| - |
64 |
| - Assigns the contents of the incoming |any| to ``*this``. |
65 |
| - |
66 |
| -.. function:: any& any::operator = (ValueType&& value) |
67 |
| - |
68 |
| - Assigns *value* to ``*this``. If ``*this`` already manages a contained |
69 |
| - object, it will be destroyed after *value* is assigned. |
70 |
| - |
71 |
| - .. versionadded:: 1.1 |
72 |
| - |
73 |
| - This function was unfortunately omitted from the 1.0 release. |
74 |
| - |
75 |
| -.. function:: void any::swap (any&) noexcept |
76 |
| - |
77 |
| - Swaps the object contained within the given |any| with the one contained |
78 |
| - within ``*this``. |
79 |
| - |
80 |
| -.. function:: std::type_info const& any::type () const noexcept |
81 |
| - |
82 |
| - Returns the :cxx:`std::type_info` for the type contained within. If the |
83 |
| - |any| is empty, it will return :cxx:`typeid(void)`. |
84 |
| - |
85 |
| -.. function:: bool any::empty () const noexcept |
86 |
| - |
87 |
| - If the |any| does not contain any data (i.e. |
88 |
| - :func:`type() <core::any::type>` returns :cxx:`typeid(void)`), it will |
89 |
| - return true. |
90 |
| - |
91 |
| -.. function:: void any::clear () noexcept |
92 |
| - |
93 |
| - :postcondition: :func:`empty() <core::any::empty>` == true |
94 |
| - |
95 |
| - Destroys the object contained within the |any|. |
96 |
| - |
| 32 | + .. function:: any (any const&) |
| 33 | + any (any&&) noexcept |
| 34 | + any () noexcept |
| 35 | + |
| 36 | + .. versionadded:: 1.2 |
| 37 | + |
| 38 | + The behavior regarding the move constructor has changed to follow |
| 39 | + the specification. It will now construct a value of the same type |
| 40 | + as contained in the incoming :any:`any` and use the move constructor |
| 41 | + of the type. If the incoming :any:`any` is empty, the newly |
| 42 | + constructed :any:`any` will be as well. Before 1.2, the move |
| 43 | + constructor would simply result in a state change. |
| 44 | + |
| 45 | + The default set of constructors work as one might imagine. The copy |
| 46 | + constructor is not marked as noexcept as the underlying type *may* |
| 47 | + throw an exception, and due to the type erasure performed, the :any:`any` |
| 48 | + has no way of enforcing this at compile time. |
| 49 | + |
| 50 | + .. function:: any (ValueType&& value) |
| 51 | + |
| 52 | + When constructing an :any:`any` with a given *ValueType*, it will perform |
| 53 | + a series of compile time checks to see whether it should perform the |
| 54 | + small object optimization. If the object is deemed small enough, it will |
| 55 | + not allocate memory. Otherwise, a new *ValueType* will be allocated via |
| 56 | + :cxx:`operator new`, and constructed with the given *value*. |
| 57 | + |
| 58 | + :raises: Any exceptions thrown by the copy or move constructor |
| 59 | + of the given ValueType. |
| 60 | + |
| 61 | + .. function:: any& operator = (any const&) |
| 62 | + any& operator = (any&&) noexcept |
| 63 | + |
| 64 | + Assigns the contents of the incoming :any:`any` to :cxx:`*this`. |
| 65 | + |
| 66 | + .. function:: any& operator = (ValueType&& value) |
| 67 | + |
| 68 | + Assigns *value* to :cxx:`*this`. If :cxx:`*this` already manages a |
| 69 | + contained object, it will be destroyed after *value* is assigned. |
| 70 | + |
| 71 | + .. versionadded:: 1.1 |
| 72 | + |
| 73 | + This function was unfortunately omitted from the 1.0 release. |
| 74 | + |
| 75 | + .. function:: void swap (any&) noexcept |
| 76 | + |
| 77 | + Performs a simple state change with the incoming :any:`any`. |
| 78 | + |
| 79 | + .. note:: Previous versions of the documentation for this function gave |
| 80 | + the impression that an actual swap operation took place. However, |
| 81 | + a *state* change results in calling swap on the internal storage |
| 82 | + type used by :any:`any`. |
| 83 | + |
| 84 | + .. function:: std::type_info const& type () const noexcept |
| 85 | + |
| 86 | + Returns the :cxx:`std::type_info` for the type contained within. If the |
| 87 | + :any:`any` is empty, it will return :cxx:`typeid(void)`. |
| 88 | + |
| 89 | + .. function:: bool empty () const noexcept |
| 90 | + |
| 91 | + If the :any:`any` does not contain any data (i.e. :any:`type` returns |
| 92 | + :cxx:`typeid(void)`), it will return :cxx:`true`. |
| 93 | + |
| 94 | + .. function:: void clear () noexcept |
| 95 | + |
| 96 | + :postcondition: :any:`empty` == true |
| 97 | + |
| 98 | + Destroys the object contained within the :any:`any`. |
97 | 99 |
|
98 | 100 | .. function:: ValueType any_cast (any const& operand)
|
99 | 101 | ValueType any_cast (any&& operand)
|
100 | 102 | ValueType any_cast (any& operand)
|
101 | 103 |
|
102 | 104 | Given a type *ValueType*, it will attempt to extract the value stored within
|
103 |
| - the given |any|. *ValueType* may be either concrete or a reference type. |
104 |
| - If ``typeid(remove_reference_t<ValueType>)`` is not equal to the value |
105 |
| - returned by :func:`type() <core::any::type>`, :class:`bad_any_cast` is |
106 |
| - thrown. |
| 105 | + the given :any:`any`. *ValueType* may be either concrete or a reference |
| 106 | + type. If :cxx:`typeid(remove_reference_t<ValueType>)` is not equal to the |
| 107 | + value returned by :any:`type`, :any:`bad_any_cast` is thrown. |
107 | 108 |
|
108 |
| - :returns: ``*any_cast<add_const_t<remove_reference_t<ValueType>>(&operand)`` |
109 |
| - for the first :func:`any_cast` signature. For the other overloads, |
| 109 | + :returns: :cxx:`*any_cast<add_const_t<remove_reference_t<T>>(&operand)` |
| 110 | + for the first :any:`any_cast` signature. For the other overloads, |
110 | 111 | the return type is
|
111 |
| - ``*any_cast<remove_reference_t<ValueType>>(&operand)``. |
| 112 | + :cxx:`*any_cast<remove_reference_t<T>>(&operand)`. |
112 | 113 |
|
113 |
| - :raises: :class:`bad_any_cast` |
| 114 | + :raises: :any:`bad_any_cast` |
114 | 115 |
|
115 | 116 | :example:
|
116 | 117 | .. code-block:: cpp
|
|
0 commit comments