18#include "../namespace.hpp"
19#include "utilities.hpp"
90 template <
class... ARGS>
103 template <class U, typename std::enable_if<std::is_assignable<T &, U>::value,
int>::type = 0>
117 template <class U, typename std::enable_if<std::is_assignable<T &, U>::value,
int>::type = 0>
120 if (this->has_value_)
138 template <typename std::enable_if<std::is_copy_constructible<T>::value,
int>::type = 0>
140 : has_value_(rhs.has_value_)
144 new (&value_) T(*rhs);
154 template <typename std::enable_if<std::is_copy_assignable<T>::value,
int>::type = 0>
162 reinterpret_cast<T &
>(value_).
operator=(*rhs);
166 else if (rhs.has_value_)
168 new (&value_) T(*rhs);
181 template <typename std::enable_if<std::is_move_constructible<T>::value,
int>::type = 0>
183 : has_value_(rhs.has_value_)
187 new (&value_) T(std::move(*rhs));
198 template <typename std::enable_if<std::is_move_assignable<T>::value,
int>::type = 0>
207 reinterpret_cast<T &
>(value_).
operator=(
std::move(*rhs));
215 else if (rhs.has_value_)
243 return &
reinterpret_cast<const T &
>(value_);
256 return &
reinterpret_cast<T &
>(value_);
269 return reinterpret_cast<const T &
>(value_);
282 return reinterpret_cast<T &
>(value_);
290 explicit operator bool() const noexcept
290 explicit operator bool() const noexcept {
…}
305 template <
class... ARGS>
331 reinterpret_cast<T &
>(value_).~T();
361 return reinterpret_cast<const T &
>(value_);
375 return reinterpret_cast<T &
>(value_);
384 template <class U, typename std::enable_if<std::is_assignable<T &, U>::value,
int>::type = 0>
388 return reinterpret_cast<const T &
>(value_);
390 return default_value;
417 template <
class T,
class... ARGS>
433 void swap(Cvb::Shims::optional<T> &lhs, Cvb::Shims::optional<T> &rhs)
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:61
optional(U &&value)
Ctor from an object assignable to T.
Definition optional.hpp:104
optional & operator=(U &&value)
Assignment operator for an object assignable to T.
Definition optional.hpp:118
optional & operator=(optional &&rhs)
Move operator.
Definition optional.hpp:199
T value_or(U &&default_value) const
Gets the contained value if has_value() is true; default_value otherwise.
Definition optional.hpp:385
optional(nullopt_t) noexcept
Ctor for explicitly not storing a value.
Definition optional.hpp:79
const T & operator*() const noexcept
Gets the reference to the stored object.
Definition optional.hpp:267
optional & operator=(const optional &rhs)
Copy operator.
Definition optional.hpp:155
void swap(optional &other)
Swaps this object with the other object.
Definition optional.hpp:343
optional() noexcept
Default ctor not storing a value.
Definition optional.hpp:73
const T * operator->() const noexcept
Gets the reference to the stored object.
Definition optional.hpp:241
bool has_value() const noexcept
Gets whether this optional contains a value.
Definition optional.hpp:319
optional(optional &&rhs)
Move ctor.
Definition optional.hpp:182
T & value()
Gets the contained value.
Definition optional.hpp:370
const T & value() const
Gets the contained value.
Definition optional.hpp:356
optional(const optional &rhs)
Copy ctor.
Definition optional.hpp:139
optional(in_place_t, ARGS &&...args)
In-place constructs a new T object.
Definition optional.hpp:91
void reset()
Destroys any contained value.
Definition optional.hpp:327
T * operator->() noexcept
Gets the reference to the stored object.
Definition optional.hpp:254
T & emplace(ARGS &&...args)
Constructs a new T in-place.
Definition optional.hpp:306
T & operator*() noexcept
Gets the reference to the stored object.
Definition optional.hpp:280
bad_optional_access()=default
Default ctor.
optional() noexcept
Default ctor not storing a value.
Definition optional.hpp:73
This class is a replacement for C++17 std::optional.
optional< T > make_optional(ARGS &&...args)
Factory function to in-place construct a T in an optional.
Definition optional.hpp:418
optional< typename std::decay< T >::type > make_optional(T &&value)
Factory function to create an optional from a T object.
Definition optional.hpp:403
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_bayer_to_rgb.h:17
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