libER 0.1.4.2
ELDEN RING API library
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
liber::optref< T > Struct Template Reference

A std::optional<std::reference_wrapper<T>> wrapper for lvalue references. More...

#include <optref.hpp>

Public Types

using value_type = T
 Value type.
 
using reference_type = std::add_lvalue_reference_t< T >
 Reference type.
 
using const_reference_type = std::add_const_t< reference_type >
 Const reference type.
 
using reference_wrapper_type = std::reference_wrapper< value_type >
 Reference wrapper type for std::optional.
 

Public Member Functions

constexpr optref () noexcept
 Default constructor - std::optional contains no reference.
 
constexpr optref (std::nullopt_t) noexcept
 Nullopt constructor - no reference.
 
constexpr optref (const optref &other) noexcept
 Copy constructor.
 
template<typename U >
requires std::convertible_to<U, T>
constexpr optref (const optref< U > &other) noexcept
 Converting copy constructor for base/derived class references.
 
constexpr optref (T &reference) noexcept
 Construct an optref from reference.
 
constexpr optref (std::reference_wrapper< T > wrapper) noexcept
 Construct an optref from std::reference_wrapper.
 
constexpr optref (T *pointer) noexcept
 Construct an optref from a pointer.
 
constexpr bool has_reference () const noexcept
 Does it contain a reference?
 
constexpr operator bool () const noexcept
 Does it contain a reference?
 
constexpr reference_type reference ()
 Get the contained reference; throws if none.
 
constexpr const_reference_type reference () const
 Get the contained const reference; throws if none.
 
void swap (optref &other) noexcept
 Swap implementation.
 
void reset () noexcept
 Reset (cannot assign after).
 

Detailed Description

template<typename T>
requires not_reference<T>
struct liber::optref< T >

A std::optional<std::reference_wrapper<T>> wrapper for lvalue references.

Satisfies CopyConstructible, CopyAssignable and TriviallyCopyable.

Template Parameters
Tthe (optionally) referenced object

Constructor & Destructor Documentation

◆ optref()

template<typename T >
template<typename U >
requires std::convertible_to<U, T>
constexpr liber::optref< T >::optref ( const optref< U > &  other)
inlineconstexprnoexcept

Converting copy constructor for base/derived class references.

Template Parameters
Uanother class that is convertible to T
Parameters
other

Member Function Documentation

◆ has_reference()

template<typename T >
constexpr bool liber::optref< T >::has_reference ( ) const
inlineconstexprnoexcept

Does it contain a reference?

Returns
true
false

◆ operator bool()

template<typename T >
constexpr liber::optref< T >::operator bool ( ) const
inlineexplicitconstexprnoexcept

Does it contain a reference?

Returns
true
false

◆ reference() [1/2]

template<typename T >
constexpr reference_type liber::optref< T >::reference ( )
inlineconstexpr

Get the contained reference; throws if none.

Exceptions
std::bad_optional_access
Returns
reference_type the reference

◆ reference() [2/2]

template<typename T >
constexpr const_reference_type liber::optref< T >::reference ( ) const
inlineconstexpr

Get the contained const reference; throws if none.

Exceptions
std::bad_optional_access
Returns
const_reference_type the const reference

◆ swap()

template<typename T >
void liber::optref< T >::swap ( optref< T > &  other)
inlinenoexcept

Swap implementation.

Parameters
other

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