15#ifndef _FASTCDR_XCDR_OPTIONAL_HPP_
16#define _FASTCDR_XCDR_OPTIONAL_HPP_
21#include "detail/optional.hpp"
22#include "../exceptions/BadOptionalAccessException.hpp"
57 const T& val)
noexcept
59 ::new(&storage_.val_)T(val);
60 storage_.engaged_ =
true;
67 ::new(&storage_.val_)T(std::move(val));
68 storage_.engaged_ =
true;
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)...);
100 storage_.engaged_ =
true;
110 bool initial_engaged =
false)
112 if (storage_.engaged_)
116 storage_.engaged_ = initial_engaged;
117 if (storage_.engaged_)
119 ::new(&storage_.val_)T();
131 if (!storage_.engaged_)
137 return storage_.val_;
148 if (!storage_.engaged_)
154 return storage_.val_;
165 if (!storage_.engaged_)
171 return std::move(storage_.val_);
182 if (!storage_.engaged_)
188 return std::move(storage_.val_);
198 return storage_.engaged_;
206 storage_.engaged_ = opt.storage_.engaged_;
207 if (opt.storage_.engaged_)
209 ::new(&storage_.val_)T(opt.storage_.val_);
219 storage_.engaged_ = opt.storage_.engaged_;
220 if (opt.storage_.engaged_)
222 ::new(&storage_.val_)T(std::move(opt.storage_.val_));
232 ::new(&storage_.val_)T(val);
233 storage_.engaged_ =
true;
242 ::new(&storage_.val_)T(std::move(val));
243 storage_.engaged_ =
true;
259 return opt_val.storage_.engaged_ == storage_.engaged_ &&
260 (storage_.engaged_ ? opt_val.storage_.val_ == storage_.val_ :
true);
279 return storage_.val_;
291 return storage_.val_;
303 return std::move(storage_.val_);
315 return std::move(storage_.val_);
327 return std::addressof(storage_.val_);
339 return std::addressof(storage_.val_);
343 explicit operator bool() const noexcept
345 return storage_.engaged_;
This class is thrown as an exception when accessing the value of a null optional.
Definition BadOptionalAccessException.hpp:28
static const char *const BAD_OPTIONAL_ACCESS_MESSAGE_DEFAULT
Default message used in the library.
Definition BadOptionalAccessException.hpp:78
This class template manages an optional contained value, i.e.
Definition optional.hpp:47
bool operator!=(const optional &opt_val) const
Compares optional values.
Definition optional.hpp:264
void reset(bool initial_engaged=false)
Reset the state of the optional.
Definition optional.hpp:109
optional()=default
Default constructor.
T & value() &
Returns the contained value.
Definition optional.hpp:129
optional(optional< T > &&val) noexcept
Move constructor.
Definition optional.hpp:80
optional(const optional< T > &val) noexcept
Copy constructor.
Definition optional.hpp:72
T && value() &&
Returns the contained value.
Definition optional.hpp:163
bool has_value() const
Checks whether the optional contains a value.
Definition optional.hpp:196
T type
Definition optional.hpp:50
optional(const T &val) noexcept
Copy constructor from an instance of the templated class.
Definition optional.hpp:56
T & operator*() &noexcept
Accesses the contained value.
Definition optional.hpp:277
bool operator==(const optional &opt_val) const
Compares optional values.
Definition optional.hpp:256
T * operator->() noexcept
Accesses the contained value.
Definition optional.hpp:325
const T & value() const &
Returns the contained value.
Definition optional.hpp:146
void emplace(Args &&... _args)
Constructs the contained value in-place.
Definition optional.hpp:95
~optional()=default
Destructor.
const T && value() const &&
Returns the contained value.
Definition optional.hpp:180
optional & operator=(const optional &opt)
Assigns content from an optional.
Definition optional.hpp:202
optional(T &&val) noexcept
Move constructor from an instance of the templated class.
Definition optional.hpp:64
static constexpr nullopt_t nullopt
nullopt is a constant of type nullopt_t that is used to indicate optional type with uninitialized sta...
Definition optional.hpp:40
Definition optional.hpp:25
An empty class type used to indicate optional type with uninitialized state.
Definition optional.hpp:29
constexpr nullopt_t(int)
Definition optional.hpp:30