template<typename Type>
bn::optional class

std::optional like container.

Template parameters
Type Element type.

It doesn't throw exceptions. Instead, asserts are used to ensure valid usage.

Public types

using value_type = Type
Value type alias.

Constructors, destructors, conversion operators

optional() constexpr
Default constructor.
optional(nullopt_t) constexpr
Null constructor.
optional(const optional& other) defaulted constexpr
Copy constructor.
optional(const optional& other) constexpr
Copy constructor.
optional(optional&& other) defaulted constexpr noexcept
Move constructor.
optional(optional&& other) constexpr
Move constructor.
template<typename OtherType>
optional(const optional<OtherType>& other) constexpr
Copy constructor.
template<typename OtherType>
optional(optional<OtherType>&& other) constexpr noexcept
Move constructor.
optional(const Type& value) constexpr
Constructor.
optional(Type&& value) constexpr
Constructor.
~optional() constexpr noexcept
Destructor.
~optional() constexpr
Destructor.
operator bool() const explicit constexpr
Indicates if it contains a value or not.

Public functions

auto operator=(nullopt_t) -> optional& constexpr
Null assignment operator.
auto operator=(const optional& other) -> optional& defaulted constexpr
Copy assignment operator.
auto operator=(const optional& other) -> optional& constexpr
Copy assignment operator.
auto operator=(optional&& other) -> optional& defaulted constexpr noexcept
Move assignment operator.
auto operator=(optional&& other) -> optional& constexpr
Move assignment operator.
template<typename OtherType>
auto operator=(const optional<OtherType>& other) -> optional& constexpr
Copy assignment operator.
template<typename OtherType>
auto operator=(optional<OtherType>&& other) -> optional& constexpr noexcept
Move assignment operator.
auto operator=(const Type& value) -> optional& constexpr
Assignment operator.
auto operator=(Type&& value) -> optional& constexpr
Assignment operator.
auto has_value() const -> bool constexpr
Indicates if it contains a value or not.
auto get() const -> const Type* constexpr
Returns a const pointer to the contained value.
auto get() -> Type* constexpr
Returns a pointer to the contained value.
auto value() const -> const Type& constexpr
Returns a const reference to the contained value.
auto value() -> Type& constexpr
Returns a reference to the contained value.
auto value_or(const Type& default_value) const -> Type constexpr
Returns a copy of the contained value if this optional has one; otherwise it returns a copy of the given default value.
auto value_or(Type&& default_value) const -> Type constexpr
Returns a copy of the contained value if this optional has one; otherwise it returns a moved copy of the given default value.
auto operator->() const -> const Type* constexpr
Returns a const pointer to the contained value.
auto operator->() -> Type* constexpr
Returns a pointer to the contained value.
auto operator*() const -> const Type& constexpr
Returns a const reference to the contained value.
auto operator*() -> Type& constexpr
Returns a reference to the contained value.
template<typename... Args>
auto emplace(Args && ... args) -> Type& constexpr
Constructs the contained value in-place.
void reset() constexpr
Disposes the contained value.
void swap(optional& other) constexpr
Exchanges the contents of this optional with those of the other one.

Friends

void swap(optional& a, optional& b) constexpr
Exchanges the contents of a optional with those of another one.
auto operator==(const optional& a, const optional& b) -> bool constexpr
Equal operator.
auto operator!=(const optional& a, const optional& b) -> bool constexpr
Not equal operator.
auto operator<(const optional& a, const optional& b) -> bool constexpr
Less than operator.
auto operator>(const optional& a, const optional& b) -> bool constexpr
Greater than operator.
auto operator<=(const optional& a, const optional& b) -> bool constexpr
Less than or equal operator.
auto operator>=(const optional& a, const optional& b) -> bool constexpr
Greater than or equal operator.
auto operator==(const optional& a, nullopt_t) -> bool constexpr
Equal operator.
auto operator!=(const optional& a, nullopt_t) -> bool constexpr
Not equal operator.
auto operator<(const optional&, nullopt_t) -> bool constexpr
Less than operator.
auto operator>(const optional& a, nullopt_t) -> bool constexpr
Greater than operator.
auto operator<=(const optional& a, nullopt_t) -> bool constexpr
Less than or equal operator.
auto operator>=(const optional&, nullopt_t) -> bool constexpr
Greater than or equal operator.
template<typename OtherType>
auto operator==(const optional& a, const OtherType& b) -> bool constexpr
Equal operator.
template<typename OtherType>
auto operator!=(const optional& a, const OtherType& b) -> bool constexpr
Not equal operator.
template<typename OtherType>
auto operator<(const optional& a, const OtherType& b) -> bool constexpr
Less than operator.
template<typename OtherType>
auto operator>(const optional& a, const OtherType& b) -> bool constexpr
Greater than operator.
template<typename OtherType>
auto operator<=(const optional& a, const OtherType& b) -> bool constexpr
Less than or equal operator.
template<typename OtherType>
auto operator>=(const optional& a, const OtherType& b) -> bool constexpr
Greater than or equal operator.

