mod_servlet
C++Servlets
 All Classes Files Functions Variables Typedefs Macros Pages
servlet::optional_ref< T > Class Template Reference

Optional reference implementation. More...

#include <optional.h>

Public Types

typedef T value_type
 Type definition for value type.
 
typedef T & reference
 Type definition for reference type.
 
typedef const T & const_reference
 Type definition for constant reference type.
 

Public Member Functions

constexpr optional_ref () noexcept
 Default constructor. More...
 
constexpr optional_ref (T &obj) noexcept
 Constructs object that contains a reference to a given object,. More...
 
constexpr optional_ref (const optional_ref &other) noexcept
 Copy constructor. More...
 
constexpr optional_ref (optional_ref &&other) noexcept
 Move constructor. More...
 
 ~optional_ref () noexcept
 Destructor. More...
 
constexpr optional_refoperator= (const optional_ref &other) noexcept
 Replaces contents of this object with the contents of other. More...
 
constexpr optional_refoperator= (optional_ref &&other) noexcept
 Move assignment. More...
 
constexpr optional_refoperator= (T &obj) noexcept
 Replaces contents of this object with the reference to other. More...
 
constexpr T * operator-> ()
 Accesses the contained value as a pointer. More...
 
constexpr const T * operator-> () const
 Accesses the contained value as a constant pointer. More...
 
constexpr T & operator* ()
 Accesses the contained value as a reference. More...
 
constexpr const T & operator* () const
 Accesses the contained value as a constant reference. More...
 
constexpr operator bool () const noexcept
 Checks whether this object contains valid pointer. More...
 
constexpr bool has_value () const noexcept
 Checks whether this object contains valid pointer. More...
 
constexpr T & value ()&
 Accesses the contained value as a reference. More...
 
constexpr const T & value () const &
 Accesses the contained value as a constant reference. More...
 
template<typename OT >
constexpr T value_or (OT &&dflt) const &noexcept
 Returns the contained value if this has a value, otherwise returns given value. More...
 
constexpr void swap (optional_ref &other) noexcept
 Swaps the contents with those of other. More...
 
constexpr void reset () noexcept
 If this object contains a reference to an object, reset the pointer to that to nullptr. More...
 

Detailed Description

template<typename T>
class servlet::optional_ref< T >

Optional reference implementation.

It is resambles std::optional but doesn't copy the object, instead it stores the reference to the object and never attempts to destroy it. This object might be usefull when returning the object from container and it is not known up front if this object exists.

Template Parameters
thetype of the value to manage.

Constructor & Destructor Documentation

template<typename T>
constexpr servlet::optional_ref< T >::optional_ref ( )
inlinenoexcept

Default constructor.

Constructs the object that does not contain a reference to any value.

template<typename T>
constexpr servlet::optional_ref< T >::optional_ref ( T &  obj)
inlinenoexcept

Constructs object that contains a reference to a given object,.

Parameters
objObject to whcih this object will refere.
template<typename T>
constexpr servlet::optional_ref< T >::optional_ref ( const optional_ref< T > &  other)
inlinenoexcept

Copy constructor.

Parameters
otherobject to copy.
template<typename T>
constexpr servlet::optional_ref< T >::optional_ref ( optional_ref< T > &&  other)
inlinenoexcept

Move constructor.

Parameters
otherobject to move.
template<typename T>
servlet::optional_ref< T >::~optional_ref ( )
inlinenoexcept

Destructor.

Does nothing.

Member Function Documentation

template<typename T>
constexpr bool servlet::optional_ref< T >::has_value ( ) const
inlinenoexcept

Checks whether this object contains valid pointer.

Returns
true if this object contains valid pointer, false otherwise.
template<typename T>
constexpr servlet::optional_ref< T >::operator bool ( ) const
inlineexplicitnoexcept

Checks whether this object contains valid pointer.

Returns
true if this object contains valid pointer, false otherwise.
See Also
has_value
template<typename T>
constexpr T& servlet::optional_ref< T >::operator* ( )
inline

Accesses the contained value as a reference.

Returns
a reference to the contained value.
Exceptions
null_pointer_exceptionif the contained pointer is nullptr.
template<typename T>
constexpr const T& servlet::optional_ref< T >::operator* ( ) const
inline

Accesses the contained value as a constant reference.

Returns
a const reference to the contained value.
Exceptions
null_pointer_exceptionif the contained pointer is nullptr.
template<typename T>
constexpr T* servlet::optional_ref< T >::operator-> ( )
inline

Accesses the contained value as a pointer.

Returns
a pointer to the contained value.
Exceptions
null_pointer_exceptionif the contained pointer is nullptr.
template<typename T>
constexpr const T* servlet::optional_ref< T >::operator-> ( ) const
inline

Accesses the contained value as a constant pointer.

Returns
a const pointer to the contained value.
Exceptions
null_pointer_exceptionif the contained pointer is nullptr.
template<typename T>
constexpr optional_ref& servlet::optional_ref< T >::operator= ( const optional_ref< T > &  other)
inlinenoexcept

Replaces contents of this object with the contents of other.

Parameters
otherobject to assign
Returns
self
template<typename T>
constexpr optional_ref& servlet::optional_ref< T >::operator= ( optional_ref< T > &&  other)
inlinenoexcept

Move assignment.

Parameters
otherobject to assign
Returns
self
template<typename T>
constexpr optional_ref& servlet::optional_ref< T >::operator= ( T &  obj)
inlinenoexcept

Replaces contents of this object with the reference to other.

Parameters
objobject to refere
Returns
self
template<typename T>
constexpr void servlet::optional_ref< T >::reset ( )
inlinenoexcept

If this object contains a reference to an object, reset the pointer to that to nullptr.

Otherwise, there are no effects.

template<typename T>
constexpr void servlet::optional_ref< T >::swap ( optional_ref< T > &  other)
inlinenoexcept

Swaps the contents with those of other.

Parameters
otherthe object to exchange the contents with
template<typename T>
constexpr T& servlet::optional_ref< T >::value ( )
inline

Accesses the contained value as a reference.

Returns
a reference to the contained value.
Exceptions
null_pointer_exceptionif the contained pointer is nullptr.
template<typename T>
constexpr const T& servlet::optional_ref< T >::value ( ) const
inline

Accesses the contained value as a constant reference.

Returns
a const reference to the contained value.
Exceptions
null_pointer_exceptionif the contained pointer is nullptr.
template<typename T>
template<typename OT >
constexpr T servlet::optional_ref< T >::value_or ( OT &&  dflt) const
inlinenoexcept

Returns the contained value if this has a value, otherwise returns given value.

Parameters
dfltthe value to use in case this is empty
Returns
The current value if this has a value, or dflt otherwise.

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