18#include "../namespace.hpp"
19#include "utilities.hpp"
89 template <
class... ARGS>
93 new(&value_) T(std::forward<ARGS>(args)...);
102 template <class U, typename std::enable_if<std::is_assignable<T&, U>::value,
int>::type = 0>
106 new(&value_) T(std::forward<U>(
value));
116 template <class U, typename std::enable_if<std::is_assignable<T&, U>::value,
int>::type = 0>
121 reinterpret_cast<T &
>(value_).
operator=(std::forward<U>(
value));
125 new(&value_) T(std::forward<U>(
value));
137 template <typename std::enable_if<std::is_copy_constructible<T>::value,
int>::type = 0>
139 : has_value_(rhs.has_value_)
143 new(&value_) T(*rhs);
153 template <typename std::enable_if<std::is_copy_assignable<T>::value,
int>::type = 0>
161 reinterpret_cast<T &
>(value_).
operator=(*rhs);
165 else if(rhs.has_value_)
167 new(&value_) T(*rhs);
180 template <typename std::enable_if<std::is_move_constructible<T>::value,
int>::type = 0>
182 : has_value_(rhs.has_value_)
186 new(&value_) T(std::move(*rhs));
197 template <typename std::enable_if<std::is_move_assignable<T>::value,
int>::type = 0>
206 reinterpret_cast<T &
>(value_).
operator=(std::move(*rhs));
214 else if(rhs.has_value_)
216 new(&value_) T(std::move(*rhs));
241 return &
reinterpret_cast<const T &
>(value_);
254 return &
reinterpret_cast<T &
>(value_);
267 return reinterpret_cast<const T &
>(value_);
280 return reinterpret_cast<T &
>(value_);
288 explicit operator bool() const noexcept
303 template <
class... ARGS>
307 auto pValue =
new(&value_) T(std::forward<ARGS>(args)...);
329 reinterpret_cast<T &
>(value_).~T();
343 auto old = std::move(*
this);
344 *
this = std::move(other);
345 other = std::move(old);
359 return reinterpret_cast<const T &
>(value_);
373 return reinterpret_cast<T &
>(value_);
382 template <class U, typename std::enable_if<std::is_assignable<T&, U>::value,
int>::type = 0>
386 return reinterpret_cast<const T &
>(value_);
388 return default_value;
415template <
class T,
class... ARGS>
Error when accessing not set value.
Definition: optional.hpp:33
bad_optional_access()=default
Default ctor.
This class is a replacement for C++17 std::optional.
Definition: optional.hpp:60
optional(U &&value)
Ctor from an object assignable to T.
Definition: optional.hpp:103
optional & operator=(U &&value)
Assignment operator for an object assignable to T.
Definition: optional.hpp:117
optional< T > make_optional(ARGS &&... args)
Factory function to in-place construct a T in an optional.
Definition: optional.hpp:416
optional & operator=(optional &&rhs)
Move operator.
Definition: optional.hpp:198
T value_or(U &&default_value) const
Gets the contained value if has_value() is true; default_value otherwise.
Definition: optional.hpp:383
optional(nullopt_t) noexcept
Ctor for explicitly not storing a value.
Definition: optional.hpp:78
const T & operator*() const noexcept
Gets the reference to the stored object.
Definition: optional.hpp:265
optional & operator=(const optional &rhs)
Copy operator.
Definition: optional.hpp:154
void swap(optional &other)
Swaps this object with the other object.
Definition: optional.hpp:341
optional() noexcept
Default ctor not storing a value.
Definition: optional.hpp:72
const T * operator->() const noexcept
Gets the reference to the stored object.
Definition: optional.hpp:239
optional< typename std::decay< T >::type > make_optional(T &&value)
Factory function to create an optional from a T object.
Definition: optional.hpp:401
bool has_value() const noexcept
Gets whether this optional contains a value.
Definition: optional.hpp:317
optional(in_place_t, ARGS &&... args)
In-place constructs a new T object.
Definition: optional.hpp:90
optional(optional &&rhs)
Move ctor.
Definition: optional.hpp:181
T & emplace(ARGS &&... args)
Constructs a new T in-place.
Definition: optional.hpp:304
T & value()
Gets the contained value.
Definition: optional.hpp:368
const T & value() const
Gets the contained value.
Definition: optional.hpp:354
optional(const optional &rhs)
Copy ctor.
Definition: optional.hpp:138
void reset()
Destroys any contained value.
Definition: optional.hpp:325
T * operator->() noexcept
Gets the reference to the stored object.
Definition: optional.hpp:252
T & operator*() noexcept
Gets the reference to the stored object.
Definition: optional.hpp:278
~optional()
Dtor.
Definition: optional.hpp:226
static constexpr nullopt_t nullopt
Tag to indicate an #optional not containing a value.
Definition: optional.hpp:52
static constexpr in_place_t in_place
Tag to indicate an Optional to in-place construct a value.
Definition: utilities.hpp:28
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24
Disambiguation tags that can be passed to the constructors of optional() to indicate that the contain...
Definition: utilities.hpp:24
Indicates optional() type with uninitialized state.
Definition: optional.hpp:48