18 virtual ~VirtualBase()
noexcept {}
19 virtual std::type_info
const &virtual_type()
const noexcept = 0;
20 virtual std::unique_ptr<VirtualBase> virtual_clone()
const noexcept = 0;
23 static std::unique_ptr<VirtualBase> upcast(T
const &value)
noexcept {
24 return std::unique_ptr<VirtualBase>(
new ConcreteType<T>(value));
29 std::unique_ptr<VirtualBase> erased_value;
32 template <
typename T>
struct ConcreteType : VirtualBase {
35 explicit ConcreteType(T
const &val) noexcept : value(val) {}
37 std::type_info
const &virtual_type()
const noexcept override {
41 std::unique_ptr<VirtualBase> virtual_clone()
const noexcept override {
42 return any::VirtualBase::upcast(value);
46 template <
typename T>
friend T any_cast(
ditto::any const &operand);
52 any(T
const &value) noexcept
53 : erased_value(any::VirtualBase::upcast(value)) {}
55 any(
any const &other)
noexcept;
57 void swap(
any &other)
noexcept;
59 any &operator=(
any const &other)
noexcept;
61 std::type_info
const &type()
const noexcept;
63 bool has_value()
const noexcept;
65 template <
typename T> T as()
const {
67 dynamic_cast<any::ConcreteType<T>
const *
>(erased_value.get())) {
70 throw std::bad_cast();