#include <bn_optional.h>
template<typename Type>
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 noexcept
- 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 noexcept
- 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 noexcept
- 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
- 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
- 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 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>
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. |