diff --git a/expected.hpp b/expected.hpp index 002fd49..c1cd6cd 100644 --- a/expected.hpp +++ b/expected.hpp @@ -69,8 +69,7 @@ namespace tl { template class expected; -#ifndef TL_IN_PLACE_MONOSTATE_DEFINED -#define TL_IN_PLACE_MONOSTATE_DEFINED +#ifndef TL_OPTIONAL_EXPECTED_MUTEX /// \brief Used to represent an expected with no data class monostate {}; @@ -157,9 +156,16 @@ static constexpr unexpect_t unexpect{}; /// \exclude namespace detail { +#ifndef TL_OPTIONAL_EXPECTED_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 decay_t = typename std::decay::type; +template +using conditional_t = typename std::conditional::type; // std::conjunction from C++17 template struct conjunction : std::true_type {}; @@ -168,12 +174,6 @@ template struct conjunction : std::conditional, B>::type {}; -// 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>; - // std::invoke from C++17 // https://stackoverflow.com/questions/38288042/c11-14-invoke-workaround template ; 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 enable_forward_value = detail::enable_if_t< +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 enable_from_other = detail::enable_if_t< +using expected_enable_from_other = detail::enable_if_t< std::is_constructible::value && std::is_constructible::value && !std::is_constructible &>::value && @@ -1260,12 +1267,12 @@ public: : impl_base(unexpect, il, std::forward(args)...), ctor_base(detail::default_constructor_tag{}) {} - template < - class U, class G, - detail::enable_if_t::value && - std::is_convertible::value)> * = - nullptr, - detail::enable_from_other * = nullptr> + template ::value && + std::is_convertible::value)> * = + nullptr, + detail::expected_enable_from_other + * = nullptr> explicit TL_EXPECTED_11_CONSTEXPR expected(const expected &rhs) : ctor_base(detail::default_constructor_tag{}) { if (rhs.has_value()) { @@ -1276,12 +1283,12 @@ public: } /// \exclude - template < - class U, class G, - detail::enable_if_t<(std::is_convertible::value && - std::is_convertible::value)> * = - nullptr, - detail::enable_from_other * = nullptr> + template ::value && + std::is_convertible::value)> * = + nullptr, + detail::expected_enable_from_other + * = nullptr> TL_EXPECTED_11_CONSTEXPR expected(const expected &rhs) : ctor_base(detail::default_constructor_tag{}) { if (rhs.has_value()) { @@ -1295,7 +1302,7 @@ public: class U, class G, detail::enable_if_t::value && std::is_convertible::value)> * = nullptr, - detail::enable_from_other * = nullptr> + detail::expected_enable_from_other * = nullptr> explicit TL_EXPECTED_11_CONSTEXPR expected(expected &&rhs) : ctor_base(detail::default_constructor_tag{}) { if (rhs.has_value()) { @@ -1310,7 +1317,7 @@ public: class U, class G, detail::enable_if_t<(std::is_convertible::value && std::is_convertible::value)> * = nullptr, - detail::enable_from_other * = nullptr> + detail::expected_enable_from_other * = nullptr> TL_EXPECTED_11_CONSTEXPR expected(expected &&rhs) : ctor_base(detail::default_constructor_tag{}) { if (rhs.has_value()) { @@ -1323,14 +1330,14 @@ public: template < class U = T, detail::enable_if_t::value> * = nullptr, - detail::enable_forward_value * = nullptr> + detail::expected_enable_forward_value * = nullptr> explicit constexpr expected(U &&v) : expected(in_place, std::forward(v)) {} /// \exclude template < class U = T, detail::enable_if_t::value> * = nullptr, - detail::enable_forward_value * = nullptr> + detail::expected_enable_forward_value * = nullptr> constexpr expected(U &&v) : expected(in_place, std::forward(v)) {} template < @@ -1816,4 +1823,5 @@ void swap(expected &lhs, } } // namespace tl +#define TL_OPTIONAL_EXPECTED_MUTEX #endif