Template Struct StructAccessor¶
Defined in File struct_accessor.hpp
Struct Documentation¶
-
template<typename
T, typenameStorage, size_tIndex>
structripple::StructAccessor: public Storage¶ The struct accessor gets a components of a struct at a given index for a given storage type, this can be used in a union to allow aliases of data elements, for example:
struct Vec2 { using Storage = std::array<int, 2>; union { Storage data; StructAccessor<int, Storage, 0> x; StructAccessor<int, Storage, 1> y; }; auto operator[](size_t i) -> int& { return data[i]; } }; // Usage: Vec 2 v; v[0] = 2; v.y = 3;
- Template Parameters
T: The type of the data for the accessor.Storage: The type of the storage for the accessor.Index: The index of the element in the storage.
Public Functions
-
operator T() const noexcept¶ Overload of conversion operator.
-
operator T&() noexcept¶ Overload of conversion to reference operator.
-
auto
operator=(T v) noexcept -> StructAccessor&¶ Overload of equal operator to set the value to
v.- Parameters
v: The value to set the accessor to.
Public Static Attributes
-
constexpr bool
is_accessor= is_storage_accessor_v<Storage>¶ True if the type is a storage accessor.