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 constructs an OptionalTuple with all elements unset.
|
|
template<typename... Args, typename = std::enable_if_t< (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 &other) |
| Copy constructs from another OptionalTuple .
|
|
constexpr OptionalTuple & | operator= (const OptionalTuple &other) |
| Copy assigns this from another OptionalTuple .
|
|
constexpr | OptionalTuple (OptionalTuple &&other) |
| Move constructs from another OptionalTuple .
|
|
constexpr OptionalTuple & | operator= (OptionalTuple &&other) |
| Move assigns this from another OptionalTuple .
|
|
| ~OptionalTuple () |
| Destroys the OptionalTuple and all its active elements.
|
|
constexpr bool | empty () const |
| Checks if the OptionalTuple contains no active elements.
|
|
constexpr size_t | count () const |
| Returns the number of active elements in the OptionalTuple .
|
|
constexpr size_t | size () const |
|
template<size_t kIndex> |
constexpr bool | has_value () const |
| Checks if the element at kIndex has a value.
|
|
template<typename T > |
constexpr bool | has_value () const |
| Checks if the element of type T has a value.
|
|
template<size_t kIndex> |
constexpr Element< kIndex > & | value () & |
|
template<size_t kIndex> |
constexpr const Element< kIndex > & | value () const & |
|
template<size_t kIndex> |
constexpr Element< kIndex > && | value () && |
|
template<size_t kIndex> |
constexpr const Element< 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 Element< kIndex > | value_or (U &&default_value) const & |
|
template<typename T , int... kExplicitGuard, typename U > |
constexpr ElementByType< T > | value_or (U &&default_value) const & |
|
template<size_t kIndex, int... kExplicitGuard, typename U > |
constexpr Element< kIndex > | value_or (U &&default_value) && |
|
template<typename T , int... kExplicitGuard, typename U > |
constexpr ElementByType< T > | value_or (U &&default_value) && |
|
template<size_t kIndex, int... kExplicitGuard, typename... Args> |
constexpr Element< kIndex > & | emplace (Args &&... args) |
|
template<typename T , int... kExplicitGuard, typename... Args> |
constexpr ElementByType< T > & | emplace (Args &&... args) |
|
template<size_t kIndex> |
constexpr void | reset () |
| Resets (clears) the value at the specified index, if any.
|
|
template<typename T > |
constexpr void | reset () |
| Resets (clears) the value of type T , if any.
|
|