18#ifndef M5_UTILITY_STL_OPTIONAL_HPP
19#define M5_UTILITY_STL_OPTIONAL_HPP
21#define TL_OPTIONAL_VERSION_MAJOR 1
22#define TL_OPTIONAL_VERSION_MINOR 1
23#define TL_OPTIONAL_VERSION_PATCH 0
31#if (defined(_MSC_VER) && _MSC_VER == 1900)
32#define TL_OPTIONAL_MSVC2015
35#if (defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ <= 9 && !defined(__clang__))
36#define TL_OPTIONAL_GCC49
39#if (defined(__GNUC__) && __GNUC__ == 5 && __GNUC_MINOR__ <= 4 && !defined(__clang__))
40#define TL_OPTIONAL_GCC54
43#if (defined(__GNUC__) && __GNUC__ == 5 && __GNUC_MINOR__ <= 5 && !defined(__clang__))
44#define TL_OPTIONAL_GCC55
47#if (defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ <= 9 && !defined(__clang__))
49#define TL_OPTIONAL_NO_CONSTRR
52#define TL_OPTIONAL_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) std::has_trivial_copy_constructor<T>::value
53#define TL_OPTIONAL_IS_TRIVIALLY_COPY_ASSIGNABLE(T) std::has_trivial_copy_assign<T>::value
56#define TL_OPTIONAL_IS_TRIVIALLY_DESTRUCTIBLE(T) std::is_trivially_destructible<T>::value
60#elif (defined(__GNUC__) && __GNUC__ < 8 && !defined(__clang__))
61#ifndef TL_GCC_LESS_8_TRIVIALLY_COPY_CONSTRUCTIBLE_MUTEX
62#define TL_GCC_LESS_8_TRIVIALLY_COPY_CONSTRUCTIBLE_MUTEX
67struct is_trivially_copy_constructible : std::is_trivially_copy_constructible<T> {};
69template <
class T,
class A>
70struct is_trivially_copy_constructible<std::vector<T, A>> : std::is_trivially_copy_constructible<T> {};
77#define TL_OPTIONAL_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) stl::detail::is_trivially_copy_constructible<T>::value
78#define TL_OPTIONAL_IS_TRIVIALLY_COPY_ASSIGNABLE(T) std::is_trivially_copy_assignable<T>::value
79#define TL_OPTIONAL_IS_TRIVIALLY_DESTRUCTIBLE(T) std::is_trivially_destructible<T>::value
81#define TL_OPTIONAL_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) std::is_trivially_copy_constructible<T>::value
82#define TL_OPTIONAL_IS_TRIVIALLY_COPY_ASSIGNABLE(T) std::is_trivially_copy_assignable<T>::value
83#define TL_OPTIONAL_IS_TRIVIALLY_DESTRUCTIBLE(T) std::is_trivially_destructible<T>::value
86#if __cplusplus > 201103L
87#define TL_OPTIONAL_CXX14
91#if (__cplusplus == 201103L || defined(TL_OPTIONAL_MSVC2015) || defined(TL_OPTIONAL_GCC49))
92#define TL_OPTIONAL_11_CONSTEXPR
94#define TL_OPTIONAL_11_CONSTEXPR constexpr
99#ifndef TL_MONOSTATE_INPLACE_MUTEX
100#define TL_MONOSTATE_INPLACE_MUTEX
116#ifndef TL_TRAITS_MUTEX
117#define TL_TRAITS_MUTEX
120using remove_const_t =
typename std::remove_const<T>::type;
122using remove_reference_t =
typename std::remove_reference<T>::type;
124using decay_t =
typename std::decay<T>::type;
125template <
bool E,
class T =
void>
126using enable_if_t =
typename std::enable_if<E, T>::type;
127template <
bool B,
class T,
class F>
128using conditional_t =
typename std::conditional<B, T, F>::type;
135template <
class B,
class... Bs>
136struct conjunction<B, Bs...> : std::conditional<bool(B::value), conjunction<Bs...>, B>::type {};
138#if defined(_LIBCPP_VERSION) && __cplusplus == 201103L
139#define TL_TRAITS_LIBCXX_MEM_FN_WORKAROUND
145#ifdef TL_TRAITS_LIBCXX_MEM_FN_WORKAROUND
147struct is_pointer_to_non_const_member_func : std::false_type {};
148template <
class T,
class Ret,
class... Args>
149struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...)> : std::true_type {};
150template <
class T,
class Ret,
class... Args>
151struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...) &> : std::true_type {};
152template <
class T,
class Ret,
class... Args>
153struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...) &&> : std::true_type {};
154template <
class T,
class Ret,
class... Args>
155struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...) volatile> : std::true_type {};
156template <
class T,
class Ret,
class... Args>
157struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...) volatile &> : std::true_type {};
158template <
class T,
class Ret,
class... Args>
159struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...) volatile &&> : std::true_type {};
162struct is_const_or_const_ref : std::false_type {};
164struct is_const_or_const_ref<T const &> : std::true_type {};
166struct is_const_or_const_ref<T const> : std::true_type {};
172 typename Fn,
typename... Args,
173#ifdef TL_TRAITS_LIBCXX_MEM_FN_WORKAROUND
174 typename = enable_if_t<!(is_pointer_to_non_const_member_func<Fn>::value && is_const_or_const_ref<Args...>::value)>,
176 typename = enable_if_t<std::is_member_pointer<decay_t<Fn>>::value>,
int = 0>
177constexpr auto invoke(Fn &&f, Args &&...args)
noexcept(
noexcept(std::mem_fn(f)(std::forward<Args>(args)...)))
178 ->
decltype(std::mem_fn(f)(std::forward<Args>(args)...))
180 return std::mem_fn(f)(std::forward<Args>(args)...);
183template <
typename Fn,
typename... Args,
typename = enable_if_t<!std::is_member_pointer<decay_t<Fn>>::value>>
184constexpr auto invoke(Fn &&f, Args &&...args)
noexcept(
noexcept(std::forward<Fn>(f)(std::forward<Args>(args)...)))
185 ->
decltype(std::forward<Fn>(f)(std::forward<Args>(args)...))
187 return std::forward<Fn>(f)(std::forward<Args>(args)...);
191template <
class F,
class,
class... Us>
194template <
class F,
class... Us>
195struct invoke_result_impl<F, decltype(detail::invoke(std::declval<F>(), std::declval<Us>()...), void()), Us...> {
196 using type =
decltype(detail::invoke(std::declval<F>(), std::declval<Us>()...));
199template <
class F,
class... Us>
202template <
class F,
class... Us>
203using invoke_result_t =
typename invoke_result<F, Us...>::type;
205#if defined(_MSC_VER) && _MSC_VER <= 1900
207template <
class T,
class U = T>
210template <
class T,
class U = T>
211struct is_nothrow_swappable : std::true_type {};
214namespace swap_adl_tests {
221template <
class T, std::
size_t N>
222tag swap(T (&a)[N], T (&b)[N]);
226template <
class,
class>
227std::false_type can_swap(...) noexcept(false);
228template <class T, class U, class = decltype(swap(std::declval<T &>(), std::declval<U &>()))>
229std::true_type can_swap(
int) noexcept(noexcept(swap(std::declval<T &>(), std::declval<U &>())));
231template <class, class>
232std::false_type uses_std(...);
233template <class T, class U>
234std::is_same<decltype(swap(std::declval<T &>(), std::declval<U &>())),
tag> uses_std(
int);
238 std::is_nothrow_move_assignable<T>::value> {};
240template <
class T, std::
size_t N>
243template <
class T,
class U>
247template <
class T,
class U = T>
249 : std::integral_constant<bool, decltype(detail::swap_adl_tests::can_swap<T, U>(0))::value &&
250 (!decltype(detail::swap_adl_tests::uses_std<T, U>(0))::value ||
251 (std::is_move_assignable<T>::value && std::is_move_constructible<T>::value))> {
254template <
class T, std::
size_t N>
256 : std::integral_constant<bool, decltype(detail::swap_adl_tests::can_swap<T[N], T[N]>(0))::value &&
257 (!decltype(detail::swap_adl_tests::uses_std<T[N], T[N]>(0))::value ||
258 is_swappable<T, T>::value)> {};
260template <
class T,
class U = T>
262 : std::integral_constant<bool, is_swappable<T, U>::value &&
263 ((decltype(detail::swap_adl_tests::uses_std<T, U>(0))::value &&
264 detail::swap_adl_tests::is_std_swap_noexcept<T>::value) ||
265 (!decltype(detail::swap_adl_tests::uses_std<T, U>(0))::value &&
266 detail::swap_adl_tests::is_adl_swap_noexcept<T, U>::value))> {};
275template <
class... Ts>
276using void_t =
typename voider<Ts...>::type;
288using fixup_void = conditional_t<std::is_void<U>::value,
monostate, U>;
290template <
class F,
class U,
class = invoke_result_t<F, U>>
294template <
class F,
class = void,
class... U>
296template <
class F,
class... U>
297struct returns_void_impl<F, void_t<invoke_result_t<F, U...>>, U...> : std::is_void<invoke_result_t<F, U...>> {};
298template <
class F,
class... U>
301template <
class T,
class... U>
302using enable_if_ret_void = enable_if_t<
returns_void<T &&, U...>::value>;
304template <
class T,
class... U>
305using disable_if_ret_void = enable_if_t<!
returns_void<T &&, U...>::value>;
307template <
class T,
class U>
308using enable_forward_value =
309 detail::enable_if_t<std::is_constructible<T, U &&>::value && !std::is_same<detail::decay_t<U>,
in_place_t>::value &&
310 !std::is_same<optional<T>, detail::decay_t<U>>::value>;
312template <
class T,
class U,
class Other>
313using enable_from_other = detail::enable_if_t<
314 std::is_constructible<T, Other>::value && !std::is_constructible<T, optional<U> &>::value &&
315 !std::is_constructible<T, optional<U> &&>::value && !std::is_constructible<T, const optional<U> &>::value &&
316 !std::is_constructible<T, const optional<U> &&>::value && !std::is_convertible<optional<U> &, T>::value &&
317 !std::is_convertible<optional<U> &&, T>::value && !std::is_convertible<const optional<U> &, T>::value &&
318 !std::is_convertible<const optional<U> &&, T>::value>;
320template <
class T,
class U>
321using enable_assign_forward =
322 detail::enable_if_t<!std::is_same<optional<T>, detail::decay_t<U>>::value &&
324 std::is_constructible<T, U>::value && std::is_assignable<T &, U>::value>;
326template <
class T,
class U,
class Other>
327using enable_assign_from_other = detail::enable_if_t<
328 std::is_constructible<T, Other>::value && std::is_assignable<T &, Other>::value &&
329 !std::is_constructible<T, optional<U> &>::value && !std::is_constructible<T, optional<U> &&>::value &&
330 !std::is_constructible<T, const optional<U> &>::value && !std::is_constructible<T, const optional<U> &&>::value &&
331 !std::is_convertible<optional<U> &, T>::value && !std::is_convertible<optional<U> &&, T>::value &&
332 !std::is_convertible<const optional<U> &, T>::value && !std::is_convertible<const optional<U> &&, T>::value &&
333 !std::is_assignable<T &, optional<U> &>::value && !std::is_assignable<T &, optional<U> &&>::value &&
334 !std::is_assignable<T &, const optional<U> &>::value && !std::is_assignable<T &, const optional<U> &&>::value>;
339template <class T, bool = ::std::is_trivially_destructible<T>::value>
345 template <
class... U>
347 : m_value(std::forward<U>(u)...), m_has_value(
true)
375 template <
class... U>
377 : m_value(std::forward<U>(u)...), m_has_value(
true)
389 bool m_has_value =
false;
398 void hard_reset()
noexcept
401 this->m_has_value =
false;
404 template <
class... Args>
405 void construct(Args &&...args)
407 new (std::addressof(this->m_value)) T(std::forward<Args>(args)...);
408 this->m_has_value =
true;
412 void assign(Opt &&rhs)
414 if (this->has_value()) {
415 if (rhs.has_value()) {
416 this->m_value = std::forward<Opt>(rhs).get();
419 this->m_has_value =
false;
423 else if (rhs.has_value()) {
424 construct(std::forward<Opt>(rhs).get());
428 bool has_value()
const
430 return this->m_has_value;
433 TL_OPTIONAL_11_CONSTEXPR T &get() &
435 return this->m_value;
437 TL_OPTIONAL_11_CONSTEXPR
const T &get()
const &
439 return this->m_value;
441 TL_OPTIONAL_11_CONSTEXPR T &&get() &&
443 return std::move(this->m_value);
445#ifndef TL_OPTIONAL_NO_CONSTRR
446 constexpr const T &&get()
const &&
448 return std::move(this->m_value);
455template <
class T,
bool = TL_OPTIONAL_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T)>
468 if (rhs.has_value()) {
469 this->construct(rhs.get());
471 this->m_has_value =
false;
485#ifndef TL_OPTIONAL_GCC49
486template <class T, bool = std::is_trivially_move_constructible<T>::value>
491template <
class T,
bool = false>
503 if (rhs.has_value()) {
504 this->construct(std::move(rhs.get()));
506 this->m_has_value =
false;
514template <
class T,
bool = TL_OPTIONAL_IS_TRIVIALLY_COPY_ASSIGNABLE(T) &&
515 TL_OPTIONAL_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) && TL_OPTIONAL_IS_TRIVIALLY_DESTRUCTIBLE(T)>
541#ifndef TL_OPTIONAL_GCC49
542template <class T, bool = std::is_trivially_destructible<T>::value && std::is_trivially_move_constructible<T>::value &&
543 std::is_trivially_move_assignable<T>::value>
548template <
class T,
bool = false>
564 std::is_nothrow_move_constructible<T>::value && std::is_nothrow_move_assignable<T>::value)
566 this->assign(std::move(rhs));
573template <class T, bool EnableCopy = std::is_copy_constructible<T>::value,
574 bool EnableMove = std::is_move_constructible<T>::value>
612template <
class T,
bool EnableCopy = (std::is_copy_constructible<T>::value && std::is_copy_assignable<T>::value),
613 bool EnableMove = (std::is_move_constructible<T>::value && std::is_move_assignable<T>::value)>
659static constexpr nullopt_t nullopt{nullopt_t::do_not_use{}, nullopt_t::do_not_use{}};
664 const char *what()
const noexcept
666 return "Optional has no value";
682 static_assert(!std::is_same<T, in_place_t>::value,
"instantiation of optional with in_place_t is ill-formed");
684 "instantiation of optional with nullopt_t is ill-formed");
691#if defined(TL_OPTIONAL_CXX14) && !defined(TL_OPTIONAL_GCC49) && !defined(TL_OPTIONAL_GCC54) && \
692 !defined(TL_OPTIONAL_GCC55)
696 TL_OPTIONAL_11_CONSTEXPR
auto and_then(F &&f) &
698 using result = detail::invoke_result_t<F, T &>;
701 return has_value() ? detail::invoke(std::forward<F>(f), **
this) : result(nullopt);
705 TL_OPTIONAL_11_CONSTEXPR
auto and_then(F &&f) &&
707 using result = detail::invoke_result_t<F, T &&>;
710 return has_value() ? detail::invoke(std::forward<F>(f), std::move(**
this)) : result(nullopt);
714 constexpr auto and_then(F &&f)
const &
716 using result = detail::invoke_result_t<F, const T &>;
719 return has_value() ? detail::invoke(std::forward<F>(f), **
this) : result(nullopt);
722#ifndef TL_OPTIONAL_NO_CONSTRR
724 constexpr auto and_then(F &&f)
const &&
726 using result = detail::invoke_result_t<F, const T &&>;
729 return has_value() ? detail::invoke(std::forward<F>(f), std::move(**
this)) : result(nullopt);
736 TL_OPTIONAL_11_CONSTEXPR detail::invoke_result_t<F, T &>
and_then(F &&f) &
738 using result = detail::invoke_result_t<F, T &>;
741 return has_value() ? detail::invoke(std::forward<F>(f), **
this) : result(nullopt);
745 TL_OPTIONAL_11_CONSTEXPR detail::invoke_result_t<F, T &&>
and_then(F &&f) &&
747 using result = detail::invoke_result_t<F, T &&>;
750 return has_value() ? detail::invoke(std::forward<F>(f), std::move(**
this)) : result(nullopt);
754 constexpr detail::invoke_result_t<F, const T &>
and_then(F &&f)
const &
756 using result = detail::invoke_result_t<F, const T &>;
757 static_assert(detail::is_optional<result>::value,
"F must return an optional");
759 return has_value() ? detail::invoke(std::forward<F>(f), **
this) : result(nullopt);
762#ifndef TL_OPTIONAL_NO_CONSTRR
764 constexpr detail::invoke_result_t<F, const T &&>
and_then(F &&f)
const &&
766 using result = detail::invoke_result_t<F, const T &&>;
767 static_assert(detail::is_optional<result>::value,
"F must return an optional");
769 return has_value() ? detail::invoke(std::forward<F>(f), std::move(**
this)) : result(nullopt);
774#if defined(TL_OPTIONAL_CXX14) && !defined(TL_OPTIONAL_GCC49) && !defined(TL_OPTIONAL_GCC54) && \
775 !defined(TL_OPTIONAL_GCC55)
778 TL_OPTIONAL_11_CONSTEXPR
auto map(F &&f) &
780 return optional_map_impl(*
this, std::forward<F>(f));
784 TL_OPTIONAL_11_CONSTEXPR
auto map(F &&f) &&
786 return optional_map_impl(std::move(*
this), std::forward<F>(f));
790 constexpr auto map(F &&f)
const &
792 return optional_map_impl(*
this, std::forward<F>(f));
796 constexpr auto map(F &&f)
const &&
798 return optional_map_impl(std::move(*
this), std::forward<F>(f));
803 TL_OPTIONAL_11_CONSTEXPR
decltype(optional_map_impl(std::declval<optional &>(), std::declval<F &&>()))
map(F &&f) &
805 return optional_map_impl(*
this, std::forward<F>(f));
809 TL_OPTIONAL_11_CONSTEXPR
decltype(optional_map_impl(std::declval<optional &&>(), std::declval<F &&>()))
map(
812 return optional_map_impl(std::move(*
this), std::forward<F>(f));
816 constexpr decltype(optional_map_impl(std::declval<const optional &>(), std::declval<F &&>()))
map(F &&f)
const &
818 return optional_map_impl(*
this, std::forward<F>(f));
821#ifndef TL_OPTIONAL_NO_CONSTRR
823 constexpr decltype(optional_map_impl(std::declval<const optional &&>(), std::declval<F &&>()))
map(F &&f)
const &&
825 return optional_map_impl(std::move(*
this), std::forward<F>(f));
830#if defined(TL_OPTIONAL_CXX14) && !defined(TL_OPTIONAL_GCC49) && !defined(TL_OPTIONAL_GCC54) && \
831 !defined(TL_OPTIONAL_GCC55)
834 TL_OPTIONAL_11_CONSTEXPR
auto transform(F &&f) &
836 return optional_map_impl(*
this, std::forward<F>(f));
840 TL_OPTIONAL_11_CONSTEXPR
auto transform(F &&f) &&
842 return optional_map_impl(std::move(*
this), std::forward<F>(f));
848 return optional_map_impl(*
this, std::forward<F>(f));
854 return optional_map_impl(std::move(*
this), std::forward<F>(f));
859 TL_OPTIONAL_11_CONSTEXPR
decltype(optional_map_impl(std::declval<optional &>(), std::declval<F &&>()))
transform(
862 return optional_map_impl(*
this, std::forward<F>(f));
866 TL_OPTIONAL_11_CONSTEXPR
decltype(optional_map_impl(std::declval<optional &&>(), std::declval<F &&>()))
transform(
869 return optional_map_impl(std::move(*
this), std::forward<F>(f));
873 constexpr decltype(optional_map_impl(std::declval<const optional &>(), std::declval<F &&>()))
transform(
876 return optional_map_impl(*
this, std::forward<F>(f));
879#ifndef TL_OPTIONAL_NO_CONSTRR
881 constexpr decltype(optional_map_impl(std::declval<const optional &&>(), std::declval<F &&>()))
transform(
884 return optional_map_impl(std::move(*
this), std::forward<F>(f));
890 template <
class F, detail::enable_if_ret_
void<F> * =
nullptr>
895 std::forward<F>(f)();
899 template <
class F, detail::disable_if_ret_
void<F> * =
nullptr>
902 return has_value() ? *this : std::forward<F>(f)();
905 template <
class F, detail::enable_if_ret_
void<F> * =
nullptr>
908 if (
has_value())
return std::move(*
this);
910 std::forward<F>(f)();
914 template <
class F, detail::disable_if_ret_
void<F> * =
nullptr>
917 return has_value() ? std::move(*
this) : std::forward<F>(f)();
920 template <
class F, detail::enable_if_ret_
void<F> * =
nullptr>
925 std::forward<F>(f)();
929 template <
class F, detail::disable_if_ret_
void<F> * =
nullptr>
932 return has_value() ? *this : std::forward<F>(f)();
935#ifndef TL_OPTIONAL_NO_CONSTRR
936 template <
class F, detail::enable_if_ret_
void<F> * =
nullptr>
939 if (
has_value())
return std::move(*
this);
941 std::forward<F>(f)();
945 template <
class F, detail::disable_if_ret_
void<F> * =
nullptr>
948 return has_value() ? std::move(*
this) : std::forward<F>(f)();
953 template <
class F,
class U>
956 return has_value() ? detail::invoke(std::forward<F>(f), **
this) : std::forward<U>(u);
959 template <
class F,
class U>
962 return has_value() ? detail::invoke(std::forward<F>(f), std::move(**
this)) : std::forward<U>(u);
965 template <
class F,
class U>
966 U
map_or(F &&f, U &&u)
const &
968 return has_value() ? detail::invoke(std::forward<F>(f), **
this) : std::forward<U>(u);
971#ifndef TL_OPTIONAL_NO_CONSTRR
972 template <
class F,
class U>
973 U
map_or(F &&f, U &&u)
const &&
975 return has_value() ? detail::invoke(std::forward<F>(f), std::move(**
this)) : std::forward<U>(u);
981 template <
class F,
class U>
984 return has_value() ? detail::invoke(std::forward<F>(f), **
this) : std::forward<U>(u)();
987 template <
class F,
class U>
988 detail::invoke_result_t<U>
map_or_else(F &&f, U &&u) &&
990 return has_value() ? detail::invoke(std::forward<F>(f), std::move(**
this)) : std::forward<U>(u)();
993 template <
class F,
class U>
994 detail::invoke_result_t<U>
map_or_else(F &&f, U &&u)
const &
996 return has_value() ? detail::invoke(std::forward<F>(f), **
this) : std::forward<U>(u)();
999#ifndef TL_OPTIONAL_NO_CONSTRR
1000 template <
class F,
class U>
1001 detail::invoke_result_t<U>
map_or_else(F &&f, U &&u)
const &&
1003 return has_value() ? detail::invoke(std::forward<F>(f), std::move(**
this)) : std::forward<U>(u)();
1012 return has_value() ? result{u} : result{nullopt};
1028 return has_value() ? std::move(*
this) : rhs;
1031#ifndef TL_OPTIONAL_NO_CONSTRR
1034 return has_value() ? std::move(*
this) : rhs;
1040 return has_value() ? *this : std::move(rhs);
1045 return has_value() ? *this : std::move(rhs);
1050 return has_value() ? std::move(*
this) : std::move(rhs);
1053#ifndef TL_OPTIONAL_NO_CONSTRR
1056 return has_value() ? std::move(*
this) : std::move(rhs);
1068 using value_type = T;
1090 template <
class... Args>
1093 :
base(in_place, std::forward<Args>(args)...)
1097 template <
class U,
class... Args>
1098 TL_OPTIONAL_11_CONSTEXPR
explicit optional(
1099 detail::enable_if_t<std::is_constructible<T, std::initializer_list<U> &, Args &&...>
::value,
in_place_t>,
1100 std::initializer_list<U> il, Args &&...args)
1102 this->construct(il, std::forward<Args>(args)...);
1106 template <class U = T, detail::enable_if_t<std::is_convertible<U &&, T>::value> * =
nullptr,
1107 detail::enable_forward_value<T, U> * =
nullptr>
1112 template <class U = T, detail::enable_if_t<!std::is_convertible<U &&, T>::value> * =
nullptr,
1113 detail::enable_forward_value<T, U> * =
nullptr>
1114 constexpr explicit optional(U &&u) : base(in_place, std::forward<U>(u))
1119 template <
class U, detail::enable_from_other<T, U, const U &> * =
nullptr,
1120 detail::enable_if_t<std::is_convertible<const U &, T>::value> * =
nullptr>
1124 this->construct(*rhs);
1128 template <
class U, detail::enable_from_other<T, U, const U &> * =
nullptr,
1129 detail::enable_if_t<!std::is_convertible<const U &, T>::value> * =
nullptr>
1133 this->construct(*rhs);
1138 template <
class U, detail::enable_from_other<T, U, U &&> * =
nullptr,
1139 detail::enable_if_t<std::is_convertible<U &&, T>::value> * =
nullptr>
1143 this->construct(std::move(*rhs));
1147 template <
class U, detail::enable_from_other<T, U, U &&> * =
nullptr,
1148 detail::enable_if_t<!std::is_convertible<U &&, T>::value> * =
nullptr>
1152 this->construct(std::move(*rhs));
1166 this->m_has_value =
false;
1186 template <
class U = T, detail::enable_assign_forward<T, U> * =
nullptr>
1190 this->m_value = std::forward<U>(u);
1192 this->construct(std::forward<U>(u));
1202 template <
class U, detail::enable_assign_from_other<T, U, const U &> * =
nullptr>
1207 this->m_value = *rhs;
1214 this->construct(*rhs);
1225 template <
class U, detail::enable_assign_from_other<T, U, U> * =
nullptr>
1230 this->m_value = std::move(*rhs);
1237 this->construct(std::move(*rhs));
1245 template <
class... Args>
1248 static_assert(std::is_constructible<T, Args &&...>
::value,
"T must be constructible with Args");
1251 this->construct(std::forward<Args>(args)...);
1255 template <
class U,
class... Args>
1256 detail::enable_if_t<std::is_constructible<T, std::initializer_list<U> &, Args &&...>
::value, T &>
emplace(
1257 std::initializer_list<U> il, Args &&...args)
1260 this->construct(il, std::forward<Args>(args)...);
1270 void swap(
optional &rhs)
noexcept(std::is_nothrow_move_constructible<T>::value &&
1278 new (std::addressof(rhs.m_value)) T(std::move(this->m_value));
1279 this->m_value.T::~T();
1282 new (std::addressof(this->m_value)) T(std::move(rhs.m_value));
1283 rhs.m_value.T::~T();
1285 swap(this->m_has_value, rhs.m_has_value);
1291 return std::addressof(this->m_value);
1296 return std::addressof(this->m_value);
1302 return this->m_value;
1307 return this->m_value;
1310 TL_OPTIONAL_11_CONSTEXPR T &&
operator*() &&
1312 return std::move(this->m_value);
1315#ifndef TL_OPTIONAL_NO_CONSTRR
1316 constexpr const T &&
operator*() const &&
1318 return std::move(this->m_value);
1325 return this->m_has_value;
1328 constexpr explicit operator bool() const noexcept
1330 return this->m_has_value;
1339 TL_OPTIONAL_11_CONSTEXPR
const T &
value() const &
1344 TL_OPTIONAL_11_CONSTEXPR T &&
value() &&
1346 if (
has_value())
return std::move(this->m_value);
1347 throw bad_optional_access();
1350#ifndef TL_OPTIONAL_NO_CONSTRR
1351 TL_OPTIONAL_11_CONSTEXPR
const T &&
value() const &&
1353 if (
has_value())
return std::move(this->m_value);
1354 throw bad_optional_access();
1362 static_assert(std::is_copy_constructible<T>::value && std::is_convertible<U &&, T>::value,
1363 "T must be copy constructible and convertible from U");
1364 return has_value() ? **this :
static_cast<T
>(std::forward<U>(u));
1368 TL_OPTIONAL_11_CONSTEXPR T
value_or(U &&u) &&
1370 static_assert(std::is_move_constructible<T>::value && std::is_convertible<U &&, T>::value,
1371 "T must be move constructible and convertible from U");
1372 return has_value() ? std::move(**
this) : static_cast<T>(std::forward<U>(u));
1380 this->m_has_value =
false;
1386template <
class T,
class U>
1387inline constexpr bool operator==(
const optional<T> &lhs,
const optional<U> &rhs)
1389 return lhs.has_value() == rhs.has_value() && (!lhs.has_value() || *lhs == *rhs);
1391template <
class T,
class U>
1392inline constexpr bool operator!=(
const optional<T> &lhs,
const optional<U> &rhs)
1394 return lhs.has_value() != rhs.has_value() || (lhs.has_value() && *lhs != *rhs);
1396template <
class T,
class U>
1397inline constexpr bool operator<(
const optional<T> &lhs,
const optional<U> &rhs)
1399 return rhs.has_value() && (!lhs.has_value() || *lhs < *rhs);
1401template <
class T,
class U>
1402inline constexpr bool operator>(
const optional<T> &lhs,
const optional<U> &rhs)
1404 return lhs.has_value() && (!rhs.has_value() || *lhs > *rhs);
1406template <
class T,
class U>
1407inline constexpr bool operator<=(
const optional<T> &lhs,
const optional<U> &rhs)
1409 return !lhs.has_value() || (rhs.has_value() && *lhs <= *rhs);
1411template <
class T,
class U>
1412inline constexpr bool operator>=(
const optional<T> &lhs,
const optional<U> &rhs)
1414 return !rhs.has_value() || (lhs.has_value() && *lhs >= *rhs);
1419inline constexpr bool operator==(
const optional<T> &lhs, nullopt_t)
noexcept
1421 return !lhs.has_value();
1424inline constexpr bool operator==(nullopt_t,
const optional<T> &rhs)
noexcept
1426 return !rhs.has_value();
1429inline constexpr bool operator!=(
const optional<T> &lhs, nullopt_t)
noexcept
1431 return lhs.has_value();
1434inline constexpr bool operator!=(nullopt_t,
const optional<T> &rhs)
noexcept
1436 return rhs.has_value();
1439inline constexpr bool operator<(
const optional<T> &, nullopt_t)
noexcept
1444inline constexpr bool operator<(nullopt_t,
const optional<T> &rhs)
noexcept
1446 return rhs.has_value();
1449inline constexpr bool operator<=(
const optional<T> &lhs, nullopt_t)
noexcept
1451 return !lhs.has_value();
1454inline constexpr bool operator<=(nullopt_t,
const optional<T> &)
noexcept
1459inline constexpr bool operator>(
const optional<T> &lhs, nullopt_t)
noexcept
1461 return lhs.has_value();
1464inline constexpr bool operator>(nullopt_t,
const optional<T> &)
noexcept
1469inline constexpr bool operator>=(
const optional<T> &, nullopt_t)
noexcept
1474inline constexpr bool operator>=(nullopt_t,
const optional<T> &rhs)
noexcept
1476 return !rhs.has_value();
1480template <
class T,
class U>
1481inline constexpr bool operator==(
const optional<T> &lhs,
const U &rhs)
1483 return lhs.has_value() ? *lhs == rhs :
false;
1485template <
class T,
class U>
1486inline constexpr bool operator==(
const U &lhs,
const optional<T> &rhs)
1488 return rhs.has_value() ? lhs == *rhs :
false;
1490template <
class T,
class U>
1491inline constexpr bool operator!=(
const optional<T> &lhs,
const U &rhs)
1493 return lhs.has_value() ? *lhs != rhs :
true;
1495template <
class T,
class U>
1496inline constexpr bool operator!=(
const U &lhs,
const optional<T> &rhs)
1498 return rhs.has_value() ? lhs != *rhs :
true;
1500template <
class T,
class U>
1501inline constexpr bool operator<(
const optional<T> &lhs,
const U &rhs)
1503 return lhs.has_value() ? *lhs < rhs :
true;
1505template <
class T,
class U>
1506inline constexpr bool operator<(
const U &lhs,
const optional<T> &rhs)
1508 return rhs.has_value() ? lhs < *rhs :
false;
1510template <
class T,
class U>
1511inline constexpr bool operator<=(
const optional<T> &lhs,
const U &rhs)
1513 return lhs.has_value() ? *lhs <= rhs :
true;
1515template <
class T,
class U>
1516inline constexpr bool operator<=(
const U &lhs,
const optional<T> &rhs)
1518 return rhs.has_value() ? lhs <= *rhs :
false;
1520template <
class T,
class U>
1521inline constexpr bool operator>(
const optional<T> &lhs,
const U &rhs)
1523 return lhs.has_value() ? *lhs > rhs :
false;
1525template <
class T,
class U>
1526inline constexpr bool operator>(
const U &lhs,
const optional<T> &rhs)
1528 return rhs.has_value() ? lhs > *rhs :
true;
1530template <
class T,
class U>
1531inline constexpr bool operator>=(
const optional<T> &lhs,
const U &rhs)
1533 return lhs.has_value() ? *lhs >= rhs :
false;
1535template <
class T,
class U>
1536inline constexpr bool operator>=(
const U &lhs,
const optional<T> &rhs)
1538 return rhs.has_value() ? lhs >= *rhs :
true;
1541template <class T, detail::enable_if_t<std::is_move_constructible<T>::value> * =
nullptr,
1542 detail::enable_if_t<detail::is_swappable<T>::value> * =
nullptr>
1543void swap(optional<T> &lhs, optional<T> &rhs)
noexcept(
noexcept(lhs.swap(rhs)))
1545 return lhs.swap(rhs);
1553 class Ret = detail::conditional_t<std::is_same<T, detail::i_am_secret>::value, detail::decay_t<U>, T>>
1559template <
class T,
class... Args>
1560inline constexpr optional<T> make_optional(Args &&...args)
1562 return optional<T>(in_place, std::forward<Args>(args)...);
1564template <
class T,
class U,
class... Args>
1565inline constexpr optional<T> make_optional(std::initializer_list<U> il, Args &&...args)
1567 return optional<T>(in_place, il, std::forward<Args>(args)...);
1570#if __cplusplus >= 201703L
1572optional(T) -> optional<T>;
1577#ifdef TL_OPTIONAL_CXX14
1578template <class Opt, class F, class Ret = decltype(detail::invoke(std::declval<F>(), *std::declval<Opt>())),
1579 detail::enable_if_t<!std::is_void<Ret>::value> * =
nullptr>
1580constexpr auto optional_map_impl(Opt &&opt, F &&f)
1582 return opt.has_value() ? detail::invoke(std::forward<F>(f), *std::forward<Opt>(opt)) : optional<Ret>(nullopt);
1585template <class Opt, class F, class Ret = decltype(detail::invoke(std::declval<F>(), *std::declval<Opt>())),
1586 detail::enable_if_t<std::is_void<Ret>::value> * =
nullptr>
1587auto optional_map_impl(Opt &&opt, F &&f)
1589 if (opt.has_value()) {
1590 detail::invoke(std::forward<F>(f), *std::forward<Opt>(opt));
1591 return make_optional(monostate{});
1594 return optional<monostate>(nullopt);
1597template <class Opt, class F, class Ret = decltype(detail::invoke(std::declval<F>(), *std::declval<Opt>())),
1598 detail::enable_if_t<!std::is_void<Ret>::value> * =
nullptr>
1600constexpr auto optional_map_impl(Opt &&opt, F &&f) -> optional<Ret>
1602 return opt.has_value() ? detail::invoke(std::forward<F>(f), *std::forward<Opt>(opt)) : optional<Ret>(nullopt);
1605template <class Opt, class F, class Ret = decltype(detail::invoke(std::declval<F>(), *std::declval<Opt>())),
1606 detail::enable_if_t<std::is_void<Ret>::value> * =
nullptr>
1608auto optional_map_impl(Opt &&opt, F &&f) -> optional<monostate>
1610 if (opt.has_value()) {
1611 detail::invoke(std::forward<F>(f), *std::forward<Opt>(opt));
1629#if defined(TL_OPTIONAL_CXX14) && !defined(TL_OPTIONAL_GCC49) && !defined(TL_OPTIONAL_GCC54) && \
1630 !defined(TL_OPTIONAL_GCC55)
1635 TL_OPTIONAL_11_CONSTEXPR
auto and_then(F &&f) &
1637 using result = detail::invoke_result_t<F, T &>;
1640 return has_value() ? detail::invoke(std::forward<F>(f), **
this) : result(nullopt);
1644 TL_OPTIONAL_11_CONSTEXPR
auto and_then(F &&f) &&
1646 using result = detail::invoke_result_t<F, T &>;
1649 return has_value() ? detail::invoke(std::forward<F>(f), **
this) : result(nullopt);
1653 constexpr auto and_then(F &&f)
const &
1655 using result = detail::invoke_result_t<F, const T &>;
1658 return has_value() ? detail::invoke(std::forward<F>(f), **
this) : result(nullopt);
1661#ifndef TL_OPTIONAL_NO_CONSTRR
1663 constexpr auto and_then(F &&f)
const &&
1665 using result = detail::invoke_result_t<F, const T &>;
1668 return has_value() ? detail::invoke(std::forward<F>(f), **
this) : result(nullopt);
1675 TL_OPTIONAL_11_CONSTEXPR detail::invoke_result_t<F, T &>
and_then(F &&f) &
1677 using result = detail::invoke_result_t<F, T &>;
1680 return has_value() ? detail::invoke(std::forward<F>(f), **
this) : result(nullopt);
1684 TL_OPTIONAL_11_CONSTEXPR detail::invoke_result_t<F, T &> and_then(F &&f) &&
1686 using result = detail::invoke_result_t<F, T &>;
1689 return has_value() ? detail::invoke(std::forward<F>(f), **
this) : result(nullopt);
1693 constexpr detail::invoke_result_t<F, const T &> and_then(F &&f)
const &
1695 using result = detail::invoke_result_t<F, const T &>;
1696 static_assert(detail::is_optional<result>::value,
"F must return an optional");
1698 return has_value() ? detail::invoke(std::forward<F>(f), **
this) : result(nullopt);
1701#ifndef TL_OPTIONAL_NO_CONSTRR
1703 constexpr detail::invoke_result_t<F, const T &> and_then(F &&f)
const &&
1705 using result = detail::invoke_result_t<F, const T &>;
1706 static_assert(detail::is_optional<result>::value,
"F must return an optional");
1708 return has_value() ? detail::invoke(std::forward<F>(f), std::move(**
this)) : result(nullopt);
1713#if defined(TL_OPTIONAL_CXX14) && !defined(TL_OPTIONAL_GCC49) && !defined(TL_OPTIONAL_GCC54) && \
1714 !defined(TL_OPTIONAL_GCC55)
1717 TL_OPTIONAL_11_CONSTEXPR
auto map(F &&f) &
1719 return detail::optional_map_impl(*
this, std::forward<F>(f));
1723 TL_OPTIONAL_11_CONSTEXPR
auto map(F &&f) &&
1725 return detail::optional_map_impl(std::move(*
this), std::forward<F>(f));
1729 constexpr auto map(F &&f)
const &
1731 return detail::optional_map_impl(*
this, std::forward<F>(f));
1735 constexpr auto map(F &&f)
const &&
1737 return detail::optional_map_impl(std::move(*
this), std::forward<F>(f));
1742 TL_OPTIONAL_11_CONSTEXPR
decltype(detail::optional_map_impl(std::declval<optional &>(), std::declval<F &&>()))
map(
1745 return detail::optional_map_impl(*
this, std::forward<F>(f));
1749 TL_OPTIONAL_11_CONSTEXPR
decltype(detail::optional_map_impl(std::declval<optional &&>(), std::declval<F &&>())) map(
1752 return detail::optional_map_impl(std::move(*
this), std::forward<F>(f));
1756 constexpr decltype(detail::optional_map_impl(std::declval<const optional &>(), std::declval<F &&>())) map(
1759 return detail::optional_map_impl(*
this, std::forward<F>(f));
1762#ifndef TL_OPTIONAL_NO_CONSTRR
1764 constexpr decltype(detail::optional_map_impl(std::declval<const optional &&>(), std::declval<F &&>())) map(
1767 return detail::optional_map_impl(std::move(*
this), std::forward<F>(f));
1772#if defined(TL_OPTIONAL_CXX14) && !defined(TL_OPTIONAL_GCC49) && !defined(TL_OPTIONAL_GCC54) && \
1773 !defined(TL_OPTIONAL_GCC55)
1776 TL_OPTIONAL_11_CONSTEXPR
auto transform(F &&f) &
1778 return detail::optional_map_impl(*
this, std::forward<F>(f));
1782 TL_OPTIONAL_11_CONSTEXPR
auto transform(F &&f) &&
1784 return detail::optional_map_impl(std::move(*
this), std::forward<F>(f));
1788 constexpr auto transform(F &&f)
const &
1790 return detail::optional_map_impl(*
this, std::forward<F>(f));
1794 constexpr auto transform(F &&f)
const &&
1796 return detail::optional_map_impl(std::move(*
this), std::forward<F>(f));
1801 TL_OPTIONAL_11_CONSTEXPR
decltype(detail::optional_map_impl(std::declval<optional &>(), std::declval<F &&>()))
1804 return detail::optional_map_impl(*
this, std::forward<F>(f));
1810 TL_OPTIONAL_11_CONSTEXPR
decltype(detail::optional_map_impl(std::declval<optional &&>(), std::declval<F &&>()))
1813 return detail::optional_map_impl(std::move(*
this), std::forward<F>(f));
1817 constexpr decltype(detail::optional_map_impl(std::declval<const optional &>(), std::declval<F &&>())) transform(
1820 return detail::optional_map_impl(*
this, std::forward<F>(f));
1823#ifndef TL_OPTIONAL_NO_CONSTRR
1825 constexpr decltype(detail::optional_map_impl(std::declval<const optional &&>(), std::declval<F &&>())) transform(
1828 return detail::optional_map_impl(std::move(*
this), std::forward<F>(f));
1834 template <
class F, detail::enable_if_ret_
void<F> * =
nullptr>
1837 if (has_value())
return *
this;
1839 std::forward<F>(f)();
1843 template <
class F, detail::disable_if_ret_
void<F> * =
nullptr>
1844 optional<T> TL_OPTIONAL_11_CONSTEXPR or_else(F &&f) &
1846 return has_value() ? *this : std::forward<F>(f)();
1849 template <
class F, detail::enable_if_ret_
void<F> * =
nullptr>
1850 optional<T> or_else(F &&f) &&
1852 if (has_value())
return std::move(*
this);
1854 std::forward<F>(f)();
1858 template <
class F, detail::disable_if_ret_
void<F> * =
nullptr>
1859 optional<T> TL_OPTIONAL_11_CONSTEXPR or_else(F &&f) &&
1861 return has_value() ? std::move(*
this) : std::forward<F>(f)();
1864 template <
class F, detail::enable_if_ret_
void<F> * =
nullptr>
1865 optional<T> or_else(F &&f)
const &
1867 if (has_value())
return *
this;
1869 std::forward<F>(f)();
1873 template <
class F, detail::disable_if_ret_
void<F> * =
nullptr>
1874 optional<T> TL_OPTIONAL_11_CONSTEXPR or_else(F &&f)
const &
1876 return has_value() ? *this : std::forward<F>(f)();
1879#ifndef TL_OPTIONAL_NO_CONSTRR
1880 template <
class F, detail::enable_if_ret_
void<F> * =
nullptr>
1881 optional<T> or_else(F &&f)
const &&
1883 if (has_value())
return std::move(*
this);
1885 std::forward<F>(f)();
1889 template <
class F, detail::disable_if_ret_
void<F> * =
nullptr>
1890 optional<T> or_else(F &&f)
const &&
1892 return has_value() ? std::move(*
this) : std::forward<F>(f)();
1897 template <
class F,
class U>
1900 return has_value() ? detail::invoke(std::forward<F>(f), **
this) : std::forward<U>(u);
1903 template <
class F,
class U>
1904 U map_or(F &&f, U &&u) &&
1906 return has_value() ? detail::invoke(std::forward<F>(f), std::move(**
this)) : std::forward<U>(u);
1909 template <
class F,
class U>
1910 U map_or(F &&f, U &&u)
const &
1912 return has_value() ? detail::invoke(std::forward<F>(f), **
this) : std::forward<U>(u);
1915#ifndef TL_OPTIONAL_NO_CONSTRR
1916 template <
class F,
class U>
1917 U map_or(F &&f, U &&u)
const &&
1919 return has_value() ? detail::invoke(std::forward<F>(f), std::move(**
this)) : std::forward<U>(u);
1925 template <
class F,
class U>
1928 return has_value() ? detail::invoke(std::forward<F>(f), **
this) : std::forward<U>(u)();
1931 template <
class F,
class U>
1932 detail::invoke_result_t<U> map_or_else(F &&f, U &&u) &&
1934 return has_value() ? detail::invoke(std::forward<F>(f), std::move(**
this)) : std::forward<U>(u)();
1937 template <
class F,
class U>
1938 detail::invoke_result_t<U> map_or_else(F &&f, U &&u)
const &
1940 return has_value() ? detail::invoke(std::forward<F>(f), **
this) : std::forward<U>(u)();
1943#ifndef TL_OPTIONAL_NO_CONSTRR
1944 template <
class F,
class U>
1945 detail::invoke_result_t<U> map_or_else(F &&f, U &&u)
const &&
1947 return has_value() ? detail::invoke(std::forward<F>(f), std::move(**
this)) : std::forward<U>(u)();
1956 return has_value() ? result{u} : result{nullopt};
1962 return has_value() ? *this : rhs;
1967 return has_value() ? *this : rhs;
1970 TL_OPTIONAL_11_CONSTEXPR optional disjunction(
const optional &rhs) &&
1972 return has_value() ? std::move(*
this) : rhs;
1975#ifndef TL_OPTIONAL_NO_CONSTRR
1976 constexpr optional disjunction(
const optional &rhs)
const &&
1978 return has_value() ? std::move(*
this) : rhs;
1982 TL_OPTIONAL_11_CONSTEXPR optional disjunction(optional &&rhs) &
1984 return has_value() ? *this : std::move(rhs);
1987 constexpr optional disjunction(optional &&rhs)
const &
1989 return has_value() ? *this : std::move(rhs);
1992 TL_OPTIONAL_11_CONSTEXPR optional disjunction(optional &&rhs) &&
1994 return has_value() ? std::move(*
this) : std::move(rhs);
1997#ifndef TL_OPTIONAL_NO_CONSTRR
1998 constexpr optional disjunction(optional &&rhs)
const &&
2000 return has_value() ? std::move(*
this) : std::move(rhs);
2012 using value_type = T &;
2036 template <
class U = T, detail::enable_if_t<!detail::is_optional<detail::decay_t<U>>::value> * =
nullptr>
2037 constexpr optional(U &&u) noexcept : m_value(std::addressof(u))
2039 static_assert(std::is_lvalue_reference<U>::value,
"U must be an lvalue");
2066 template <
class U = T, detail::enable_if_t<!detail::is_optional<detail::decay_t<U>>::value> * =
nullptr>
2069 static_assert(std::is_lvalue_reference<U>::value,
"U must be an lvalue");
2070 m_value = std::addressof(u);
2081 m_value = std::addressof(rhs.value());
2086 template <
class U = T, detail::enable_if_t<!detail::is_optional<detail::decay_t<U>>::value> * =
nullptr>
2089 return *
this = std::forward<U>(u);
2094 std::swap(m_value, rhs.m_value);
2103 TL_OPTIONAL_11_CONSTEXPR T *operator->() noexcept
2114 constexpr const T &operator*() const noexcept
2119 constexpr bool has_value() const noexcept
2121 return m_value !=
nullptr;
2124 constexpr explicit operator bool() const noexcept
2126 return m_value !=
nullptr;
2132 if (has_value())
return *m_value;
2135 TL_OPTIONAL_11_CONSTEXPR
const T &value()
const
2137 if (has_value())
return *m_value;
2145 static_assert(std::is_copy_constructible<T>::value && std::is_convertible<U &&, T>::value,
2146 "T must be copy constructible and convertible from U");
2147 return has_value() ? **this :
static_cast<T
>(std::forward<U>(u));
2154 static_assert(std::is_move_constructible<T>::value && std::is_convertible<U &&, T>::value,
2155 "T must be move constructible and convertible from U");
2156 return has_value() ? **this :
static_cast<T
>(std::forward<U>(u));
2175struct hash<
m5::stl::optional<T>> {
2180 return std::hash<m5::stl::detail::remove_const_t<T>>()(*o);
Definition optional.hpp:661
Used to represent an optional with no data; essentially a bool.
Definition optional.hpp:102
optional & operator=(nullopt_t) noexcept
Definition optional.hpp:2053
optional take()
Takes the value out of the optional, leaving it empty.
Definition optional.hpp:2005
TL_OPTIONAL_11_CONSTEXPR optional(const optional &rhs) noexcept=default
constexpr optional(U &&u) noexcept
Constructs the stored value with u.
Definition optional.hpp:2037
constexpr const T * operator->() const noexcept
Returns a pointer to the stored value.
Definition optional.hpp:2098
void reset() noexcept
Destroys the stored value if one exists, making the optional empty.
Definition optional.hpp:2160
TL_OPTIONAL_11_CONSTEXPR T & value()
Returns the contained value if there is one, otherwise throws bad_optional_access.
Definition optional.hpp:2130
TL_OPTIONAL_11_CONSTEXPR optional disjunction(const optional &rhs) &
Returns rhs if *this is empty, otherwise the current value.
Definition optional.hpp:1960
constexpr T value_or(U &&u) const &noexcept
Returns the stored value if there is one, otherwise returns u
Definition optional.hpp:2143
TL_OPTIONAL_11_CONSTEXPR decltype(detail::optional_map_impl(std::declval< optional & >(), std::declval< F && >())) map(F &&f) &
Carries out some operation on the stored object if there is one.
Definition optional.hpp:1742
TL_OPTIONAL_11_CONSTEXPR T value_or(U &&u) &&noexcept
\group value_or
Definition optional.hpp:2152
detail::invoke_result_t< U > map_or_else(F &&f, U &&u) &
Definition optional.hpp:1926
TL_OPTIONAL_11_CONSTEXPR T & operator*() noexcept
Returns the stored value.
Definition optional.hpp:2109
optional & operator=(const optional &rhs)=default
TL_OPTIONAL_11_CONSTEXPR detail::invoke_result_t< F, T & > and_then(F &&f) &
Definition optional.hpp:1675
constexpr optional< typename std::decay< U >::type > conjunction(U &&u) const
Returns u if *this has a value, otherwise an empty optional.
Definition optional.hpp:1953
optional< T > TL_OPTIONAL_11_CONSTEXPR or_else(F &&f) &
Calls f if the optional is empty.
Definition optional.hpp:1835
TL_OPTIONAL_11_CONSTEXPR decltype(detail::optional_map_impl(std::declval< optional && >(), std::declval< F && >())) transform(F &&f) &&
Definition optional.hpp:1811
optional & emplace(U &&u) noexcept
Rebinds this optional to u.
Definition optional.hpp:2087
optional & operator=(const optional< U > &rhs) noexcept
Definition optional.hpp:2079
TL_OPTIONAL_11_CONSTEXPR decltype(detail::optional_map_impl(std::declval< optional & >(), std::declval< F && >())) transform(F &&f) &
Carries out some operation on the stored object if there is one.
Definition optional.hpp:1802
~optional()=default
No-op.
optional & operator=(U &&u)
Rebinds this optional to u.
Definition optional.hpp:2067
constexpr optional() noexcept
Constructs an optional that does not contain a value.
Definition optional.hpp:2015
TL_OPTIONAL_11_CONSTEXPR optional(optional &&rhs)=default
U map_or(F &&f, U &&u) &
Maps the stored value with f if there is one, otherwise returns u
Definition optional.hpp:1898
Definition optional.hpp:679
TL_OPTIONAL_11_CONSTEXPR detail::invoke_result_t< F, T & > and_then(F &&f) &
Definition optional.hpp:736
constexpr bool has_value() const noexcept
Returns whether or not the optional has a value.
Definition optional.hpp:1323
constexpr optional< typename std::decay< U >::type > conjunction(U &&u) const
Returns u if *this has a value, otherwise an empty optional.
Definition optional.hpp:1009
TL_OPTIONAL_11_CONSTEXPR decltype(optional_map_impl(std::declval< optional & >(), std::declval< F && >())) map(F &&f) &
Carries out some operation on the stored object if there is one.
Definition optional.hpp:803
~optional()=default
Destroys the stored value if there is one.
optional & operator=(optional< U > &&rhs)
Definition optional.hpp:1226
constexpr optional() noexcept=default
Constructs an optional that does not contain a value.
constexpr const T * operator->() const
Returns a pointer to the stored value.
Definition optional.hpp:1289
U map_or(F &&f, U &&u) &
Maps the stored value with f if there is one, otherwise returns u.
Definition optional.hpp:954
optional & operator=(optional &&rhs)=default
void reset() noexcept
Destroys the stored value if one exists, making the optional empty.
Definition optional.hpp:1376
void swap(optional &rhs) noexcept(std::is_nothrow_move_constructible< T >::value &&detail::is_nothrow_swappable< T >::value)
Definition optional.hpp:1270
optional(const optional< U > &rhs)
Converting copy constructor.
Definition optional.hpp:1121
optional & operator=(nullopt_t) noexcept
Definition optional.hpp:1162
TL_OPTIONAL_11_CONSTEXPR optional(optional &&rhs)=default
T & emplace(Args &&...args)
Definition optional.hpp:1246
optional & operator=(const optional< U > &rhs)
Definition optional.hpp:1203
TL_OPTIONAL_11_CONSTEXPR optional(const optional &rhs)=default
constexpr optional(detail::enable_if_t< std::is_constructible< T, Args... >::value, in_place_t >, Args &&...args)
Constructs the stored value in-place using the given arguments.
Definition optional.hpp:1091
TL_OPTIONAL_11_CONSTEXPR T & value() &
Returns the contained value if there is one, otherwise throws bad_optional_access.
Definition optional.hpp:1334
TL_OPTIONAL_11_CONSTEXPR T & operator*() &
Returns the stored value.
Definition optional.hpp:1300
optional(optional< U > &&rhs)
Converting move constructor.
Definition optional.hpp:1140
constexpr T value_or(U &&u) const &
Returns the stored value if there is one, otherwise returns u
Definition optional.hpp:1360
optional & operator=(const optional &rhs)=default
optional< T > TL_OPTIONAL_11_CONSTEXPR or_else(F &&f) &
Calls f if the optional is empty.
Definition optional.hpp:891
TL_OPTIONAL_11_CONSTEXPR decltype(optional_map_impl(std::declval< optional & >(), std::declval< F && >())) transform(F &&f) &
Carries out some operation on the stored object if there is one.
Definition optional.hpp:859
optional & operator=(U &&u)
Definition optional.hpp:1187
TL_OPTIONAL_11_CONSTEXPR optional disjunction(const optional &rhs) &
Returns rhs if *this is empty, otherwise the current value.
Definition optional.hpp:1016
constexpr optional(U &&u)
Constructs the stored value with u.
Definition optional.hpp:1108
optional take()
Takes the value out of the optional, leaving it empty.
Definition optional.hpp:1061
detail::invoke_result_t< U > map_or_else(F &&f, U &&u) &
Definition optional.hpp:982
Top level namespace of M5.
Definition bit_segment.hpp:17
STL compatibility functions and classes.
Definition optional.hpp:132
Definition optional.hpp:1549
Definition optional.hpp:192
Definition optional.hpp:266
Definition optional.hpp:280
Definition optional.hpp:251
Definition optional.hpp:516
Definition optional.hpp:456
Definition optional.hpp:614
Definition optional.hpp:575
Definition optional.hpp:544
Definition optional.hpp:487
Definition optional.hpp:395
Definition optional.hpp:359
Definition optional.hpp:383
Definition optional.hpp:340
Definition optional.hpp:295
Definition optional.hpp:244
Definition optional.hpp:238
Definition optional.hpp:217
Definition optional.hpp:272
A tag type to tell optional to construct its value in-place.
Definition optional.hpp:105
Definition optional.hpp:653
A tag type to represent an empty optional.
Definition optional.hpp:652