15#ifndef _FASTCDR_XCDR_OPTIONAL_HPP_
16#define _FASTCDR_XCDR_OPTIONAL_HPP_
22#include "../exceptions/BadOptionalAccessException.hpp"
57 const T& val)
noexcept
67 ::new(&
storage_.val_)T(std::move(val));
75 ::new(&
storage_.val_)T(val.storage_.val_);
76 storage_.engaged_ = val.storage_.engaged_;
83 ::new(&
storage_.val_)T(std::move(val.storage_.val_));
84 storage_.engaged_ = val.storage_.engaged_;
99 storage_.val_.T(std::forward<Args>(_args)...);
110 bool initial_engaged =
false)
116 storage_.engaged_ = initial_engaged;
219 storage_.engaged_ = opt.storage_.engaged_;
220 if (opt.storage_.engaged_)
222 ::new(&
storage_.val_)T(std::move(opt.storage_.val_));
242 ::new(&
storage_.val_)T(std::move(val));
343 explicit operator bool() const noexcept
This class is thrown as an exception when accessing the value of a null optional.
static Cdr_DllAPI const char *const BAD_OPTIONAL_ACCESS_MESSAGE_DEFAULT
Default message used in the library.
This class template manages an optional contained value, i.e. a value that may or may not be present.
optional(const T &val) noexcept
Copy constructor from an instance of the templated class.
optional()=default
Default constructor.
T & value() &
Returns the contained value.
~optional()=default
Destructor.
T && value() &&
Returns the contained value.
optional(const optional< T > &val) noexcept
Copy constructor.
optional(T &&val) noexcept
Move constructor from an instance of the templated class.
T * operator->() noexcept
Accesses the contained value.
optional & operator=(const optional &opt)
Assigns content from an optional.
void reset(bool initial_engaged=false)
Reset the state of the optional.
void emplace(Args &&... _args)
Constructs the contained value in-place.
detail::optional_storage< T > storage_
bool operator==(const optional &opt_val) const
Compares optional values.
T & operator*() &noexcept
Accesses the contained value.
optional(optional< T > &&val) noexcept
Move constructor.
const T && value() const &&
Returns the contained value.
bool has_value() const
Checks whether the optional contains a value.
bool operator!=(const optional &opt_val) const
Compares optional values.
const T & value() const &
Returns the contained value.
static constexpr nullopt_t nullopt
nullopt is a constant of type nullopt_t that is used to indicate optional type with uninitialized sta...
An empty class type used to indicate optional type with uninitialized state.