29 #ifndef AURORA_OPTIONAL_HPP
30 #define AURORA_OPTIONAL_HPP
36 #include <type_traits>
117 #ifdef AURORA_HAS_VARIADIC_TEMPLATES
121 template <
typename... Args>
125 construct(std::forward<Args>(args)...);
128 #endif // AURORA_HAS_VARIADIC_TEMPLATES
135 construct(std::move(
object));
144 construct(origin.content());
154 construct(std::move(source.content()));
163 Optional(std::move(
object)).swap(*
this);
179 Optional(std::move(source)).swap(*
this);
197 if (mFilled && other.mFilled)
199 adlSwap(content(), other.content());
203 other.construct(std::move(content()));
206 else if (other.mFilled)
208 this->construct(std::move(other.content()));
255 return reinterpret_cast<T&
>(mStorage);
258 const T& content()
const
261 return reinterpret_cast<const T&
>(mStorage);
264 #ifdef AURORA_HAS_VARIADIC_TEMPLATES
266 template <
typename... Args>
267 void construct(Args&&... args)
272 new (&content()) T(std::forward<Args>(args)...);
278 void construct(T& source)
281 new (&content()) T(std::move(source));
285 #endif // AURORA_HAS_VARIADIC_TEMPLATES
297 typename std::aligned_storage<sizeof(T), std::alignment_of<T>::value>::type mStorage;
303 template <
typename T>
309 #ifdef AURORA_HAS_VARIADIC_TEMPLATES
322 template <
typename T,
typename... Args>
325 return Optional<T>(inplace, std::forward<Args>(args)...);
328 #endif // AURORA_HAS_VARIADIC_TEMPLATES
334 template <
typename T>
338 || lhs && rhs && *lhs == *rhs;
344 template <
typename T>
347 return !(lhs == rhs);
354 #endif // AURORA_OPTIONAL_HPP
T & operator*()
Returns the contained object.
Definition: Optional.hpp:215
Optional(T object)
Construct implicitly from T object (move or copy)
Definition: Optional.hpp:132
Optional(InplaceType, Args &&...args)
Construct object in-place, forwarding arguments.
Definition: Optional.hpp:122
Optional(NulloptType)
Construct empty optional from aurora::nullopt.
Definition: Optional.hpp:112
Optional(const Optional &origin)
Copy constructor.
Definition: Optional.hpp:140
~Optional()
Destructor.
Definition: Optional.hpp:185
Configuration header of the library.
Null literal for optional objects.
Definition: Optional.hpp:60
Optional()
Construct empty optional with default constructor.
Definition: Optional.hpp:105
Tag to construct optional objects in-place.
Definition: Optional.hpp:66
T * operator->()
Returns the contained object for member access.
Definition: Optional.hpp:229
Type aurora::SafeBool and corresponding functionality.
Helpers to declare and invoke swap() functions.
Represents optional values.
Definition: Optional.hpp:98
Optional(Optional &&source)
Move constructor.
Definition: Optional.hpp:149
Optional & operator=(T object)
Assign from T object (move or copy)
Definition: Optional.hpp:161
Definition: DispatchTraits.hpp:39
void swap(Optional &other)
Swaps two optional objects.
Definition: Optional.hpp:193