| 65 | }; |
| 66 | |
| 67 | class any final |
| 68 | { |
| 69 | public: |
| 70 | /// Constructs an object of type any with an empty state. |
| 71 | any() noexcept : |
| 72 | vtable(nullptr) |
| 73 | { |
| 74 | } |
| 75 | |
| 76 | /// Constructs an object of type any with an equivalent state as other. |
| 77 | any(const any& rhs) : |
| 78 | vtable(rhs.vtable) |
| 79 | { |
| 80 | if(!rhs.empty()) |
| 81 | { |
| 82 | rhs.vtable->copy(rhs.storage, this->storage); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | /// Constructs an object of type any with a state equivalent to the original state of other. |
| 87 | /// rhs is left in a valid but otherwise unspecified state. |
| 88 | any(any&& rhs) noexcept : |
| 89 | vtable(rhs.vtable) |
| 90 | { |
| 91 | if(!rhs.empty()) |
| 92 | { |
| 93 | rhs.vtable->move(rhs.storage, this->storage); |
| 94 | rhs.vtable = nullptr; |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | /// Same effect as this->clear(). |
| 99 | ~any() |
| 100 | { |
| 101 | this->clear(); |
| 102 | } |
| 103 | |
| 104 | /// Constructs an object of type any that contains an object of type T direct-initialized with std::forward<ValueType>(value). |
| 105 | /// |
| 106 | /// T shall satisfy the CopyConstructible requirements, otherwise the program is ill-formed. |
| 107 | /// This is because an `any` may be copy constructed into another `any` at any time, so a copy should always be allowed. |
| 108 | template<typename ValueType, typename = typename std::enable_if<!std::is_same<typename std::decay<ValueType>::type, any>::value>::type> |
| 109 | any(ValueType&& value) |
| 110 | { |
| 111 | static_assert(std::is_copy_constructible<typename std::decay<ValueType>::type>::value, |
| 112 | "T shall satisfy the CopyConstructible requirements."); |
| 113 | this->construct(std::forward<ValueType>(value)); |
| 114 | } |
| 115 | |
| 116 | template <typename ValueType, typename... Args> |
| 117 | explicit any(in_place_type_t<ValueType>, Args&&... args) |
| 118 | { |
| 119 | this->emplace_construct<ValueType>(std::forward<Args>(args)...); |
| 120 | } |
| 121 | |
| 122 | template <typename ValueType, typename U, typename... Args> |
| 123 | explicit any(in_place_type_t<ValueType>, std::initializer_list<U> il, Args&&... args) |
| 124 | { |