diff --git a/tl/expected.hpp b/tl/expected.hpp
index 2042c51..f22d41b 100644
--- a/tl/expected.hpp
+++ b/tl/expected.hpp
@@ -1,2283 +1,2283 @@
-///
-// expected - An implementation of std::expected with extensions
-// Written in 2017 by Simon Brand (@TartanLlama)
-//
-// To the extent possible under law, the author(s) have dedicated all
-// copyright and related and neighboring rights to this software to the
-// public domain worldwide. This software is distributed without any warranty.
-//
-// You should have received a copy of the CC0 Public Domain Dedication
-// along with this software. If not, see
-// .
-///
-
-#ifndef TL_EXPECTED_HPP
-#define TL_EXPECTED_HPP
-
-#define TL_EXPECTED_VERSION_MAJOR 0
-#define TL_EXPECTED_VERSION_MINOR 2
-
-#include
-#include
-#include
-#include
-
-#if defined(__EXCEPTIONS) || defined(_CPPUNWIND)
-#define TL_EXPECTED_EXCEPTIONS_ENABLED
-#endif
-
-#if (defined(_MSC_VER) && _MSC_VER == 1900)
-/// \exclude
-#define TL_EXPECTED_MSVC2015
-#define TL_EXPECTED_MSVC2015_CONSTEXPR
-#else
-#define TL_EXPECTED_MSVC2015_CONSTEXPR constexpr
-#endif
-
-#if (defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ <= 9 && \
- !defined(__clang__))
-/// \exclude
-#define TL_EXPECTED_GCC49
-#endif
-
-#if (defined(__GNUC__) && __GNUC__ == 5 && __GNUC_MINOR__ <= 4 && \
- !defined(__clang__))
-/// \exclude
-#define TL_EXPECTED_GCC54
-#endif
-
-#if (defined(__GNUC__) && __GNUC__ == 5 && __GNUC_MINOR__ <= 5 && \
- !defined(__clang__))
-/// \exclude
-#define TL_EXPECTED_GCC55
-#endif
-
-#if (defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ <= 9 && \
- !defined(__clang__))
-// GCC < 5 doesn't support overloading on const&& for member functions
-/// \exclude
-#define TL_EXPECTED_NO_CONSTRR
-
-// GCC < 5 doesn't support some standard C++11 type traits
-/// \exclude
-#define TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) \
- std::has_trivial_copy_constructor
-/// \exclude
-#define TL_EXPECTED_IS_TRIVIALLY_COPY_ASSIGNABLE(T) \
- std::has_trivial_copy_assign
-
-// This one will be different for GCC 5.7 if it's ever supported
-/// \exclude
-#define TL_EXPECTED_IS_TRIVIALLY_DESTRUCTIBLE(T) \
- std::is_trivially_destructible
-
-// 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
- struct is_trivially_copy_constructible : std::is_trivially_copy_constructible{};
-#ifdef _GLIBCXX_VECTOR
- template
- struct is_trivially_copy_constructible>
- : std::is_trivially_copy_constructible{};
-#endif
- }
-}
-#endif
-
-#define TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) \
- tl::detail::is_trivially_copy_constructible
-#define TL_EXPECTED_IS_TRIVIALLY_COPY_ASSIGNABLE(T) \
- std::is_trivially_copy_assignable
-#define TL_EXPECTED_IS_TRIVIALLY_DESTRUCTIBLE(T) std::is_trivially_destructible
-#else
-/// \exclude
-#define TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) \
- std::is_trivially_copy_constructible
-/// \exclude
-#define TL_EXPECTED_IS_TRIVIALLY_COPY_ASSIGNABLE(T) \
- std::is_trivially_copy_assignable
-/// \exclude
-#define TL_EXPECTED_IS_TRIVIALLY_DESTRUCTIBLE(T) \
- std::is_trivially_destructible
-#endif
-
-#if __cplusplus > 201103L
-/// \exclude
-#define TL_EXPECTED_CXX14
-#endif
-
-#ifdef TL_EXPECTED_GCC49
-#define TL_EXPECTED_GCC49_CONSTEXPR
-#else
-#define TL_EXPECTED_GCC49_CONSTEXPR constexpr
-#endif
-
-#if (__cplusplus == 201103L || defined(TL_EXPECTED_MSVC2015) || \
- defined(TL_EXPECTED_GCC49))
-/// \exclude
-#define TL_EXPECTED_11_CONSTEXPR
-#else
-/// \exclude
-#define TL_EXPECTED_11_CONSTEXPR constexpr
-#endif
-
-namespace tl {
-template class expected;
-
-#ifndef TL_MONOSTATE_INPLACE_MUTEX
-#define TL_MONOSTATE_INPLACE_MUTEX
-/// \brief Used to represent an expected with no data
-class monostate {};
-
-/// \brief A tag type to tell expected to construct its value in-place
-struct in_place_t {
- explicit in_place_t() = default;
-};
-/// \brief A tag to tell expected to construct its value in-place
-static constexpr in_place_t in_place{};
-#endif
-
-/// Used as a wrapper to store the unexpected value
-template class unexpected {
-public:
- static_assert(!std::is_same::value, "E must not be void");
-
- unexpected() = delete;
- constexpr explicit unexpected(const E &e) : m_val(e) {}
-
- constexpr explicit unexpected(E &&e) : m_val(std::move(e)) {}
-
- /// \returns the contained value
- /// \group unexpected_value
- constexpr const E &value() const & { return m_val; }
- /// \group unexpected_value
- TL_EXPECTED_11_CONSTEXPR E &value() & { return m_val; }
- /// \group unexpected_value
- TL_EXPECTED_11_CONSTEXPR E &&value() && { return std::move(m_val); }
- /// \exclude
- constexpr const E &&value() const && { return std::move(m_val); }
-
-private:
- E m_val;
-};
-
-/// \brief Compares two unexpected objects
-/// \details Simply compares lhs.value() to rhs.value()
-/// \group unexpected_relop
-template
-constexpr bool operator==(const unexpected &lhs, const unexpected &rhs) {
- return lhs.value() == rhs.value();
-}
-/// \group unexpected_relop
-template
-constexpr bool operator!=(const unexpected &lhs, const unexpected &rhs) {
- return lhs.value() != rhs.value();
-}
-/// \group unexpected_relop
-template
-constexpr bool operator<(const unexpected &lhs, const unexpected &rhs) {
- return lhs.value() < rhs.value();
-}
-/// \group unexpected_relop
-template
-constexpr bool operator<=(const unexpected &lhs, const unexpected &rhs) {
- return lhs.value() <= rhs.value();
-}
-/// \group unexpected_relop
-template
-constexpr bool operator>(const unexpected &lhs, const unexpected &rhs) {
- return lhs.value() > rhs.value();
-}
-/// \group unexpected_relop
-template
-constexpr bool operator>=(const unexpected &lhs, const unexpected &rhs) {
- return lhs.value() >= rhs.value();
-}
-
-/// Create an `unexpected` from `e`, deducing the return type
-///
-/// *Example:*
-/// auto e1 = tl::make_unexpected(42);
-/// unexpected e2 (42); //same semantics
-template
-unexpected::type> make_unexpected(E &&e) {
- return unexpected::type>(std::forward(e));
-}
-
-/// \brief A tag type to tell expected to construct the unexpected value
-struct unexpect_t {
- unexpect_t() = default;
-};
-/// \brief A tag to tell expected to construct the unexpected value
-static constexpr unexpect_t unexpect{};
-
-/// \exclude
-namespace detail {
-template
-[[noreturn]] TL_EXPECTED_11_CONSTEXPR void throw_exception(E &&e) {
-#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED
- throw std::forward(e);
-#else
- (void)e;
- #ifdef _MSC_VER
- __assume(0);
- #else
- __builtin_unreachable();
- #endif
-#endif
-}
-
-#ifndef TL_TRAITS_MUTEX
-#define TL_TRAITS_MUTEX
-// C++14-style aliases for brevity
-template using remove_const_t = typename std::remove_const::type;
-template
-using remove_reference_t = typename std::remove_reference::type;
-template using decay_t = typename std::decay::type;
-template
-using enable_if_t = typename std::enable_if::type;
-template
-using conditional_t = typename std::conditional::type;
-
-// std::conjunction from C++17
-template struct conjunction : std::true_type {};
-template struct conjunction : B {};
-template
-struct conjunction
- : std::conditional, B>::type {};
-
-// std::invoke from C++17
-// https://stackoverflow.com/questions/38288042/c11-14-invoke-workaround
-template >{}>,
- int = 0>
-constexpr auto invoke(Fn &&f, Args &&... args) noexcept(
- noexcept(std::mem_fn(f)(std::forward(args)...)))
- -> decltype(std::mem_fn(f)(std::forward(args)...)) {
- return std::mem_fn(f)(std::forward(args)...);
-}
-
-template >{}>>
-constexpr auto invoke(Fn &&f, Args &&... args) noexcept(
- noexcept(std::forward(f)(std::forward(args)...)))
- -> decltype(std::forward(f)(std::forward(args)...)) {
- return std::forward(f)(std::forward(args)...);
-}
-
-// std::invoke_result from C++17
-template struct invoke_result_impl;
-
-template
-struct invoke_result_impl<
- F, decltype(detail::invoke(std::declval(), std::declval()...), void()),
- Us...> {
- using type = decltype(detail::invoke(std::declval(), std::declval()...));
-};
-
-template
-using invoke_result = invoke_result_impl;
-
-template
-using invoke_result_t = typename invoke_result::type;
-#endif
-
-// Trait for checking if a type is a tl::expected
-template struct is_expected_impl : std::false_type {};
-template
-struct is_expected_impl> : std::true_type {};
-template using is_expected = is_expected_impl>;
-
-template
-using expected_enable_forward_value = detail::enable_if_t<
- std::is_constructible::value &&
- !std::is_same, in_place_t>::value &&
- !std::is_same, detail::decay_t>::value &&
- !std::is_same, detail::decay_t>::value>;
-
-template
-using expected_enable_from_other = detail::enable_if_t<
- std::is_constructible::value &&
- std::is_constructible::value &&
- !std::is_constructible &>::value &&
- !std::is_constructible &&>::value &&
- !std::is_constructible &>::value &&
- !std::is_constructible &&>::value &&
- !std::is_convertible &, T>::value &&
- !std::is_convertible &&, T>::value &&
- !std::is_convertible &, T>::value &&
- !std::is_convertible &&, T>::value>;
-
-template
-using is_void_or = conditional_t::value, std::true_type, U>;
-
-template
-using is_copy_constructible_or_void =
- is_void_or>;
-
-template
-using is_move_constructible_or_void =
- is_void_or>;
-
-template
-using is_copy_assignable_or_void =
- is_void_or>;
-
-
-template
-using is_move_assignable_or_void =
- is_void_or>;
-
-
-} // namespace detail
-
-/// \exclude
-namespace detail {
-struct no_init_t {};
-static constexpr no_init_t no_init{};
-
-// Implements the storage of the values, and ensures that the destructor is
-// trivial if it can be.
-//
-// This specialization is for where neither `T` or `E` is trivially
-// destructible, so the destructors must be called on destruction of the
-// `expected`
-template ::value,
- bool = std::is_trivially_destructible::value>
-struct expected_storage_base {
- constexpr expected_storage_base() : m_val(T{}), m_has_val(true) {}
- constexpr expected_storage_base(no_init_t) : m_no_init(), m_has_val(false) {}
-
- template ::value> * =
- nullptr>
- constexpr expected_storage_base(in_place_t, Args &&... args)
- : m_val(std::forward(args)...), m_has_val(true) {}
-
- template &, Args &&...>::value> * = nullptr>
- constexpr expected_storage_base(in_place_t, std::initializer_list il,
- Args &&... args)
- : m_val(il, std::forward(args)...), m_has_val(true) {}
- template ::value> * =
- nullptr>
- constexpr explicit expected_storage_base(unexpect_t, Args &&... args)
- : m_unexpect(std::forward(args)...), m_has_val(false) {}
-
- template &, Args &&...>::value> * = nullptr>
- constexpr explicit expected_storage_base(unexpect_t,
- std::initializer_list il,
- Args &&... args)
- : m_unexpect(il, std::forward(args)...), m_has_val(false) {}
-
- ~expected_storage_base() {
- if (m_has_val) {
- m_val.~T();
- } else {
- m_unexpect.~unexpected();
- }
- }
- union {
- char m_no_init;
- T m_val;
- unexpected m_unexpect;
- };
- bool m_has_val;
-};
-
-// This specialization is for when both `T` and `E` are trivially-destructible,
-// so the destructor of the `expected` can be trivial.
-template struct expected_storage_base {
- constexpr expected_storage_base() : m_val(T{}), m_has_val(true) {}
- constexpr expected_storage_base(no_init_t) : m_no_init(), m_has_val(false) {}
-
- template ::value> * =
- nullptr>
- constexpr expected_storage_base(in_place_t, Args &&... args)
- : m_val(std::forward(args)...), m_has_val(true) {}
-
- template &, Args &&...>::value> * = nullptr>
- constexpr expected_storage_base(in_place_t, std::initializer_list il,
- Args &&... args)
- : m_val(il, std::forward(args)...), m_has_val(true) {}
- template ::value> * =
- nullptr>
- constexpr explicit expected_storage_base(unexpect_t, Args &&... args)
- : m_unexpect(std::forward(args)...), m_has_val(false) {}
-
- template &, Args &&...>::value> * = nullptr>
- constexpr explicit expected_storage_base(unexpect_t,
- std::initializer_list il,
- Args &&... args)
- : m_unexpect(il, std::forward(args)...), m_has_val(false) {}
-
- ~expected_storage_base() = default;
- union {
- char m_no_init;
- T m_val;
- unexpected m_unexpect;
- };
- bool m_has_val;
-};
-
-// T is trivial, E is not.
-template struct expected_storage_base {
- constexpr expected_storage_base() : m_val(T{}), m_has_val(true) {}
- TL_EXPECTED_MSVC2015_CONSTEXPR expected_storage_base(no_init_t)
- : m_no_init(), m_has_val(false) {}
-
- template ::value> * =
- nullptr>
- constexpr expected_storage_base(in_place_t, Args &&... args)
- : m_val(std::forward(args)...), m_has_val(true) {}
-
- template &, Args &&...>::value> * = nullptr>
- constexpr expected_storage_base(in_place_t, std::initializer_list il,
- Args &&... args)
- : m_val(il, std::forward(args)...), m_has_val(true) {}
- template ::value> * =
- nullptr>
- constexpr explicit expected_storage_base(unexpect_t, Args &&... args)
- : m_unexpect(std::forward(args)...), m_has_val(false) {}
-
- template &, Args &&...>::value> * = nullptr>
- constexpr explicit expected_storage_base(unexpect_t,
- std::initializer_list il,
- Args &&... args)
- : m_unexpect(il, std::forward(args)...), m_has_val(false) {}
-
- ~expected_storage_base() {
- if (!m_has_val) {
- m_unexpect.~unexpected();
- }
- }
-
- union {
- char m_no_init;
- T m_val;
- unexpected m_unexpect;
- };
- bool m_has_val;
-};
-
-// E is trivial, T is not.
-template struct expected_storage_base {
- constexpr expected_storage_base() : m_val(T{}), m_has_val(true) {}
- constexpr expected_storage_base(no_init_t) : m_no_init(), m_has_val(false) {}
-
- template ::value> * =
- nullptr>
- constexpr expected_storage_base(in_place_t, Args &&... args)
- : m_val(std::forward(args)...), m_has_val(true) {}
-
- template &, Args &&...>::value> * = nullptr>
- constexpr expected_storage_base(in_place_t, std::initializer_list il,
- Args &&... args)
- : m_val(il, std::forward(args)...), m_has_val(true) {}
- template ::value> * =
- nullptr>
- constexpr explicit expected_storage_base(unexpect_t, Args &&... args)
- : m_unexpect(std::forward(args)...), m_has_val(false) {}
-
- template &, Args &&...>::value> * = nullptr>
- constexpr explicit expected_storage_base(unexpect_t,
- std::initializer_list il,
- Args &&... args)
- : m_unexpect(il, std::forward(args)...), m_has_val(false) {}
-
- ~expected_storage_base() {
- if (m_has_val) {
- m_val.~T();
- }
- }
- union {
- char m_no_init;
- T m_val;
- unexpected m_unexpect;
- };
- bool m_has_val;
-};
-
-// `T` is `void`, `E` is trivially-destructible
-template struct expected_storage_base {
- TL_EXPECTED_MSVC2015_CONSTEXPR 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) {}
-
- template ::value> * =
- nullptr>
- constexpr explicit expected_storage_base(unexpect_t, Args &&... args)
- : m_unexpect(std::forward(args)...), m_has_val(false) {}
-
- template &, Args &&...>::value> * = nullptr>
- constexpr explicit expected_storage_base(unexpect_t,
- std::initializer_list il,
- Args &&... args)
- : m_unexpect(il, std::forward(args)...), m_has_val(false) {}
-
- ~expected_storage_base() = default;
- struct dummy {};
- union {
- dummy m_val;
- unexpected m_unexpect;
- };
- bool m_has_val;
-};
-
-// `T` is `void`, `E` is not trivially-destructible
-template struct expected_storage_base {
- constexpr expected_storage_base() : m_dummy(), m_has_val(true) {}
- constexpr expected_storage_base(no_init_t) : m_dummy(), m_has_val(false) {}
-
- constexpr expected_storage_base(in_place_t) : m_dummy(), m_has_val(true) {}
-
- template ::value> * =
- nullptr>
- constexpr explicit expected_storage_base(unexpect_t, Args &&... args)
- : m_unexpect(std::forward(args)...), m_has_val(false) {}
-
- template &, Args &&...>::value> * = nullptr>
- constexpr explicit expected_storage_base(unexpect_t,
- std::initializer_list il,
- Args &&... args)
- : m_unexpect(il, std::forward(args)...), m_has_val(false) {}
-
- ~expected_storage_base() {
- if (!m_has_val) {
- m_unexpect.~unexpected();
- }
- }
-
- union {
- char m_dummy;
- unexpected m_unexpect;
- };
- bool m_has_val;
-};
-
-// This base class provides some handy member functions which can be used in
-// further derived classes
-template
-struct expected_operations_base : expected_storage_base {
- using expected_storage_base::expected_storage_base;
-
- template void construct(Args &&... args) noexcept {
- new (std::addressof(this->m_val)) T(std::forward(args)...);
- this->m_has_val = true;
- }
-
- template void construct_with(Rhs &&rhs) noexcept {
- new (std::addressof(this->m_val)) T(std::forward(rhs).get());
- this->m_has_val = true;
- }
-
- template void construct_error(Args &&... args) noexcept {
- new (std::addressof(this->m_unexpect))
- unexpected(std::forward(args)...);
- this->m_has_val = false;
- }
-
- #ifdef TL_EXPECTED_EXCEPTIONS_ENABLED
-
- // These assign overloads ensure that the most efficient assignment
- // implementation is used while maintaining the strong exception guarantee.
- // The problematic case is where rhs has a value, but *this does not.
- //
- // This overload handles the case where we can just copy-construct `T`
- // directly into place without throwing.
- template ::value>
- * = nullptr>
- void assign(const expected_operations_base &rhs) noexcept {
- if (!this->m_has_val && rhs.m_has_val) {
- geterr().~unexpected();
- construct(rhs.get());
- } else {
- assign_common(rhs);
- }
- }
-
- // This overload handles the case where we can attempt to create a copy of
- // `T`, then no-throw move it into place if the copy was successful.
- template ::value &&
- std::is_nothrow_move_constructible::value>
- * = nullptr>
- void assign(const expected_operations_base &rhs) noexcept {
- if (!this->m_has_val && rhs.m_has_val) {
- T tmp = rhs.get();
- geterr().~unexpected();
- construct(std::move(tmp));
- } else {
- assign_common(rhs);
- }
- }
-
- // This overload is the worst-case, where we have to move-construct the
- // unexpected value into temporary storage, then try to copy the T into place.
- // If the construction succeeds, then everything is fine, but if it throws,
- // then we move the old unexpected value back into place before rethrowing the
- // exception.
- template ::value &&
- !std::is_nothrow_move_constructible::value>
- * = nullptr>
- void assign(const expected_operations_base &rhs) {
- if (!this->m_has_val && rhs.m_has_val) {
- auto tmp = std::move(geterr());
- geterr().~unexpected();
-
- try {
- construct(rhs.get());
- } catch (...) {
- geterr() = std::move(tmp);
- throw;
- }
- } else {
- assign_common(rhs);
- }
- }
-
- // These overloads do the same as above, but for rvalues
- template ::value>
- * = nullptr>
- void assign(expected_operations_base &&rhs) noexcept {
- if (!this->m_has_val && rhs.m_has_val) {
- geterr().~unexpected();
- construct(std::move(rhs).get());
- } else {
- assign_common(std::move(rhs));
- }
- }
-
- template ::value>
- * = nullptr>
- void assign(expected_operations_base &&rhs) {
- if (!this->m_has_val && rhs.m_has_val) {
- auto tmp = std::move(geterr());
- geterr().~unexpected();
- try {
- construct(std::move(rhs).get());
- } catch (...) {
- geterr() = std::move(tmp);
- throw;
- }
- } else {
- assign_common(std::move(rhs));
- }
- }
-
- #else
-
- // If exceptions are disabled then we can just copy-construct
- void assign(const expected_operations_base &rhs) noexcept {
- if (!this->m_has_val && rhs.m_has_val) {
- geterr().~unexpected();
- construct(rhs.get());
- } else {
- assign_common(rhs);
- }
- }
-
- void assign(expected_operations_base &&rhs) noexcept {
- if (!this->m_has_val && rhs.m_has_val) {
- geterr().~unexpected();
- construct(std::move(rhs).get());
- } else {
- assign_common(rhs);
- }
- }
-
- #endif
-
- // The common part of move/copy assigning
- template void assign_common(Rhs &&rhs) {
- if (this->m_has_val) {
- if (rhs.m_has_val) {
- get() = std::forward(rhs).get();
- } else {
- destroy_val();
- construct_error(std::forward(rhs).geterr());
- }
- } else {
- if (!rhs.m_has_val) {
- geterr() = std::forward(rhs).geterr();
- }
- }
- }
-
- bool has_value() const { return this->m_has_val; }
-
- TL_EXPECTED_11_CONSTEXPR T &get() & { return this->m_val; }
- constexpr const T &get() const & { return this->m_val; }
- TL_EXPECTED_11_CONSTEXPR T &&get() && { return std::move(this->m_val); }
-#ifndef TL_EXPECTED_NO_CONSTRR
- constexpr const T &&get() const && { return std::move(this->m_val); }
-#endif
-
- TL_EXPECTED_11_CONSTEXPR unexpected &geterr() & {
- return this->m_unexpect;
- }
- constexpr const unexpected &geterr() const & { return this->m_unexpect; }
- TL_EXPECTED_11_CONSTEXPR unexpected &&geterr() && {
- return std::move(this->m_unexpect);
- }
-#ifndef TL_EXPECTED_NO_CONSTRR
- constexpr const unexpected &&geterr() const && {
- return std::move(this->m_unexpect);
- }
-#endif
-
- constexpr void destroy_val() {
- get().~T();
- }
-};
-
-// This base class provides some handy member functions which can be used in
-// further derived classes
-template
-struct expected_operations_base : expected_storage_base {
- using expected_storage_base::expected_storage_base;
-
- template void construct() noexcept { this->m_has_val = true; }
-
- // This function doesn't use its argument, but needs it so that code in
- // levels above this can work independently of whether T is void
- template void construct_with(Rhs &&) noexcept {
- this->m_has_val = true;
- }
-
- template void construct_error(Args &&... args) noexcept {
- new (std::addressof(this->m_unexpect))
- unexpected(std::forward(args)...);
- this->m_has_val = false;
- }
-
- template void assign(Rhs &&rhs) noexcept {
- if (!this->m_has_val) {
- if (rhs.m_has_val) {
- geterr().~unexpected();
- construct();
- } else {
- geterr() = std::forward(rhs).geterr();
- }
- } else {
- if (!rhs.m_has_val) {
- construct_error(std::forward(rhs).geterr());
- }
- }
- }
-
- bool has_value() const { return this->m_has_val; }
-
- TL_EXPECTED_11_CONSTEXPR unexpected &geterr() & {
- return this->m_unexpect;
- }
- constexpr const unexpected &geterr() const & { return this->m_unexpect; }
- TL_EXPECTED_11_CONSTEXPR unexpected &&geterr() && {
- return std::move(this->m_unexpect);
- }
-#ifndef TL_EXPECTED_NO_CONSTRR
- constexpr const unexpected &&geterr() const && {
- return std::move(this->m_unexpect);
- }
-#endif
-
- constexpr void destroy_val() {
- //no-op
- }
-};
-
-// This class manages conditionally having a trivial copy constructor
-// This specialization is for when T and E are trivially copy constructible
-template ::
- value &&TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(E)::value>
-struct expected_copy_base : expected_operations_base {
- using expected_operations_base::expected_operations_base;
-};
-
-// This specialization is for when T or E are not trivially copy constructible
-template
-struct expected_copy_base : expected_operations_base {
- using expected_operations_base::expected_operations_base;
-
- expected_copy_base() = default;
- expected_copy_base(const expected_copy_base &rhs)
- : expected_operations_base(no_init) {
- if (rhs.has_value()) {
- this->construct_with(rhs);
- } else {
- this->construct_error(rhs.geterr());
- }
- }
-
- expected_copy_base(expected_copy_base &&rhs) = default;
- expected_copy_base &operator=(const expected_copy_base &rhs) = default;
- expected_copy_base &operator=(expected_copy_base &&rhs) = default;
-};
-
-// This class manages conditionally having a trivial move constructor
-// Unfortunately there's no way to achieve this in GCC < 5 AFAIK, since it
-// doesn't implement an analogue to std::is_trivially_move_constructible. We
-// have to make do with a non-trivial move constructor even if T is trivially
-// move constructible
-#ifndef TL_EXPECTED_GCC49
-template >::value
- &&std::is_trivially_move_constructible::value>
-struct expected_move_base : expected_copy_base {
- using expected_copy_base::expected_copy_base;
-};
-#else
-template struct expected_move_base;
-#endif
-template
-struct expected_move_base : expected_copy_base {
- using expected_copy_base::expected_copy_base;
-
- expected_move_base() = default;
- expected_move_base(const expected_move_base &rhs) = default;
-
- expected_move_base(expected_move_base &&rhs) noexcept(
- std::is_nothrow_move_constructible::value)
- : expected_copy_base