rstd 0.1.0
Loading...
Searching...
No Matches
rstd::mem::maybe_uninit::MaybeUninit< T > Class Template Referenceexport
module rstd.core

Public Member Functions

 ~MaybeUninit ()=default
 Destructor does nothing - it never calls T's destructor.
 
constexpr auto write (T &&val) noexcept(meta::is_nothrow_move_constructible_v< T >) -> T &
 
constexpr auto as_ptr () const noexcept -> const T *
 
constexpr auto as_mut_ptr () noexcept -> T *
 
constexpr auto assume_init () &&noexcept -> T requires(meta::is_move_constructible_v< T >)
 
constexpr auto assume_init_read () const noexcept -> T requires(meta::is_copy_constructible_v< T >)
 
constexpr auto assume_init_ref () const noexcept -> const T &
 
constexpr auto assume_init_mut () noexcept -> T &
 
constexpr void assume_init_drop () noexcept
 

Static Public Member Functions

static constexpr auto make (T &&val) noexcept(meta::is_nothrow_move_constructible_v< T >) -> MaybeUninit
 
static constexpr auto uninit () noexcept -> MaybeUninit
 
static constexpr auto zeroed () noexcept -> MaybeUninit
 

Detailed Description

template<typename T = void>
class rstd::mem::maybe_uninit::MaybeUninit< T >

A wrapper type to construct uninitialized instances of T.

This is useful for constructing uninitialized data that is later initialized. Unlike direct use of uninitialized memory, MaybeUninit<T> signals to the compiler that the data here might not be initialized.

Note that dropping a MaybeUninit<T> will never call T's destructor. It is your responsibility to make sure T gets destroyed if it got initialized.

Member Function Documentation

◆ as_mut_ptr()

template<typename T = void>
auto rstd::mem::maybe_uninit::MaybeUninit< T >::as_mut_ptr ( ) -> T*
inlineconstexprexportnoexcept

Gets a mutable pointer to the contained value. Reading from this pointer or dereferencing it is undefined behavior unless the MaybeUninit<T> is initialized.

◆ as_ptr()

template<typename T = void>
auto rstd::mem::maybe_uninit::MaybeUninit< T >::as_ptr ( ) const -> const T*
inlineconstexprexportnoexcept

Gets a const pointer to the contained value. Reading from this pointer or dereferencing it is undefined behavior unless the MaybeUninit<T> is initialized.

◆ assume_init()

template<typename T = void>
auto rstd::mem::maybe_uninit::MaybeUninit< T >::assume_init ( ) && -> T requires(meta::is_move_constructible_v<T>)
inlineconstexprexportnoexcept

Extracts the value from the MaybeUninit<T> container by move.

Safety

It is up to the caller to guarantee that the MaybeUninit<T> really is in an initialized state. Calling this when the content is not yet fully initialized causes undefined behavior.

◆ assume_init_drop()

template<typename T = void>
void rstd::mem::maybe_uninit::MaybeUninit< T >::assume_init_drop ( )
inlineconstexprexportnoexcept

Drops the contained value in place.

Safety

It is up to the caller to guarantee that the MaybeUninit<T> really is in an initialized state. Calling this when the content is not yet fully initialized causes undefined behavior.

◆ assume_init_mut()

template<typename T = void>
auto rstd::mem::maybe_uninit::MaybeUninit< T >::assume_init_mut ( ) -> T&
inlineconstexprexportnoexcept

Gets a mutable reference to the contained value.

Safety

Calling this when the content is not yet fully initialized causes undefined behavior: it is up to the caller to guarantee that the MaybeUninit<T> really is in an initialized state.

◆ assume_init_read()

template<typename T = void>
auto rstd::mem::maybe_uninit::MaybeUninit< T >::assume_init_read ( ) const -> T requires(meta::is_copy_constructible_v<T>)
inlineconstexprexportnoexcept

Extracts the value from the MaybeUninit<T> container by copy.

Safety

It is up to the caller to guarantee that the MaybeUninit<T> really is in an initialized state. Calling this when the content is not yet fully initialized causes undefined behavior.

◆ assume_init_ref()

template<typename T = void>
auto rstd::mem::maybe_uninit::MaybeUninit< T >::assume_init_ref ( ) const -> const T&
inlineconstexprexportnoexcept

Gets a const reference to the contained value.

Safety

Calling this when the content is not yet fully initialized causes undefined behavior: it is up to the caller to guarantee that the MaybeUninit<T> really is in an initialized state.

◆ make()

template<typename T = void>
static constexpr auto rstd::mem::maybe_uninit::MaybeUninit< T >::make ( T && val) -> MaybeUninit
inlinestaticconstexprexportnoexcept

Creates a new MaybeUninit<T> initialized with the given value. It is safe to call assume_init() on the return value of this function.

Note that dropping a MaybeUninit<T> will never call T's destructor. It is your responsibility to make sure T gets destroyed if it got initialized.

◆ uninit()

template<typename T = void>
static constexpr auto rstd::mem::maybe_uninit::MaybeUninit< T >::uninit ( ) -> MaybeUninit
inlinestaticconstexprexportnoexcept

Creates a new MaybeUninit<T> in an uninitialized state.

Note that dropping a MaybeUninit<T> will never call T's destructor. It is your responsibility to make sure T gets destroyed if it got initialized.

◆ write()

template<typename T = void>
auto rstd::mem::maybe_uninit::MaybeUninit< T >::write ( T && val) -> T&
inlineconstexprexportnoexcept

Sets the value of the MaybeUninit<T>.

This overwrites any previous value without dropping it, so be careful not to use this twice unless you want to skip running the destructor. For your convenience, this also returns a mutable reference to the (now safely initialized) contents.

◆ zeroed()

template<typename T = void>
static constexpr auto rstd::mem::maybe_uninit::MaybeUninit< T >::zeroed ( ) -> MaybeUninit
inlinestaticconstexprexportnoexcept

Creates a new MaybeUninit<T> in an uninitialized state, with the memory being filled with 0 bytes.

Note that if T has padding bytes, those bytes may not be zeroed. It depends on T whether that already makes for proper initialization.


The documentation for this class was generated from the following file: