xlnt
Public Member Functions | List of all members
xlnt::optional< T > Class Template Reference

Many settings in xlnt are allowed to not have a value set. This class encapsulates a value which may or may not be set. Memory is allocated within the optional class. More...

#include <optional.hpp>

Public Member Functions

 optional () noexcept
 Default contructor. is_set() will be false initially. More...
 
 optional (const T &value) noexcept(XLNT_NOEXCEPT_VALUE_COMPAT(ctor_copy_T_noexcept{}))
 Constructs this optional with a value. noexcept if T copy ctor is noexcept More...
 
 optional (T &&value) noexcept(XLNT_NOEXCEPT_VALUE_COMPAT(ctor_move_T_noexcept{}))
 Constructs this optional with a value. noexcept if T move ctor is noexcept More...
 
 optional (const optional &other) noexcept(XLNT_NOEXCEPT_VALUE_COMPAT(copy_ctor_noexcept{}))
 Copy constructs this optional from other noexcept if T copy ctor is noexcept More...
 
 optional (optional &&other) noexcept(XLNT_NOEXCEPT_VALUE_COMPAT(move_ctor_noexcept{}))
 Move constructs this optional from other. Clears the value from other if set noexcept if T move ctor is noexcept More...
 
optionaloperator= (const optional &other) noexcept(XLNT_NOEXCEPT_VALUE_COMPAT(set_copy_noexcept_t{} &&clear_noexcept_t{}))
 Copy assignment of this optional from other noexcept if set and clear are noexcept for T& More...
 
optionaloperator= (optional &&other) noexcept(XLNT_NOEXCEPT_VALUE_COMPAT(set_move_noexcept_t{} &&clear_noexcept_t{}))
 Move assignment of this optional from other noexcept if set and clear are noexcept for T&& More...
 
 ~optional () noexcept
 Destructor cleans up the T instance if set More...
 
bool is_set () const noexcept
 Returns true if this object currently has a value set. This should be called before accessing the value with optional::get(). More...
 
void set (const T &value) noexcept(XLNT_NOEXCEPT_VALUE_COMPAT(set_copy_noexcept_t{}))
 Copies the value into the stored value More...
 
void set (T &&value) noexcept(XLNT_NOEXCEPT_VALUE_COMPAT(set_move_noexcept_t{}))
 Moves the value into the stored value More...
 
optionaloperator= (const T &rhs) noexcept(XLNT_NOEXCEPT_VALUE_COMPAT(set_copy_noexcept_t{}))
 Assignment operator overload. Equivalent to setting the value using optional::set. More...
 
optionaloperator= (T &&rhs) noexcept(XLNT_NOEXCEPT_VALUE_COMPAT(set_move_noexcept_t{}))
 Assignment operator overload. Equivalent to setting the value using optional::set. More...
 
void clear () noexcept(XLNT_NOEXCEPT_VALUE_COMPAT(clear_noexcept_t{}))
 After this is called, is_set() will return false until a new value is provided. More...
 
T & get ()
 Gets the value. If no value has been initialized in this object, an xlnt::invalid_attribute exception will be thrown. More...
 
const T & get () const
 Gets the value. If no value has been initialized in this object, an xlnt::invalid_attribute exception will be thrown. More...
 
bool operator== (const optional< T > &other) const noexcept
 Returns true if neither this nor other have a value or both have a value and those values are equal according to their equality operator. More...
 
bool operator!= (const optional< T > &other) const noexcept
 Returns false if neither this nor other have a value or both have a value and those values are equal according to their equality operator. More...
 

Detailed Description

template<typename T>
class xlnt::optional< T >

Many settings in xlnt are allowed to not have a value set. This class encapsulates a value which may or may not be set. Memory is allocated within the optional class.

Constructor & Destructor Documentation

◆ optional() [1/5]

template<typename T>
xlnt::optional< T >::optional ( )
inlinenoexcept

Default contructor. is_set() will be false initially.

◆ optional() [2/5]

template<typename T>
xlnt::optional< T >::optional ( const T &  value)
inlinenoexcept

Constructs this optional with a value. noexcept if T copy ctor is noexcept

◆ optional() [3/5]

template<typename T>
xlnt::optional< T >::optional ( T &&  value)
inlinenoexcept

Constructs this optional with a value. noexcept if T move ctor is noexcept

◆ optional() [4/5]

template<typename T>
xlnt::optional< T >::optional ( const optional< T > &  other)
inlinenoexcept

Copy constructs this optional from other noexcept if T copy ctor is noexcept

◆ optional() [5/5]

template<typename T>
xlnt::optional< T >::optional ( optional< T > &&  other)
inlinenoexcept

Move constructs this optional from other. Clears the value from other if set noexcept if T move ctor is noexcept

◆ ~optional()

template<typename T>
xlnt::optional< T >::~optional ( )
inlinenoexcept

Destructor cleans up the T instance if set

Member Function Documentation

◆ clear()

template<typename T>
void xlnt::optional< T >::clear ( )
inlinenoexcept

After this is called, is_set() will return false until a new value is provided.

◆ get() [1/2]

template<typename T>
T& xlnt::optional< T >::get ( )
inline

Gets the value. If no value has been initialized in this object, an xlnt::invalid_attribute exception will be thrown.

◆ get() [2/2]

template<typename T>
const T& xlnt::optional< T >::get ( ) const
inline

Gets the value. If no value has been initialized in this object, an xlnt::invalid_attribute exception will be thrown.

◆ is_set()

template<typename T>
bool xlnt::optional< T >::is_set ( ) const
inlinenoexcept

Returns true if this object currently has a value set. This should be called before accessing the value with optional::get().

◆ operator!=()

template<typename T>
bool xlnt::optional< T >::operator!= ( const optional< T > &  other) const
inlinenoexcept

Returns false if neither this nor other have a value or both have a value and those values are equal according to their equality operator.

◆ operator=() [1/4]

template<typename T>
optional& xlnt::optional< T >::operator= ( const optional< T > &  other)
inlinenoexcept

Copy assignment of this optional from other noexcept if set and clear are noexcept for T&

◆ operator=() [2/4]

template<typename T>
optional& xlnt::optional< T >::operator= ( optional< T > &&  other)
inlinenoexcept

Move assignment of this optional from other noexcept if set and clear are noexcept for T&&

◆ operator=() [3/4]

template<typename T>
optional& xlnt::optional< T >::operator= ( const T &  rhs)
inlinenoexcept

Assignment operator overload. Equivalent to setting the value using optional::set.

◆ operator=() [4/4]

template<typename T>
optional& xlnt::optional< T >::operator= ( T &&  rhs)
inlinenoexcept

Assignment operator overload. Equivalent to setting the value using optional::set.

◆ operator==()

template<typename T>
bool xlnt::optional< T >::operator== ( const optional< T > &  other) const
inlinenoexcept

Returns true if neither this nor other have a value or both have a value and those values are equal according to their equality operator.

◆ set() [1/2]

template<typename T>
void xlnt::optional< T >::set ( const T &  value)
inlinenoexcept

Copies the value into the stored value

◆ set() [2/2]

template<typename T>
void xlnt::optional< T >::set ( T &&  value)
inlinenoexcept

Moves the value into the stored value


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