azure-core
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
Azure::Nullable< T > Class Template Referencefinal

Manages an optional contained value, i.e. a value that may or may not be present. More...

#include <nullable.hpp>

Public Member Functions

constexpr Nullable ()
 Constructs a Nullable that represents the absence of value.
 
constexpr Nullable (T initialValue) noexcept(std::is_nothrow_move_constructible< T >::value)
 Constructs a Nullable having an initialValue.
 
 Nullable (const Nullable &other) noexcept(std::is_nothrow_copy_constructible< T >::value)
 Constructs a Nullable by copying another Nullable.
 
 Nullable (Nullable &&other) noexcept(std::is_nothrow_move_constructible< T >::value)
 Constructs a Nullable by moving in another Nullable.
 
 ~Nullable ()
 Destructs the Nullable, calling the destructor for the contained value if there is one.
 
void Reset () noexcept(std::is_nothrow_destructible< T >::value)
 Destructs the contained value, if there is one.
 
void Swap (Nullable &other) noexcept(std::is_nothrow_move_constructible< T >::value)
 Exchanges the contents.
 
Nullableoperator= (const Nullable &other)
 Assignment operator.
 
Nullableoperator= (Nullable &&other) noexcept(std::is_nothrow_move_constructible< T >::value)
 Assignment operator with move semantics.
 
template<class U = T, typename std::enable_if< !std::is_same< Nullable, typename std::remove_cv< typename std::remove_reference< U >::type >::type >::value &&!(std::is_scalar< U >::value &&std::is_same< T, typename std::decay< U >::type >::value) &&std::is_constructible< T, U >::value &&std::is_assignable< T &, U >::value, int >::type = 0>
Nullableoperator= (U &&other) noexcept(std::is_nothrow_constructible< T, U >::value &&std::is_nothrow_assignable< T &, U >::value)
 Assignment operator from another type.
 
template<class... U>
T & Emplace (U &&... Args) noexcept(std::is_nothrow_constructible< T, U... >::value)
 Construct the contained value in-place.
 
bool HasValue () const noexcept
 Check whether a value is contained.
 
const T & Value () const &noexcept
 Get the contained value.
 
T & Value () &noexcept
 Get the contained value reference.
 
T && Value () &&noexcept
 Get the contained value (as rvalue reference).
 
constexpr operator bool () const noexcept
 operator bool on the condition of Azure::Nullable::HasValue.
 
constexpr const T * operator-> () const
 Accesses the contained value.
 
constexpr T * operator-> ()
 Accesses the contained value.
 
constexpr const T & operator* () const &
 Accesses the contained value.
 
constexpr T & operator* () &
 Accesses the contained value.
 
constexpr T && operator* () &&
 Accesses the contained value.
 
constexpr const T && operator* () const &&
 Accesses the contained value.
 
template<class U = T, typename std::enable_if< std::is_convertible< const T &, typename std::remove_cv< T >::type >::value &&std::is_convertible< U, T >::value, int >::type = 0>
constexpr std::remove_cv< T >::type ValueOr (U &&other) const &
 Get the contained value, returns other if value is absent.
 
template<class U = T, typename std::enable_if< std::is_convertible< T, typename std::remove_cv< T >::type >::value &&std::is_convertible< U, T >::value, int >::type = 0>
constexpr std::remove_cv< T >::type ValueOr (U &&other) &&
 Get the contained value, returns other if value is absent.
 

Friends

void swap (Nullable &lhs, Nullable &rhs) noexcept(std::is_nothrow_move_constructible< T >::value)
 Invokes Azure::Nullable::Swap while having a lowercase name that satisfies swappable requirements (see details).
 

Detailed Description

template<class T>
class Azure::Nullable< T >
Template Parameters
TA type to represent contained values.

Constructor & Destructor Documentation

◆ Nullable() [1/4]

template<class T >
constexpr Azure::Nullable< T >::Nullable ( )
inlineconstexpr

◆ Nullable() [2/4]

template<class T >
constexpr Azure::Nullable< T >::Nullable ( initialValue)
inlineconstexprnoexcept
Parameters
initialValueA non-absent value to initialize with.

◆ Nullable() [3/4]

template<class T >
Azure::Nullable< T >::Nullable ( const Nullable< T > &  other)
inlinenoexcept
Parameters
otherAnother Nullable instance to copy.

◆ Nullable() [4/4]

template<class T >
Azure::Nullable< T >::Nullable ( Nullable< T > &&  other)
inlinenoexcept
Parameters
otherA Nullable instance to move into the instance being constructed.

◆ ~Nullable()

template<class T >
Azure::Nullable< T >::~Nullable ( )
inline

Member Function Documentation

◆ Emplace()

template<class T >
template<class... U>
T & Azure::Nullable< T >::Emplace ( U &&...  Args)
inlinenoexcept

If this instance already contains a value before the call, the contained value is destroyed by calling its destructor.

◆ HasValue()

template<class T >
bool Azure::Nullable< T >::HasValue ( ) const
inlinenoexcept
Returns
true If a value is contained, false if value is absent.

