16 #ifndef LLVM_ADT_ANY_H
17 #define LLVM_ADT_ANY_H
24 #include <type_traits>
34 template <
typename T>
struct TypeId {
static const char Id; };
37 virtual ~StorageBase() =
default;
38 virtual std::unique_ptr<StorageBase> clone()
const = 0;
39 virtual const void *id()
const = 0;
42 template <
typename T>
struct StorageImpl :
public StorageBase {
47 std::unique_ptr<StorageBase> clone()
const override {
48 return std::make_unique<StorageImpl<T>>(
Value);
56 StorageImpl &operator=(
const StorageImpl &
Other) =
delete;
57 StorageImpl(
const StorageImpl &
Other) =
delete;
64 : Storage(
Other.Storage ?
Other.Storage->clone() : nullptr) {}
84 std::is_copy_constructible<std::decay_t<T>>>::value,
88 std::make_unique<StorageImpl<std::decay_t<T>>>(std::forward<T>(
Value));
115 std::unique_ptr<StorageBase> Storage;
124 return Value.Storage->id() == &Any::TypeId<remove_cvref_t<T>>
::Id;
128 return static_cast<T>(*any_cast<remove_cvref_t<T>>(&
Value));
132 return static_cast<T>(*any_cast<remove_cvref_t<T>>(&
Value));
144 return &
static_cast<Any::StorageImpl<U> &
>(*
Value->Storage).
Value;
148 using U = std::decay_t<T>;
152 return &
static_cast<Any::StorageImpl<U> &
>(*
Value->Storage).
Value;
157 #endif // LLVM_ADT_ANY_H