lib/thirdparty: update expected/optional

This commit is contained in:
Dirk-Jan C. Binnema
2023-03-03 18:41:45 +02:00
parent 413a2564b6
commit 9d0fe0e5d4
2 changed files with 359 additions and 242 deletions

View File

@ -1,6 +1,6 @@
///
// expected - An implementation of std::expected with extensions
// Written in 2017 by Simon Brand (simonrbrand@gmail.com, @TartanLlama)
// Written in 2017 by Sy Brand (tartanllama@gmail.com, @TartanLlama)
//
// Documentation available at http://tl.tartanllama.xyz/
//
@ -51,6 +51,16 @@
#define TL_EXPECTED_GCC55
#endif
#if !defined(TL_ASSERT)
//can't have assert in constexpr in C++11 and GCC 4.9 has a compiler bug
#if (__cplusplus > 201103L) && !defined(TL_EXPECTED_GCC49)
#include <cassert>
#define TL_ASSERT(x) assert(x)
#else
#define TL_ASSERT(x)
#endif
#endif
#if (defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ <= 9 && \
!defined(__clang__))
// GCC < 5 doesn't support overloading on const&& for member functions
@ -66,30 +76,30 @@
#define TL_EXPECTED_IS_TRIVIALLY_DESTRUCTIBLE(T) \
std::is_trivially_destructible<T>
// GCC 5 < v < 8 has a bug in is_trivially_copy_constructible which breaks std::vector
// for non-copyable types
#elif (defined(__GNUC__) && __GNUC__ < 8 && \
!defined(__clang__))
// GCC 5 < v < 8 has a bug in is_trivially_copy_constructible which breaks
// std::vector for non-copyable types
#elif (defined(__GNUC__) && __GNUC__ < 8 && !defined(__clang__))
#ifndef TL_GCC_LESS_8_TRIVIALLY_COPY_CONSTRUCTIBLE_MUTEX
#define TL_GCC_LESS_8_TRIVIALLY_COPY_CONSTRUCTIBLE_MUTEX
namespace tl {
namespace detail {
template <class T>
struct is_trivially_copy_constructible : std::is_trivially_copy_constructible<T>{};
struct is_trivially_copy_constructible
: std::is_trivially_copy_constructible<T> {};
#ifdef _GLIBCXX_VECTOR
template <class T, class A>
struct is_trivially_copy_constructible<std::vector<T,A>>
: std::false_type{};
struct is_trivially_copy_constructible<std::vector<T, A>> : std::false_type {};
#endif
}
}
} // namespace detail
} // namespace tl
#endif
#define TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) \
tl::detail::is_trivially_copy_constructible<T>
#define TL_EXPECTED_IS_TRIVIALLY_COPY_ASSIGNABLE(T) \
std::is_trivially_copy_assignable<T>
#define TL_EXPECTED_IS_TRIVIALLY_DESTRUCTIBLE(T) std::is_trivially_destructible<T>
#define TL_EXPECTED_IS_TRIVIALLY_DESTRUCTIBLE(T) \
std::is_trivially_destructible<T>
#else
#define TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) \
std::is_trivially_copy_constructible<T>
@ -138,6 +148,17 @@ public:
constexpr explicit unexpected(E &&e) : m_val(std::move(e)) {}
template <class... Args, typename std::enable_if<std::is_constructible<
E, Args &&...>::value>::type * = nullptr>
constexpr explicit unexpected(Args &&...args)
: m_val(std::forward<Args>(args)...) {}
template <
class U, class... Args,
typename std::enable_if<std::is_constructible<
E, std::initializer_list<U> &, Args &&...>::value>::type * = nullptr>
constexpr explicit unexpected(std::initializer_list<U> l, Args &&...args)
: m_val(l, std::forward<Args>(args)...) {}
constexpr const E &value() const & { return m_val; }
TL_EXPECTED_11_CONSTEXPR E &value() & { return m_val; }
TL_EXPECTED_11_CONSTEXPR E &&value() && { return std::move(m_val); }
@ -147,6 +168,10 @@ private:
E m_val;
};
#ifdef __cpp_deduction_guides
template <class E> unexpected(E) -> unexpected<E>;
#endif
template <class E>
constexpr bool operator==(const unexpected<E> &lhs, const unexpected<E> &rhs) {
return lhs.value() == rhs.value();
@ -188,6 +213,7 @@ template<typename E>
#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED
throw std::forward<E>(e);
#else
(void)e;
#ifdef _MSC_VER
__assume(0);
#else
@ -223,19 +249,26 @@ struct conjunction<B, Bs...>
// which results in a hard-error when using it in a noexcept expression
// in some cases. This is a check to workaround the common failing case.
#ifdef TL_TRAITS_LIBCXX_MEM_FN_WORKAROUND
template <class T> struct is_pointer_to_non_const_member_func : std::false_type {};
template <class T>
struct is_pointer_to_non_const_member_func : std::false_type {};
template <class T, class Ret, class... Args>
struct is_pointer_to_non_const_member_func<Ret(T::*) (Args...)> : std::true_type {};
struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...)>
: std::true_type {};
template <class T, class Ret, class... Args>
struct is_pointer_to_non_const_member_func<Ret(T::*) (Args...)&> : std::true_type {};
struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...) &>
: std::true_type {};
template <class T, class Ret, class... Args>
struct is_pointer_to_non_const_member_func<Ret(T::*) (Args...) &&> : std::true_type {};
struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...) &&>
: std::true_type {};
template <class T, class Ret, class... Args>
struct is_pointer_to_non_const_member_func<Ret(T::*) (Args...) volatile> : std::true_type {};
struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...) volatile>
: std::true_type {};
template <class T, class Ret, class... Args>
struct is_pointer_to_non_const_member_func<Ret(T::*) (Args...) volatile &> : std::true_type {};
struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...) volatile &>
: std::true_type {};
template <class T, class Ret, class... Args>
struct is_pointer_to_non_const_member_func<Ret(T::*) (Args...) volatile &&> : std::true_type {};
struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...) volatile &&>
: std::true_type {};
template <class T> struct is_const_or_const_ref : std::false_type {};
template <class T> struct is_const_or_const_ref<T const &> : std::true_type {};
@ -244,13 +277,13 @@ template <class T> struct is_const_or_const_ref<T const> : std::true_type {};
// std::invoke from C++17
// https://stackoverflow.com/questions/38288042/c11-14-invoke-workaround
template <typename Fn, typename... Args,
template <
typename Fn, typename... Args,
#ifdef TL_TRAITS_LIBCXX_MEM_FN_WORKAROUND
typename = enable_if_t<!(is_pointer_to_non_const_member_func<Fn>::value
&& is_const_or_const_ref<Args...>::value)>,
typename = enable_if_t<!(is_pointer_to_non_const_member_func<Fn>::value &&
is_const_or_const_ref<Args...>::value)>,
#endif
typename = enable_if_t<std::is_member_pointer<decay_t<Fn>>::value>,
int = 0>
typename = enable_if_t<std::is_member_pointer<decay_t<Fn>>::value>, int = 0>
constexpr auto invoke(Fn &&f, Args &&...args) noexcept(
noexcept(std::mem_fn(f)(std::forward<Args>(args)...)))
-> decltype(std::mem_fn(f)(std::forward<Args>(args)...)) {
@ -270,9 +303,11 @@ template <class F, class, class... Us> struct invoke_result_impl;
template <class F, class... Us>
struct invoke_result_impl<
F, decltype(detail::invoke(std::declval<F>(), std::declval<Us>()...), void()),
F,
decltype(detail::invoke(std::declval<F>(), std::declval<Us>()...), void()),
Us...> {
using type = decltype(detail::invoke(std::declval<F>(), std::declval<Us>()...));
using type =
decltype(detail::invoke(std::declval<F>(), std::declval<Us>()...));
};
template <class F, class... Us>
@ -337,8 +372,8 @@ struct is_swappable<T[N], T[N]>
: std::integral_constant<
bool,
decltype(detail::swap_adl_tests::can_swap<T[N], T[N]>(0))::value &&
(!decltype(
detail::swap_adl_tests::uses_std<T[N], T[N]>(0))::value ||
(!decltype(detail::swap_adl_tests::uses_std<T[N], T[N]>(
0))::value ||
is_swappable<T, T>::value)> {};
template <class T, class U = T>
@ -346,12 +381,10 @@ struct is_nothrow_swappable
: std::integral_constant<
bool,
is_swappable<T, U>::value &&
((decltype(detail::swap_adl_tests::uses_std<T, U>(0))::value
&& detail::swap_adl_tests::is_std_swap_noexcept<T>::value) ||
((decltype(detail::swap_adl_tests::uses_std<T, U>(0))::value &&
detail::swap_adl_tests::is_std_swap_noexcept<T>::value) ||
(!decltype(detail::swap_adl_tests::uses_std<T, U>(0))::value &&
detail::swap_adl_tests::is_adl_swap_noexcept<T,
U>::value))> {
};
detail::swap_adl_tests::is_adl_swap_noexcept<T, U>::value))> {};
#endif
#endif
@ -393,14 +426,10 @@ using is_move_constructible_or_void =
is_void_or<T, std::is_move_constructible<T>>;
template <class T>
using is_copy_assignable_or_void =
is_void_or<T, std::is_copy_assignable<T>>;
using is_copy_assignable_or_void = is_void_or<T, std::is_copy_assignable<T>>;
template <class T>
using is_move_assignable_or_void =
is_void_or<T, std::is_move_assignable<T>>;
using is_move_assignable_or_void = is_void_or<T, std::is_move_assignable<T>>;
} // namespace detail
@ -594,7 +623,13 @@ template <class T, class E> struct expected_storage_base<T, E, false, true> {
// `T` is `void`, `E` is trivially-destructible
template <class E> struct expected_storage_base<void, E, false, true> {
TL_EXPECTED_MSVC2015_CONSTEXPR expected_storage_base() : m_has_val(true) {}
#if __GNUC__ <= 5
//no constexpr for GCC 4/5 bug
#else
TL_EXPECTED_MSVC2015_CONSTEXPR
#endif
expected_storage_base() : m_has_val(true) {}
constexpr expected_storage_base(no_init_t) : m_val(), m_has_val(false) {}
constexpr expected_storage_base(in_place_t) : m_has_val(true) {}
@ -795,7 +830,7 @@ struct expected_operations_base : expected_storage_base<T, E> {
geterr().~unexpected<E>();
construct(std::move(rhs).get());
} else {
assign_common(rhs);
assign_common(std::move(rhs));
}
}
@ -839,9 +874,7 @@ struct expected_operations_base : expected_storage_base<T, E> {
}
#endif
TL_EXPECTED_11_CONSTEXPR void destroy_val() {
get().~T();
}
TL_EXPECTED_11_CONSTEXPR void destroy_val() { get().~T(); }
};
// This base class provides some handy member functions which can be used in
@ -1220,14 +1253,17 @@ class expected : private detail::expected_move_assign_base<T, E>,
"T must not be in_place_t");
static_assert(!std::is_same<T, std::remove_cv<unexpect_t>::type>::value,
"T must not be unexpect_t");
static_assert(!std::is_same<T, typename std::remove_cv<unexpected<E>>::type>::value,
static_assert(
!std::is_same<T, typename std::remove_cv<unexpected<E>>::type>::value,
"T must not be unexpected<E>");
static_assert(!std::is_reference<E>::value, "E must not be a reference");
T *valptr() { return std::addressof(this->m_val); }
const T *valptr() const { return std::addressof(this->m_val); }
unexpected<E> *errptr() { return std::addressof(this->m_unexpect); }
const unexpected<E> *errptr() const { return std::addressof(this->m_unexpect); }
const unexpected<E> *errptr() const {
return std::addressof(this->m_unexpect);
}
template <class U = T,
detail::enable_if_t<!std::is_void<U>::value> * = nullptr>
@ -1272,24 +1308,26 @@ public:
#else
template <class F>
TL_EXPECTED_11_CONSTEXPR auto
and_then(F &&f) & -> decltype(and_then_impl(std::declval<expected&>(), std::forward<F>(f))) {
and_then(F &&f) & -> decltype(and_then_impl(std::declval<expected &>(),
std::forward<F>(f))) {
return and_then_impl(*this, std::forward<F>(f));
}
template <class F>
TL_EXPECTED_11_CONSTEXPR auto and_then(F &&f) && -> decltype(
and_then_impl(std::declval<expected&&>(), std::forward<F>(f))) {
TL_EXPECTED_11_CONSTEXPR auto
and_then(F &&f) && -> decltype(and_then_impl(std::declval<expected &&>(),
std::forward<F>(f))) {
return and_then_impl(std::move(*this), std::forward<F>(f));
}
template <class F>
constexpr auto and_then(F &&f) const & -> decltype(
and_then_impl(std::declval<expected const&>(), std::forward<F>(f))) {
constexpr auto and_then(F &&f) const & -> decltype(and_then_impl(
std::declval<expected const &>(), std::forward<F>(f))) {
return and_then_impl(*this, std::forward<F>(f));
}
#ifndef TL_EXPECTED_NO_CONSTRR
template <class F>
constexpr auto and_then(F &&f) const && -> decltype(
and_then_impl(std::declval<expected const&&>(), std::forward<F>(f))) {
constexpr auto and_then(F &&f) const && -> decltype(and_then_impl(
std::declval<expected const &&>(), std::forward<F>(f))) {
return and_then_impl(std::move(*this), std::forward<F>(f));
}
#endif
@ -1311,14 +1349,14 @@ public:
}
#else
template <class F>
TL_EXPECTED_11_CONSTEXPR decltype(
expected_map_impl(std::declval<expected &>(), std::declval<F &&>()))
TL_EXPECTED_11_CONSTEXPR decltype(expected_map_impl(
std::declval<expected &>(), std::declval<F &&>()))
map(F &&f) & {
return expected_map_impl(*this, std::forward<F>(f));
}
template <class F>
TL_EXPECTED_11_CONSTEXPR decltype(
expected_map_impl(std::declval<expected>(), std::declval<F &&>()))
TL_EXPECTED_11_CONSTEXPR decltype(expected_map_impl(std::declval<expected>(),
std::declval<F &&>()))
map(F &&f) && {
return expected_map_impl(std::move(*this), std::forward<F>(f));
}
@ -1355,14 +1393,14 @@ public:
}
#else
template <class F>
TL_EXPECTED_11_CONSTEXPR decltype(
expected_map_impl(std::declval<expected &>(), std::declval<F &&>()))
TL_EXPECTED_11_CONSTEXPR decltype(expected_map_impl(
std::declval<expected &>(), std::declval<F &&>()))
transform(F &&f) & {
return expected_map_impl(*this, std::forward<F>(f));
}
template <class F>
TL_EXPECTED_11_CONSTEXPR decltype(
expected_map_impl(std::declval<expected>(), std::declval<F &&>()))
TL_EXPECTED_11_CONSTEXPR decltype(expected_map_impl(std::declval<expected>(),
std::declval<F &&>()))
transform(F &&f) && {
return expected_map_impl(std::move(*this), std::forward<F>(f));
}
@ -1425,6 +1463,49 @@ public:
return map_error_impl(std::move(*this), std::forward<F>(f));
}
#endif
#endif
#if defined(TL_EXPECTED_CXX14) && !defined(TL_EXPECTED_GCC49) && \
!defined(TL_EXPECTED_GCC54) && !defined(TL_EXPECTED_GCC55)
template <class F> TL_EXPECTED_11_CONSTEXPR auto transform_error(F &&f) & {
return map_error_impl(*this, std::forward<F>(f));
}
template <class F> TL_EXPECTED_11_CONSTEXPR auto transform_error(F &&f) && {
return map_error_impl(std::move(*this), std::forward<F>(f));
}
template <class F> constexpr auto transform_error(F &&f) const & {
return map_error_impl(*this, std::forward<F>(f));
}
template <class F> constexpr auto transform_error(F &&f) const && {
return map_error_impl(std::move(*this), std::forward<F>(f));
}
#else
template <class F>
TL_EXPECTED_11_CONSTEXPR decltype(map_error_impl(std::declval<expected &>(),
std::declval<F &&>()))
transform_error(F &&f) & {
return map_error_impl(*this, std::forward<F>(f));
}
template <class F>
TL_EXPECTED_11_CONSTEXPR decltype(map_error_impl(std::declval<expected &&>(),
std::declval<F &&>()))
transform_error(F &&f) && {
return map_error_impl(std::move(*this), std::forward<F>(f));
}
template <class F>
constexpr decltype(map_error_impl(std::declval<const expected &>(),
std::declval<F &&>()))
transform_error(F &&f) const & {
return map_error_impl(*this, std::forward<F>(f));
}
#ifndef TL_EXPECTED_NO_CONSTRR
template <class F>
constexpr decltype(map_error_impl(std::declval<const expected &&>(),
std::declval<F &&>()))
transform_error(F &&f) const && {
return map_error_impl(std::move(*this), std::forward<F>(f));
}
#endif
#endif
template <class F> expected TL_EXPECTED_11_CONSTEXPR or_else(F &&f) & {
return or_else_impl(*this, std::forward<F>(f));
@ -1680,19 +1761,20 @@ public:
T, Args &&...>::value> * = nullptr>
void emplace(Args &&...args) {
if (has_value()) {
val() = T(std::forward<Args>(args)...);
val().~T();
} else {
err().~unexpected<E>();
::new (valptr()) T(std::forward<Args>(args)...);
this->m_has_val = true;
}
::new (valptr()) T(std::forward<Args>(args)...);
}
template <class... Args, detail::enable_if_t<!std::is_nothrow_constructible<
T, Args &&...>::value> * = nullptr>
void emplace(Args &&...args) {
if (has_value()) {
val() = T(std::forward<Args>(args)...);
val().~T();
::new (valptr()) T(std::forward<Args>(args)...);
} else {
auto tmp = std::move(err());
err().~unexpected<E>();
@ -1818,12 +1900,12 @@ private:
void swap_where_only_one_has_value_and_t_is_not_void(
expected &rhs, move_constructing_t_can_throw,
t_is_nothrow_move_constructible) {
e_is_nothrow_move_constructible) {
auto temp = std::move(rhs.err());
rhs.err().~unexpected_type();
#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED
try {
::new (rhs.valptr()) T(val());
::new (rhs.valptr()) T(std::move(val()));
val().~T();
::new (errptr()) unexpected_type(std::move(temp));
std::swap(this->m_has_val, rhs.m_has_val);
@ -1832,7 +1914,7 @@ private:
throw;
}
#else
::new (rhs.valptr()) T(val());
::new (rhs.valptr()) T(std::move(val()));
val().~T();
::new (errptr()) unexpected_type(std::move(temp));
std::swap(this->m_has_val, rhs.m_has_val);
@ -1862,27 +1944,37 @@ public:
}
}
constexpr const T *operator->() const { return valptr(); }
TL_EXPECTED_11_CONSTEXPR T *operator->() { return valptr(); }
constexpr const T *operator->() const {
TL_ASSERT(has_value());
return valptr();
}
TL_EXPECTED_11_CONSTEXPR T *operator->() {
TL_ASSERT(has_value());
return valptr();
}
template <class U = T,
detail::enable_if_t<!std::is_void<U>::value> * = nullptr>
constexpr const U &operator*() const & {
TL_ASSERT(has_value());
return val();
}
template <class U = T,
detail::enable_if_t<!std::is_void<U>::value> * = nullptr>
TL_EXPECTED_11_CONSTEXPR U &operator*() & {
TL_ASSERT(has_value());
return val();
}
template <class U = T,
detail::enable_if_t<!std::is_void<U>::value> * = nullptr>
constexpr const U &&operator*() const && {
TL_ASSERT(has_value());
return std::move(val());
}
template <class U = T,
detail::enable_if_t<!std::is_void<U>::value> * = nullptr>
TL_EXPECTED_11_CONSTEXPR U &&operator*() && {
TL_ASSERT(has_value());
return std::move(val());
}
@ -1918,10 +2010,22 @@ public:
return std::move(val());
}
constexpr const E &error() const & { return err().value(); }
TL_EXPECTED_11_CONSTEXPR E &error() & { return err().value(); }
constexpr const E &&error() const && { return std::move(err().value()); }
TL_EXPECTED_11_CONSTEXPR E &&error() && { return std::move(err().value()); }
constexpr const E &error() const & {
TL_ASSERT(!has_value());
return err().value();
}
TL_EXPECTED_11_CONSTEXPR E &error() & {
TL_ASSERT(!has_value());
return err().value();
}
constexpr const E &&error() const && {
TL_ASSERT(!has_value());
return std::move(err().value());
}
TL_EXPECTED_11_CONSTEXPR E &&error() && {
TL_ASSERT(!has_value());
return std::move(err().value());
}
template <class U> constexpr T value_or(U &&v) const & {
static_assert(std::is_copy_constructible<T>::value &&
@ -2222,9 +2326,9 @@ template <class Exp, class F,
detail::enable_if_t<!std::is_void<Ret>::value> * = nullptr>
constexpr auto or_else_impl(Exp &&exp, F &&f) {
static_assert(detail::is_expected<Ret>::value, "F must return an expected");
return exp.has_value()
? std::forward<Exp>(exp)
: detail::invoke(std::forward<F>(f), std::forward<Exp>(exp).error());
return exp.has_value() ? std::forward<Exp>(exp)
: detail::invoke(std::forward<F>(f),
std::forward<Exp>(exp).error());
}
template <class Exp, class F,
@ -2232,9 +2336,9 @@ template <class Exp, class F,
std::declval<Exp>().error())),
detail::enable_if_t<std::is_void<Ret>::value> * = nullptr>
detail::decay_t<Exp> or_else_impl(Exp &&exp, F &&f) {
return exp.has_value()
? std::forward<Exp>(exp)
: (detail::invoke(std::forward<F>(f), std::forward<Exp>(exp).error()),
return exp.has_value() ? std::forward<Exp>(exp)
: (detail::invoke(std::forward<F>(f),
std::forward<Exp>(exp).error()),
std::forward<Exp>(exp));
}
#else
@ -2244,9 +2348,9 @@ template <class Exp, class F,
detail::enable_if_t<!std::is_void<Ret>::value> * = nullptr>
auto or_else_impl(Exp &&exp, F &&f) -> Ret {
static_assert(detail::is_expected<Ret>::value, "F must return an expected");
return exp.has_value()
? std::forward<Exp>(exp)
: detail::invoke(std::forward<F>(f), std::forward<Exp>(exp).error());
return exp.has_value() ? std::forward<Exp>(exp)
: detail::invoke(std::forward<F>(f),
std::forward<Exp>(exp).error());
}
template <class Exp, class F,
@ -2254,9 +2358,9 @@ template <class Exp, class F,
std::declval<Exp>().error())),
detail::enable_if_t<std::is_void<Ret>::value> * = nullptr>
detail::decay_t<Exp> or_else_impl(Exp &&exp, F &&f) {
return exp.has_value()
? std::forward<Exp>(exp)
: (detail::invoke(std::forward<F>(f), std::forward<Exp>(exp).error()),
return exp.has_value() ? std::forward<Exp>(exp)
: (detail::invoke(std::forward<F>(f),
std::forward<Exp>(exp).error()),
std::forward<Exp>(exp));
}
#endif
@ -2276,6 +2380,20 @@ constexpr bool operator!=(const expected<T, E> &lhs,
? true
: (!lhs.has_value() ? lhs.error() != rhs.error() : *lhs != *rhs);
}
template <class E, class F>
constexpr bool operator==(const expected<void, E> &lhs,
const expected<void, F> &rhs) {
return (lhs.has_value() != rhs.has_value())
? false
: (!lhs.has_value() ? lhs.error() == rhs.error() : true);
}
template <class E, class F>
constexpr bool operator!=(const expected<void, E> &lhs,
const expected<void, F> &rhs) {
return (lhs.has_value() != rhs.has_value())
? true
: (!lhs.has_value() ? lhs.error() == rhs.error() : false);
}
template <class T, class E, class U>
constexpr bool operator==(const expected<T, E> &x, const U &v) {

View File

@ -18,7 +18,7 @@
#define TL_OPTIONAL_HPP
#define TL_OPTIONAL_VERSION_MAJOR 1
#define TL_OPTIONAL_VERSION_MINOR 0
#define TL_OPTIONAL_VERSION_MINOR 1
#define TL_OPTIONAL_VERSION_PATCH 0
#include <exception>
@ -409,7 +409,7 @@ template <class T> struct optional_operations_base : optional_storage_base<T> {
this->m_has_value = false;
}
template <class... Args> void construct(Args &&... args) noexcept {
template <class... Args> void construct(Args &&... args) {
new (std::addressof(this->m_value)) T(std::forward<Args>(args)...);
this->m_has_value = true;
}
@ -742,8 +742,7 @@ public:
static_assert(detail::is_optional<result>::value,
"F must return an optional");
return has_value() ? detail::invoke(std::forward<F>(f), **this)
: result(nullopt);
return has_value() ? detail::invoke(std::forward<F>(f), **this) : result(nullopt);
}
template <class F>
@ -1183,7 +1182,7 @@ public:
}
}
if (rhs.has_value()) {
else if (rhs.has_value()) {
this->construct(*rhs);
}
@ -1205,7 +1204,7 @@ public:
}
}
if (rhs.has_value()) {
else if (rhs.has_value()) {
this->construct(std::move(*rhs));
}
@ -1323,7 +1322,7 @@ public:
static_assert(std::is_move_constructible<T>::value &&
std::is_convertible<U &&, T>::value,
"T must be move constructible and convertible from U");
return has_value() ? **this : static_cast<T>(std::forward<U>(u));
return has_value() ? std::move(**this) : static_cast<T>(std::forward<U>(u));
}
/// Destroys the stored value if one exists, making the optional empty
@ -1646,7 +1645,7 @@ public:
static_assert(detail::is_optional<result>::value,
"F must return an optional");
return has_value() ? detail::invoke(std::forward<F>(f), **this)
return has_value() ? detail::invoke(std::forward<F>(f), std::move(**this))
: result(nullopt);
}
#endif