Function documentation

template<typename Type>
bn::optional<Type>::optional(const optional& other) defaulted constexpr

Copy constructor.

Parameters
other optional to copy.

template<typename Type>
bn::optional<Type>::optional(const optional& other) constexpr

Copy constructor.

Parameters
other optional to copy.

template<typename Type>
bn::optional<Type>::optional(optional&& other) defaulted constexpr noexcept

Move constructor.

Parameters
other optional to move.

template<typename Type>
bn::optional<Type>::optional(optional&& other) constexpr

Move constructor.

Parameters
other optional to move.

template<typename Type> template<typename OtherType>
bn::optional<Type>::optional(const optional<OtherType>& other) constexpr

Copy constructor.

Parameters
other Different type optional to copy.

template<typename Type> template<typename OtherType>
bn::optional<Type>::optional(optional<OtherType>&& other) constexpr noexcept

Move constructor.

Parameters
other Different type optional to move.

template<typename Type>
bn::optional<Type>::optional(const Type& value) constexpr

Constructor.

Parameters
value Value to copy.

template<typename Type>
bn::optional<Type>::optional(Type&& value) constexpr

Constructor.

Parameters
value Value to move.

template<typename Type>
optional& bn::optional<Type>::operator=(nullopt_t) constexpr

Null assignment operator.

Returns Reference to this.

template<typename Type>
optional& bn::optional<Type>::operator=(const optional& other) defaulted constexpr

Copy assignment operator.

Parameters
other optional to copy.
Returns Reference to this.

template<typename Type>
optional& bn::optional<Type>::operator=(const optional& other) constexpr

Copy assignment operator.

Parameters
other optional to copy.
Returns Reference to this.

template<typename Type>
optional& bn::optional<Type>::operator=(optional&& other) defaulted constexpr noexcept

Move assignment operator.

Parameters
other optional to move.
Returns Reference to this.

template<typename Type>
optional& bn::optional<Type>::operator=(optional&& other) constexpr

Move assignment operator.

Parameters
other optional to move.
Returns Reference to this.

template<typename Type> template<typename OtherType>
optional& bn::optional<Type>::operator=(const optional<OtherType>& other) constexpr

Copy assignment operator.

Parameters
other Different type optional to copy.
Returns Reference to this.

template<typename Type> template<typename OtherType>
optional& bn::optional<Type>::operator=(optional<OtherType>&& other) constexpr noexcept

Move assignment operator.

Parameters
other Different type optional to move.
Returns Reference to this.

template<typename Type>
optional& bn::optional<Type>::operator=(const Type& value) constexpr

Assignment operator.

Parameters
value Value to copy.
Returns Reference to this.

template<typename Type>
optional& bn::optional<Type>::operator=(Type&& value) constexpr

Assignment operator.

Parameters
value Value to move.
Returns Reference to this.

template<typename Type> template<typename... Args>
Type& bn::optional<Type>::emplace(Args && ... args) constexpr

Constructs the contained value in-place.

Parameters
args Parameters of the value to construct.
Returns Reference to the constructed value.

template<typename Type>
void bn::optional<Type>::swap(optional& other) constexpr

Exchanges the contents of this optional with those of the other one.

Parameters
other optional to exchange the contents with.

template<typename Type>
void swap(optional& a, optional& b) constexpr

Exchanges the contents of a optional with those of another one.

Parameters
a First optional to exchange the contents with.
b Second optional to exchange the contents with.