carb::variant::traits

Defined in carb/variant/VariantUtils.h

struct traits

A structure containing functions for performing the prescribed actions on a VariantData. The functions handle the default behavior if the v-table or v-table function are nullptr.

Public Static Functions

static void swap(VariantData &lhs, VariantData &rhs) noexcept

Swaps two VariantData members.

Note

VariantData is treated as a trivial type and no v-table functions are required to perform this.

Parameters
  • lhs – The left-hand VariantData.

  • rhs – The right-hand VariantData.

static void destruct(VariantData &self) noexcept

Destructs a VariantData.

Note

The default behavior (if !self.vtable->Destructor) treats self as trivially destructible.

Parameters

self – The VariantData to destruct.

static VariantData copy(const VariantData &self) noexcept

Copies a VariantData.

Note

The default behavior (if !self.vtable->Copy) treats self as trivially copyable.

Parameters

self – The VariantData to copy.

Returns

A VariantData that represents a copy of self. The v-table of the return value must be the same as self.vtable. When finished with the return value, it must be destroyed via destruct().

static bool equals(const VariantData &self, const VariantData &other) noexcept

Tests two VariantData instances for equality.

Note

The default behavior (if !self.vtable->Equals) treats self and other as trivially comparable (i.e. bitwise compare via std::memcmp).

Parameters
  • self – The VariantData to compare. This parameter provides the v-table for the comparison.

  • other – The other VariantData to compare.

Returns

true if self and other are equal; false otherwise.

static omni::string toString(const VariantData &self) noexcept

Renders a VariantData as a string for debugging purposes.

Note

The default behavior (if !self.vtable->ToString) produces "<vtable>:<data>".

Parameters

self – The VariantData to render as a string.

Returns

A string representing self for debugging purposes.

static bool convertTo(const VariantData &self, const VTable *newType, VariantData &out) noexcept

Attempts to convert a VariantData to a different type.

If newType is the same as self.vtable, then traits::copy() is invoked instead.

Note

The default behavior (if !self.vtable->ConvertTo) merely returns false.

Parameters

self – The VariantData to convert. This parameter provides the v-table for the comparison.

static size_t hash(const VariantData &self) noexcept

Computes a hash of a VariantData.

Note

The default behavior (if !self.vtable->Hash) produces size_t(self.data).

Parameters

self – The VariantData to hash.

Returns

A hash value representing self.