24 #ifndef STATICLIB_SUPPORT_OPTIONAL_HPP
25 #define STATICLIB_SUPPORT_OPTIONAL_HPP
27 #include <type_traits>
29 #include "staticlib/config.hpp"
45 exception(
"Invalid attempt to access non-initialized value of 'optional' object") { }
57 typename std::aligned_storage<sizeof(T), std::alignment_of<T>::value>::type value_space;
62 T* value_ptr =
nullptr;
77 value_ptr(new (std::addressof(value_space)) T(std::move(
value))) { }
95 if(other.has_value()) {
96 value_ptr =
new (std::addressof(value_space)) T(std::move(other.value()));
109 if (other.has_value()) {
110 value_ptr =
new (std::addressof(value_space)) T(std::move(other.value()));
130 explicit operator bool()
const {
140 return nullptr != value_ptr;
182 return std::move(default_value);
195 return std::move(*value_ptr);
197 return std::move(default_value);