10 #include <type_traits>
22 template <
typename Type>
25 using RawType = std::remove_reference_t<Type>;
45 template <typename T, typename = std::enable_if_t<std::is_copy_assignable<T>::value>>
56 storage.
emplace(std::forward<Type>(t));
77 storage.
emplace(std::forward<Type>(other.value()));
94 template <
typename... TArgs>
99 storage.
emplace(std::forward<TArgs>(args)...);
104 template <typename T, typename = std::enable_if_t<std::is_assignable<Type, T>::value>>
118 storage.
emplace(std::forward<Type>(t));
121 value() = std::forward<Type>(t);
151 storage.
emplace(std::move(other.value()));
154 value() = std::move(other.value());
187 template <
typename TOther>
198 template <
typename TException,
typename... TArgs>
203 throw TException(std::forward<TArgs>(args)...);
212 return std::addressof(
value());
220 return std::addressof(
value());
234 template <
typename T1,
typename T2>
242 template <
typename T>
247 return opt.
value() == t;
250 template <
typename T>
255 return opt.
value() == t;
259 template <
typename T>
261 if (!opt1 || !opt2) {
268 template <
typename T>
Base class for utility wrappers (Optional, Variant, ...)
#define SPH_ASSERT(x,...)
#define INLINE
Macros for conditional compilation based on selected compiler.
#define NAMESPACE_SPH_END
bool operator==(const Optional< T > &opt, const T &t)
const NothingType NOTHING
Optional< T1 > optionalCast(const Optional< T2 > &opt)
Few non-standard type traits.
Simple block of memory on stack with size and alignment given by template type.
INLINE void emplace(TArgs &&... rest)
Wrapper of type value of which may or may not be present.
Optional & operator=(const Optional &other)
Copies the value of another optional object.
INLINE Type & value()
Returns the reference to the stored value.
Optional & operator=(Type &&t)
Moves the value on right-hand side, initializing the optional if necessary.
Optional(const Optional &other)
Copy constructor from other optional.
Optional & operator=(const NothingType &)
Destroys the stored value, provided the object has been initialized.
INLINE const RawType * operator->() const
Used to access members of the stored value.
INLINE RawType * operator->()
Used to access members of the stored value.
Optional(const NothingType &)
Construct uninitialized value.
Optional()=default
Creates an uninitialized value.
Optional(Optional &&other)
Move constructor from other optional.
INLINE Type valueOr(const TOther &other) const
Returns the stored value if the object has been initialized, otherwise returns provided parameter.
Optional & operator=(const T &t)
Copies the value on right-hand side, initializing the optional if necessary.
INLINE bool operator!() const
Returns true if the object is uninitialized.
INLINE const Type & value() const
Returns the const reference to the stored value.
Optional & operator=(Optional &&other)
Moves the value of another optional object.
Optional(const T &t)
Copy constuctor from stored value.
Optional(Type &&t)
Move constuctor from stored value.
void emplace(TArgs &&... args)
Constructs the uninitialized object from a list of arguments.
INLINE Type valueOrThrow(TArgs &&... args)
Returns the stored value if the object has been initialized, otherwise throws an exception,...