userver: utils::OptionalRef< T > Class Template Reference
Loading...
Searching...
No Matches
utils::OptionalRef< T > Class Template Reference

#include <userver/utils/optional_ref.hpp>

Detailed Description

template<class T>
class utils::OptionalRef< T >

Class that behaves as a nullable reference. Main difference from the pointer - value comparison of pointed values.

Initializes from reference to a T or from optional<T>.

Once the reference is constructed it can not be changed to point to different address.

Definition at line 31 of file optional_ref.hpp.

Public Types

using value_type = T

Public Member Functions

constexpr OptionalRef (std::nullopt_t) noexcept
constexpr OptionalRef (const OptionalRef &) noexcept=default
constexpr OptionalRef & operator= (const OptionalRef &) noexcept=delete
constexpr OptionalRef (T &other) noexcept
constexpr OptionalRef (const T &&)=delete
template<typename U>
constexpr OptionalRef (const std::optional< U > &other) noexcept
template<typename U>
constexpr OptionalRef (std::optional< U > &other) noexcept
template<typename U>
constexpr OptionalRef (const std::optional< U > &&) noexcept
template<typename U>
constexpr OptionalRef (const boost::optional< U > &other) noexcept
template<typename U>
constexpr OptionalRef (boost::optional< U > &other) noexcept
template<typename U>
constexpr OptionalRef (const boost::optional< U > &&) noexcept
constexpr bool has_value () const noexcept
constexpr operator bool () const noexcept
constexpr T * operator-> () const
constexpr T & operator* () const
constexpr T & value () const
template<typename U>
constexpr T value_or (U &&default_value) const
template<typename F>
constexpr auto and_then (F &&function) const -> std::remove_cvref_t< std::invoke_result_t< F, T & > >
template<typename F>
constexpr auto transform (F &&function) const
template<typename F>
constexpr OptionalRef or_else (F &&function) const

Member Typedef Documentation

◆ value_type

template<class T>
using utils::OptionalRef< T >::value_type = T

Definition at line 33 of file optional_ref.hpp.

Constructor & Destructor Documentation

◆ OptionalRef() [1/8]

template<class T>
utils::OptionalRef< T >::OptionalRef ( std::nullopt_t )
inlineconstexprnoexcept

Definition at line 38 of file optional_ref.hpp.

◆ OptionalRef() [2/8]

template<class T>
utils::OptionalRef< T >::OptionalRef ( T & other)
inlineconstexprnoexcept

Definition at line 42 of file optional_ref.hpp.

◆ OptionalRef() [3/8]

template<class T>
template<typename U>
utils::OptionalRef< T >::OptionalRef ( const std::optional< U > & other)
inlineexplicitconstexprnoexcept

Definition at line 48 of file optional_ref.hpp.

◆ OptionalRef() [4/8]

template<class T>
template<typename U>
utils::OptionalRef< T >::OptionalRef ( std::optional< U > & other)
inlineexplicitconstexprnoexcept

Definition at line 51 of file optional_ref.hpp.

◆ OptionalRef() [5/8]

template<class T>
template<typename U>
utils::OptionalRef< T >::OptionalRef ( const std::optional< U > && )
inlineexplicitconstexprnoexcept

Definition at line 54 of file optional_ref.hpp.

◆ OptionalRef() [6/8]

template<class T>
template<typename U>
utils::OptionalRef< T >::OptionalRef ( const boost::optional< U > & other)
inlineexplicitconstexprnoexcept

Definition at line 59 of file optional_ref.hpp.

◆ OptionalRef() [7/8]

template<class T>
template<typename U>
utils::OptionalRef< T >::OptionalRef ( boost::optional< U > & other)
inlineexplicitconstexprnoexcept

Definition at line 62 of file optional_ref.hpp.

◆ OptionalRef() [8/8]

template<class T>
template<typename U>
utils::OptionalRef< T >::OptionalRef ( const boost::optional< U > && )
inlineexplicitconstexprnoexcept

Definition at line 65 of file optional_ref.hpp.

Member Function Documentation

◆ and_then()

template<class T>
template<typename F>
auto utils::OptionalRef< T >::and_then ( F && function) const -> std::remove_cvref_t< std::invoke_result_t< F, T & > >
inlineconstexpr

Definition at line 100 of file optional_ref.hpp.

◆ has_value()

template<class T>
bool utils::OptionalRef< T >::has_value ( ) const
inlineconstexprnoexcept

Definition at line 69 of file optional_ref.hpp.

◆ operator bool()

template<class T>
utils::OptionalRef< T >::operator bool ( ) const
inlineexplicitconstexprnoexcept

Definition at line 70 of file optional_ref.hpp.

◆ operator*()

template<class T>
T & utils::OptionalRef< T >::operator* ( ) const
inlineconstexpr

Definition at line 77 of file optional_ref.hpp.

◆ operator->()

template<class T>
T * utils::OptionalRef< T >::operator-> ( ) const
inlineconstexpr

Definition at line 72 of file optional_ref.hpp.

◆ or_else()

template<class T>
template<typename F>
OptionalRef utils::OptionalRef< T >::or_else ( F && function) const
inlineconstexpr

Definition at line 124 of file optional_ref.hpp.

◆ transform()

template<class T>
template<typename F>
auto utils::OptionalRef< T >::transform ( F && function) const
inlineconstexpr

Definition at line 114 of file optional_ref.hpp.

◆ value()

template<class T>
T & utils::OptionalRef< T >::value ( ) const
inlineconstexpr

Definition at line 82 of file optional_ref.hpp.

◆ value_or()

template<class T>
template<typename U>
T utils::OptionalRef< T >::value_or ( U && default_value) const
inlineconstexpr

Definition at line 91 of file optional_ref.hpp.


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