Doxygen
|
Implementation of a variant container (similar to C++17's std::variant). 更多...
#include <variant.h>
Public 成员函数 | |
Variant () | |
The default constructor 更多... | |
Variant (const Variant< Ts... > &src) | |
The copy constructor 更多... | |
Variant (Variant< Ts... > &&src) | |
The move constructor 更多... | |
Variant< Ts... > & | operator= (const Variant< Ts... > &src) |
The copy assignment operator 更多... | |
Variant< Ts... > & | operator= (Variant< Ts... > &&src) |
The move assignment operator 更多... | |
~Variant () | |
The destructor 更多... | |
template<uint8_t index> | |
constexpr bool | is () const |
Returns true iff the variant container holds a specific type. 更多... | |
constexpr bool | valid () const |
Returns true iff the Variant holds a valid type. 更多... | |
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 (i.e. 更多... | |
template<uint8_t index, typename... Args> | |
void | set (Args &&... args) |
Replaces the contents of the variant container by constructing a type T calling the constructor with Args 更多... | |
template<uint8_t index> | |
Type< index > & | get () |
Return a non-constant reference to the value held by the variant container. 更多... | |
template<uint8_t index> | |
const Type< index > & | get () const |
Returns a constant reference to the value held by the variant container. 更多... | |
Private 类型 | |
using | Data = typename std::aligned_storage< data_size, data_align >::type |
the data type for the Variant's internal memory 更多... | |
using | HelperT = details::HelperT< Ts... > |
a short hand name for the helper class 更多... | |
template<uint8_t index> | |
using | Type = typename VariantType< index, Ts... >::type |
静态 Private 成员函数 | |
static uint8_t | invalid_id () |
The id that represents an invalid type 更多... | |
Private 属性 | |
Data | m_data |
the actual data 更多... | |
uint8_t | m_id |
a unique identifier for the type held by this variant 更多... | |
静态 Private 属性 | |
static const size_t | data_size = details::TMax<sizeof(Ts)...>::value |
constant respresenting the maximum size that can hold all types in the template list 更多... | |
static const size_t | data_align = details::TMax<alignof(Ts)...>::value |
constant respresenting the maximum alignment requirement for all types in the template list 更多... | |
Implementation of a variant container (similar to C++17's std::variant).
It can hold either no instances (e.g. initially or after calling invalidate()), or hold exactly one instance of an object (after calling set()) whose type is one of the variant's template parameters. Each parameter has an index, the first parameter has index 0. It behaves similar to a C union, in that the memory of all possible object types is shared, but unlike a C union it does allow C++ objects with constructors and destructors to be stored and knows what type is stored.
|
private |
|
private |
|
private |
Return a non-constant reference to the value held by the variant container.
std::bad_cast() | if called on a variant container that does not hold an instance of the type of the variant at index. |
被这些函数引用 TemplateVariant::call(), TemplateVariant::operator==(), TemplateVariant::toBool(), TemplateVariant::toInt(), TemplateVariant::toList(), TemplateVariant::toString() , 以及 TemplateVariant::toStruct().
|
inline |
Returns a constant reference to the value held by the variant container.
std::bad_cast() | if called on a variant container that does not hold an instance of the type of the variant at index. |
|
inlineconstexpr |
Returns the index of the type held by this variant, or invalid_id() if the variant does not hold any type (i.e.
valid() returns false).
被这些函数引用 Variant< bool, int, QCString, TemplateStructIntfPtr, TemplateListIntfPtr, FunctionDelegate, TemplateStructIntfWeakPtr >::get(), Variant< bool, int, QCString, TemplateStructIntfPtr, TemplateListIntfPtr, FunctionDelegate, TemplateStructIntfWeakPtr >::is(), Variant< bool, int, QCString, TemplateStructIntfPtr, TemplateListIntfPtr, FunctionDelegate, TemplateStructIntfWeakPtr >::set() , 以及 TemplateVariant::type().
|
inlinestaticprivate |
The id that represents an invalid type
被这些函数引用 Variant< bool, int, QCString, TemplateStructIntfPtr, TemplateListIntfPtr, FunctionDelegate, TemplateStructIntfWeakPtr >::invalidate() , 以及 Variant< bool, int, QCString, TemplateStructIntfPtr, TemplateListIntfPtr, FunctionDelegate, TemplateStructIntfWeakPtr >::valid().
|
inline |
Invalidate the variant. Will destroy any object that is held.
|
inlineconstexpr |
Returns true iff the variant container holds a specific type.
T | the type to search for. |
被这些函数引用 TemplateVariant::isBool(), TemplateVariant::isFunction(), TemplateVariant::isInt(), TemplateVariant::isList(), TemplateVariant::isString(), TemplateVariant::isStruct() , 以及 TemplateVariant::isWeakStruct().
|
inline |
The copy assignment operator
|
inline |
Replaces the contents of the variant container by constructing a type T calling the constructor with Args
index | the type to make the variant hold an instance of. |
Args | The arguments types to pass to the constructor of T. |
args | The argument values |
被这些函数引用 TemplateVariant::TemplateVariant().
|
inlineconstexpr |
Returns true iff the Variant holds a valid type.
被这些函数引用 TemplateVariant::isValid(), Variant< bool, int, QCString, TemplateStructIntfPtr, TemplateListIntfPtr, FunctionDelegate, TemplateStructIntfWeakPtr >::operator=() , 以及 TemplateVariant::operator==().
|
staticprivate |
|
staticprivate |
the actual data
被这些函数引用 Variant< bool, int, QCString, TemplateStructIntfPtr, TemplateListIntfPtr, FunctionDelegate, TemplateStructIntfWeakPtr >::get(), Variant< bool, int, QCString, TemplateStructIntfPtr, TemplateListIntfPtr, FunctionDelegate, TemplateStructIntfWeakPtr >::invalidate(), Variant< bool, int, QCString, TemplateStructIntfPtr, TemplateListIntfPtr, FunctionDelegate, TemplateStructIntfWeakPtr >::operator=(), Variant< bool, int, QCString, TemplateStructIntfPtr, TemplateListIntfPtr, FunctionDelegate, TemplateStructIntfWeakPtr >::set(), Variant< bool, int, QCString, TemplateStructIntfPtr, TemplateListIntfPtr, FunctionDelegate, TemplateStructIntfWeakPtr >::Variant() , 以及 Variant< bool, int, QCString, TemplateStructIntfPtr, TemplateListIntfPtr, FunctionDelegate, TemplateStructIntfWeakPtr >::~Variant().
|
private |
a unique identifier for the type held by this variant
被这些函数引用 Variant< bool, int, QCString, TemplateStructIntfPtr, TemplateListIntfPtr, FunctionDelegate, TemplateStructIntfWeakPtr >::get(), Variant< bool, int, QCString, TemplateStructIntfPtr, TemplateListIntfPtr, FunctionDelegate, TemplateStructIntfWeakPtr >::index(), Variant< bool, int, QCString, TemplateStructIntfPtr, TemplateListIntfPtr, FunctionDelegate, TemplateStructIntfWeakPtr >::invalidate(), Variant< bool, int, QCString, TemplateStructIntfPtr, TemplateListIntfPtr, FunctionDelegate, TemplateStructIntfWeakPtr >::is(), Variant< bool, int, QCString, TemplateStructIntfPtr, TemplateListIntfPtr, FunctionDelegate, TemplateStructIntfWeakPtr >::operator=(), Variant< bool, int, QCString, TemplateStructIntfPtr, TemplateListIntfPtr, FunctionDelegate, TemplateStructIntfWeakPtr >::set(), Variant< bool, int, QCString, TemplateStructIntfPtr, TemplateListIntfPtr, FunctionDelegate, TemplateStructIntfWeakPtr >::valid(), Variant< bool, int, QCString, TemplateStructIntfPtr, TemplateListIntfPtr, FunctionDelegate, TemplateStructIntfWeakPtr >::Variant() , 以及 Variant< bool, int, QCString, TemplateStructIntfPtr, TemplateListIntfPtr, FunctionDelegate, TemplateStructIntfWeakPtr >::~Variant().