template<typename... Types>
class pw::OptionalTuple< Types >
Tuple class with optional elements. Equivalent to std::tuple<std::optional<Types>...>, but much more efficient. Field presence is tracked by a single pw::BitSet, so the tuple elements are packed equivalently to std::tuple<Types...>.
Tuple elements are specified by their index. Elements may also be referenced by type, if there is only one instance of that type in the tuple.
Compatible with std::tuple_element and std::tuple_size.
- Note
- Like
std::optional, moving an element out of an OptionalTuple leaves the element in an active but moved state (has_value<>() returns true). Call reset() to remove the element.
|
|
constexpr | OptionalTuple ()=default |
| | Default constructs an OptionalTuple with all elements unset.
|
| |
| template<typename... Args, typename = std::enable_if_t< (sizeof...(Args) == sizeof...(Types)) && (sizeof...(Types) != 0) && (std::is_constructible_v<containers::internal::Maybe<Types>, Args> && ...) && (sizeof...(Types) != 1 || (!containers::internal::IsOptionalTuple< cpp20::remove_cvref_t<Args>>::value && ...))>> |
| constexpr | OptionalTuple (Args &&... args) |
| |
|
constexpr | OptionalTuple (const OptionalTuple &)=default |
| |
|
constexpr | OptionalTuple (OptionalTuple &&)=default |
| |
|
constexpr OptionalTuple & | operator= (const OptionalTuple &)=default |
| |
|
constexpr OptionalTuple & | operator= (OptionalTuple &&)=default |
| |
| constexpr size_t | size () const noexcept |
| |
|
constexpr size_t | count () const noexcept |
| | Returns the number of active elements in the OptionalTuple.
|
| |
|
constexpr bool | empty () const noexcept |
| | Checks if the OptionalTuple contains no active elements.
|
| |
|
template<size_t kIndex> |
| constexpr bool | has_value () const noexcept |
| | Checks if the element at kIndex has a value.
|
| |
|
template<typename T > |
| constexpr bool | has_value () const noexcept |
| | Checks if the element of type T has a value.
|
| |
| template<size_t kIndex> |
| constexpr ElementType< kIndex > & | value () & |
| |
| template<size_t kIndex> |
| constexpr const ElementType< kIndex > & | value () const & |
| |
| template<size_t kIndex> |
| constexpr ElementType< kIndex > && | value () && |
| |
| template<size_t kIndex> |
| constexpr const ElementType< kIndex > && | value () const && |
| |
| template<typename T > |
| constexpr ElementByType< T > & | value () & |
| |
| template<typename T > |
| constexpr const ElementByType< T > & | value () const & |
| |
| template<typename T > |
| constexpr ElementByType< T > && | value () && |
| |
| template<typename T > |
| constexpr const ElementByType< T > && | value () const && |
| |
| template<size_t kIndex, int &... kExplicitGuard, typename U > |
| constexpr ElementType< kIndex > | value_or (U &&default_value) const & |
| |
| template<size_t kIndex, int &... kExplicitGuard, typename U > |
| constexpr ElementType< kIndex > | value_or (U &&default_value) && |
| |
| template<typename T , int &... kExplicitGuard, typename U > |
| constexpr ElementByType< T > | value_or (U &&default_value) const & |
| |
| template<typename T , int &... kExplicitGuard, typename U > |
| constexpr ElementByType< T > | value_or (U &&default_value) && |
| |
| template<size_t kIndex, int &... kExplicitGuard, typename... Args> |
| ElementType< kIndex > & | emplace (Args &&... args) |
| |
| template<typename T , int &... kExplicitGuard, typename... Args> |
| ElementByType< T > & | emplace (Args &&... args) |
| |
|
template<size_t kIndex> |
| void | reset () |
| | Resets (clears) the value at the specified index, if any.
|
| |
|
template<typename T > |
| void | reset () |
| | Resets (clears) the value of type T, if any.
|
| |
template<typename... Types>
template<typename... Args, typename = std::enable_if_t< (sizeof...(Args) == sizeof...(Types)) && (sizeof...(Types) != 0) && (std::is_constructible_v<containers::internal::Maybe<Types>, Args> && ...) && (sizeof...(Types) != 1 || (!containers::internal::IsOptionalTuple< cpp20::remove_cvref_t<Args>>::value && ...))>>
Constructs an OptionalTuple, forwarding each argument to its corresponding element. Pass pw::kTupleNull to skip initializing an element.