13 template <
typename... All>
struct Impl;
15 template <
typename Head,
typename... Rest>
16 struct Impl<Head, Rest...> {
17 static void destroy(
const std::type_index&
id,
void* data) {
18 if (
id ==
typeid(Head))
reinterpret_cast<Head*
>(data)->~Head();
22 static void move(
const std::type_index&
id,
void* newData,
23 const void* oldData) {
24 if (
id ==
typeid(Head))
25 new(newData) Head(std::move(*
reinterpret_cast<const Head*
>(oldData)));
30 static void copy(
const std::type_index&
id,
void* newData,
31 const void* oldData) {
32 if (
id ==
typeid(Head))
33 new(newData) Head(*
reinterpret_cast<const Head*
>(oldData));
41 static void destroy(
const std::type_index&
id,
const void* data) {}
42 static void move(
const std::type_index&
id,
void* newData,
43 const void* oldData) {}
44 static void copy(
const std::type_index&
id,
void* newData,
45 const void* oldData) {}
53 template <
typename... Types>
57 typename std::aligned_union<1, Types...>::type data;
59 std::type_index invalidType()
const {
return typeid(void); }
62 Any(): type(invalidType()) {}
77 old.type = invalidType();
82 std::swap(type, old.type);
83 std::swap(data, old.data);
88 bool is()
const {
return type ==
typeid(T); }
90 bool valid()
const {
return type != invalidType(); }
94 ASSERT(type ==
typeid(T),
"Any::get requested-type=%s! storage-type=%s",
95 typeid(T).name(), type.name());
96 return *
reinterpret_cast<T*
>(&data);