浏览该文件的文档.
28 template <
size_t arg1,
size_t ... others>
36 static const size_t value = arg;
40 template <
size_t arg1,
size_t arg2,
size_t ... others>
41 struct TMax<arg1, arg2, others...>
44 static const size_t value = arg1 >= arg2 ?
45 TMax<arg1, others...>::value :
46 TMax<arg2, others...>::value ;
53 template<uint8_t n,
typename... Ts>
59 template<uint8_t n,
typename F,
typename... Ts>
66 inline static void copy(uint8_t
id,
const void * src_v,
void * dst_v)
70 new (dst_v) F(*
reinterpret_cast<const F*
>(src_v));
82 inline static void move(uint8_t
id,
void * src_v,
void * dst_v)
86 new (dst_v) F(std::move(*
reinterpret_cast<F*
>(src_v)));
97 inline static void destroy(uint8_t
id,
void * data)
101 reinterpret_cast<F*
>(data)->~F();
115 inline static void copy(uint8_t
id,
const void * src_v,
void * dst_v) { }
116 inline static void move(uint8_t
id,
void * src_v,
void * dst_v) { }
117 inline static void destroy(uint8_t
id,
void * data) { }
121 template<
typename ...Ts>
124 inline static void copy(uint8_t
id,
const void *src_v,
void *dst_v)
126 inline static void move(uint8_t
id,
void *src_v,
void *dst_v)
128 inline static void destroy(uint8_t
id,
void *data)
136 inline static void copy(uint8_t
id,
const void * src_v,
void * dst_v) { }
137 inline static void move(uint8_t
id,
void * src_v,
void * dst_v) { }
138 inline static void destroy(uint8_t
id,
void * data) { }
147 template<uint8_t index,
typename... Items>
151 template<
typename F,
typename...Ts>
158 template<uint8_t index,
typename F,
typename... Ts>
175 template<
typename... Ts>
184 using Data =
typename std::aligned_storage<data_size, data_align>::type;
189 template<u
int8_t index>
251 template<u
int8_t index>
273 template<uint8_t
index,
typename... Args>
284 template<u
int8_t index>
287 if (
m_id !=
index)
throw std::bad_cast();
294 template<u
int8_t index>
297 if (
m_id !=
index)
throw std::bad_cast();
Generic declaration of a template type wrapper where VariantType<index,...>::type represents the type...
typename VariantType< index, Ts... >::type Type
Variant()
The default constructor
Implementation of a variant container (similar to C++17's std::variant).
Helper to kickstart the recursive search
Variant< Ts... > & operator=(const Variant< Ts... > &src)
The copy assignment operator
generic declaration of a template to compute the maximum size of a set of template parameters.
typename std::aligned_storage< data_size, data_align >::type Data
the data type for the Variant's internal memory
Variant(const Variant< Ts... > &src)
The copy constructor
void invalidate()
Invalidate the variant. Will destroy any object that is held.
constexpr uint8_t index() const
Returns the index of the type held by this variant, or invalid_id() if the variant does not hold any ...
Type< index > & get()
Return a non-constant reference to the value held by the variant container.
constexpr bool valid() const
Returns true iff the Variant holds a valid type.
const Type< index > & get() const
Returns a constant reference to the value held by the variant container.
typename VariantType< index-1, Ts... >::type type
void set(Args &&... args)
Replaces the contents of the variant container by constructing a type T calling the constructor with ...
generic declaration of a template to handle copying, moving, and deleting type that matches a given i...
static uint8_t invalid_id()
The id that represents an invalid type
static const size_t data_align
constant respresenting the maximum alignment requirement for all types in the template list
constexpr bool is() const
Returns true iff the variant container holds a specific type.
static void copy(uint8_t id, const void *src_v, void *dst_v)
uint8_t m_id
a unique identifier for the type held by this variant
static void move(uint8_t id, void *src_v, void *dst_v)
static void destroy(uint8_t id, void *data)
static const size_t data_size
constant respresenting the maximum size that can hold all types in the template list
Variant(Variant< Ts... > &&src)
The move constructor
Data m_data
the actual data