A value wrapper capable of storing values of any type, similar to std::any.
class KwargsValue;| Name | Description |
|---|---|
KwargsValue() |
Default constructor. |
KwargsValue(const KwargsValue&) |
Copy constructor. |
KwargsValue(KwargsValue&&) |
Move constructor. |
KwargsValue(const _Tp&) |
Stores a value or a pointer to a value of type _Tp. |
KwargsValue(_Tp&&) |
Stores a value of type _Tp with move semantics. |
KwargsValue(const char (&)[_Size]) |
Partial specialization for string literals, stores the pointer to the first character. |
| Name | Description |
|---|---|
~KwargsValue |
Destructor. |
| Name | Description |
|---|---|
typeName |
Returns the string name of the last _Tp used in construction. Compiler-dependent. |
typeHashCode |
Returns the hash code of the last _Tp using std::type_info::hash_code(). |
valueTypeHashCode |
Returns the hash code of _Tp::value_type if available; otherwise same as typeHashCode(). |
hasValueType |
Checks whether _Tp::value_type exists. |
isSameType |
Checks whether the stored type _Tp matches a given type. |
isInteger |
Checks if _Tp is an integer or enum type. |
isRealNumber |
Checks if _Tp is a floating-point type. |
isEnum |
Checks if _Tp is an enumeration. |
isStdArray |
Checks if _Tp is std::array. |
isIterable |
Checks if _Tp is an iterable container. |
pointer |
Returns a pointer to the internal value. Ensure the type layout matches before dereferencing. |
reference |
Dereferences pointer(). |
value |
Retrieves the stored value with optional implicit conversion. |
size |
Returns sizeof(_Tp) at construction time. |
| Name | Description |
|---|---|
operator= |
Assignment operator. |
Initializes with a default int value of 0.
constexpr KwargsValue() = default;Constructs from any value. If the type is a struct, union, or larger than 8 bytes, a pointer to the object is stored (lifetime considerations apply). Otherwise, the value is stored via byte-level copy.
template<typename _Tp>
constexpr KwargsValue(const _Tp& __value) noexcept;For rvalue references, constructs by dynamically allocating the object and moving it.
template<typename _Tp>
constexpr KwargsValue(_Tp&& __value);Partial specialization for string literals; stores a pointer to the first character.
template<std::size_t _Size>
constexpr KwargsValue(const char (&__value)[_Size]) noexcept;If the value was dynamically allocated during construction, it is destroyed and freed.
_KWARGS_DESTRUCTOR_CONSTEXPR ~KwargsValue() noexcept;Tip
_KWARGS_DESTRUCTOR_CONSTEXPR is defined as constexpr in C++20 and inline in C++17.
Returns the string representation of _Tp. The result may vary by compiler.
constexpr std::string_view typeName() const noexcept;Returns the hash code of _Tp.
constexpr std::size_t typeHashCode() const noexcept;Returns the hash code of _Tp::value_type, or falls back to typeHashCode() if unavailable.
constexpr std::size_t valueTypeHashCode() const noexcept;Checks for the existence of _Tp::value_type.
constexpr bool hasValueType() const noexcept;Checks whether the stored type _Tp matches the provided type.
template<typename _Tp>
constexpr bool isSameType() const noexcept;Tip
For enums, it compares the underlying type instead.
Checks if _Tp is an integer or enum.
constexpr bool isInteger() const noexcept;Checks if _Tp is a floating-point type.
constexpr bool isRealNumber() const noexcept;Checks if _Tp is an enum.
constexpr bool isEnum() const noexcept;Checks if _Tp is a std::array.
constexpr bool isStdArray() const noexcept;Checks if _Tp is an iterable container type.
constexpr bool isIterable() const noexcept;Tip
Iterable containers are those with .begin() and .end() member functions.
Returns a pointer to the stored value. Ensure type layout compatibility before dereferencing.
template<typename _Tp>
constexpr _Tp* pointer() noexcept;
template<typename _Tp>
constexpr const _Tp* pointer() const noexcept;Dereferences the pointer returned by pointer().
template<typename _Tp>
constexpr _Tp& reference() noexcept
{ return *pointer<_Tp>(); }
template<typename _Tp>
constexpr const _Tp& reference() const noexcept
{ return *pointer<_Tp>(); }Returns the stored value of type _Tp, with optional conversion if types differ.
template<typename _Tp>
constexpr std::enable_if_t<..., _Tp> value() const noexcept;Note
Due to type erasure, direct copying is not supported.
Warning
If conversion fails, assert() is triggered. If NODEBUG is defined, it returns a default-constructed _Tp.
In constexpr functions, which may execute at compile-time, throw is not permitted since it's a runtime operation.
Returns the size of the stored type _Tp. If _Tp is a string literal, returns the number of characters.
constexpr std::uint32_t size() const noexcept;Performs copy or move assignment and updates the stored type to that of the __other's _Tp.
constexpr KwargsValue& operator=(const KwargsValue& __other);
constexpr KwargsValue& operator=(KwargsValue&& __other) noexcept;