◆ operator bool()

template<class T >
constexpr Azure::Nullable< T >::operator bool ( ) const
inlineexplicitconstexprnoexcept

◆ operator*() [1/4]

template<class T >
constexpr T & Azure::Nullable< T >::operator* ( ) &
inlineconstexpr
Returns
Returns a reference to the contained value.
Warning
The behavior is undefined if *this does not contain a value.
Note
This operator does not check whether the Nullable contains a value! You can do so manually by using HasValue() or simply operator bool(). Alternatively, if checked access is needed, Value() or ValueOr() may be used.

◆ operator*() [2/4]

template<class T >
constexpr T && Azure::Nullable< T >::operator* ( ) &&
inlineconstexpr
Returns
Returns a reference to the contained value.
Warning
The behavior is undefined if *this does not contain a value.
Note
This operator does not check whether the Nullable contains a value! You can do so manually by using HasValue() or simply operator bool(). Alternatively, if checked access is needed, Value() or ValueOr() may be used.

◆ operator*() [3/4]

template<class T >
constexpr const T & Azure::Nullable< T >::operator* ( ) const &
inlineconstexpr
Returns
Returns a reference to the contained value.
Warning
The behavior is undefined if *this does not contain a value.
Note
This operator does not check whether the Nullable contains a value! You can do so manually by using HasValue() or simply operator bool(). Alternatively, if checked access is needed, Value() or ValueOr() may be used.

◆ operator*() [4/4]

template<class T >
constexpr const T && Azure::Nullable< T >::operator* ( ) const &&
inlineconstexpr
Returns
Returns a reference to the contained value.
Warning
The behavior is undefined if *this does not contain a value.
Note
This operator does not check whether the Nullable contains a value! You can do so manually by using HasValue() or simply operator bool(). Alternatively, if checked access is needed, Value() or ValueOr() may be used.

◆ operator->() [1/2]

template<class T >
constexpr T * Azure::Nullable< T >::operator-> ( )
inlineconstexpr
Returns
Returns a pointer to the contained value.
Warning
The behavior is undefined if *this does not contain a value.
Note
This operator does not check whether the Nullable contains a value! You can do so manually by using HasValue() or simply operator bool(). Alternatively, if checked access is needed, Value() or ValueOr() may be used.

◆ operator->() [2/2]

template<class T >
constexpr const T * Azure::Nullable< T >::operator-> ( ) const
inlineconstexpr
Returns
Returns a pointer to the contained value.
Warning
The behavior is undefined if *this does not contain a value.
Note
This operator does not check whether the Nullable contains a value! You can do so manually by using HasValue() or simply operator bool(). Alternatively, if checked access is needed, Value() or ValueOr() may be used.

◆ operator=()

template<class T >
template<class U = T, typename std::enable_if< !std::is_same< Nullable, typename std::remove_cv< typename std::remove_reference< U >::type >::type >::value &&!(std::is_scalar< U >::value &&std::is_same< T, typename std::decay< U >::type >::value) &&std::is_constructible< T, U >::value &&std::is_assignable< T &, U >::value, int >::type = 0>
Nullable & Azure::Nullable< T >::operator= ( U &&  other)
inlinenoexcept
Template Parameters
UType of other.
Parameters
otherOther Azure::Nullable.

◆ Reset()

template<class T >
void Azure::Nullable< T >::Reset ( )
inlinenoexcept

◆ Swap()

template<class T >
void Azure::Nullable< T >::Swap ( Nullable< T > &  other)
inlinenoexcept
Parameters
otherAn instance to exchange the contents with.

◆ Value() [1/3]

template<class T >
T && Azure::Nullable< T >::Value ( ) &&
inlinenoexcept

◆ Value() [2/3]

template<class T >
T & Azure::Nullable< T >::Value ( ) &
inlinenoexcept

◆ Value() [3/3]

template<class T >
const T & Azure::Nullable< T >::Value ( ) const &
inlinenoexcept

◆ ValueOr() [1/2]

template<class T >
template<class U = T, typename std::enable_if< std::is_convertible< T, typename std::remove_cv< T >::type >::value &&std::is_convertible< U, T >::value, int >::type = 0>
constexpr std::remove_cv< T >::type Azure::Nullable< T >::ValueOr ( U &&  other) &&
inlineconstexpr
Parameters
otherA value to return when no value is contained.
Returns
A contained value (when present), or other.

◆ ValueOr() [2/2]

template<class T >
template<class U = T, typename std::enable_if< std::is_convertible< const T &, typename std::remove_cv< T >::type >::value &&std::is_convertible< U, T >::value, int >::type = 0>
constexpr std::remove_cv< T >::type Azure::Nullable< T >::ValueOr ( U &&  other) const &
inlineconstexpr
Parameters
otherA value to return when no value is contained.
Returns
A contained value (when present), or other.

Friends And Related Symbol Documentation

◆ swap

template<class T >
void swap ( Nullable< T > &  lhs,
Nullable< T > &  rhs 
)
friend

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