16#ifndef TL_EXPECTED_HPP
17#define TL_EXPECTED_HPP
19#define TL_EXPECTED_VERSION_MAJOR 1
20#define TL_EXPECTED_VERSION_MINOR 3
21#define TL_EXPECTED_VERSION_PATCH 1
28#if defined(__EXCEPTIONS) || defined(_CPPUNWIND)
29#define TL_EXPECTED_EXCEPTIONS_ENABLED
32#if (defined(_MSC_VER) && _MSC_VER == 1900)
33#define TL_EXPECTED_MSVC2015
34#define TL_EXPECTED_MSVC2015_CONSTEXPR
36#define TL_EXPECTED_MSVC2015_CONSTEXPR constexpr
39#if (defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ <= 9 && \
41#define TL_EXPECTED_GCC49
44#if (defined(__GNUC__) && __GNUC__ == 5 && __GNUC_MINOR__ <= 4 && \
46#define TL_EXPECTED_GCC54
49#if (defined(__GNUC__) && __GNUC__ == 5 && __GNUC_MINOR__ <= 5 && \
51#define TL_EXPECTED_GCC55
55#define TL_CPLUSPLUS _MSVC_LANG
57#define TL_CPLUSPLUS __cplusplus
60#if !defined(TL_ASSERT)
62#if (TL_CPLUSPLUS > 201103L) && !defined(TL_EXPECTED_GCC49)
64#define TL_ASSERT(x) assert(x)
70#if (defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ <= 9 && \
74#define TL_EXPECTED_NO_CONSTRR
76#define TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) \
77 std::has_trivial_copy_constructor<T>
78#define TL_EXPECTED_IS_TRIVIALLY_COPY_ASSIGNABLE(T) \
79 std::has_trivial_copy_assign<T>
82#define TL_EXPECTED_IS_TRIVIALLY_DESTRUCTIBLE(T) \
83 std::is_trivially_destructible<T>
87#elif (defined(__GNUC__) && __GNUC__ < 8 && !defined(__clang__))
88#ifndef TL_GCC_LESS_8_TRIVIALLY_COPY_CONSTRUCTIBLE_MUTEX
89#define TL_GCC_LESS_8_TRIVIALLY_COPY_CONSTRUCTIBLE_MUTEX
93struct is_trivially_copy_constructible
94 : std::is_trivially_copy_constructible<T> {};
96template <
class T,
class A>
97struct is_trivially_copy_constructible<
std::vector<T, A>> : std::false_type {};
103#define TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) \
104 tl::detail::is_trivially_copy_constructible<T>
105#define TL_EXPECTED_IS_TRIVIALLY_COPY_ASSIGNABLE(T) \
106 std::is_trivially_copy_assignable<T>
107#define TL_EXPECTED_IS_TRIVIALLY_DESTRUCTIBLE(T) \
108 std::is_trivially_destructible<T>
110#define TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) \
111 std::is_trivially_copy_constructible<T>
112#define TL_EXPECTED_IS_TRIVIALLY_COPY_ASSIGNABLE(T) \
113 std::is_trivially_copy_assignable<T>
114#define TL_EXPECTED_IS_TRIVIALLY_DESTRUCTIBLE(T) \
115 std::is_trivially_destructible<T>
118#if TL_CPLUSPLUS > 201103L
119#define TL_EXPECTED_CXX14
122#ifdef TL_EXPECTED_GCC49
123#define TL_EXPECTED_GCC49_CONSTEXPR
125#define TL_EXPECTED_GCC49_CONSTEXPR constexpr
128#if (TL_CPLUSPLUS == 201103L || defined(TL_EXPECTED_MSVC2015) || \
129 defined(TL_EXPECTED_GCC49))
130#define TL_EXPECTED_11_CONSTEXPR
132#define TL_EXPECTED_11_CONSTEXPR constexpr
135#if TL_CPLUSPLUS >= 201703L
136#define TL_EXPECTED_NODISCARD [[nodiscard]]
138#define TL_EXPECTED_NODISCARD
144#ifndef TL_MONOSTATE_INPLACE_MUTEX
145#define TL_MONOSTATE_INPLACE_MUTEX
156 static_assert(!std::is_same<E, void>::value,
"E must not be void");
163 template <
class... Args,
typename std::enable_if<std::is_constructible<
164 E, Args &&...>
::value>::type * =
nullptr>
166 : m_val(
std::forward<Args>(args)...) {}
168 class U,
class... Args,
169 typename std::enable_if<std::is_constructible<
170 E, std::initializer_list<U> &, Args &&...>
::value>::type * =
nullptr>
171 constexpr explicit unexpected(std::initializer_list<U> l, Args &&...args)
172 : m_val(l,
std::forward<Args>(args)...) {}
174 constexpr const E &
value() const & {
return m_val; }
177 constexpr const E &&
value() const && {
return std::move(m_val); }
183#ifdef __cpp_deduction_guides
184template <
class E> unexpected(E) -> unexpected<E>;
222#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED
223#define TL_EXPECTED_THROW_EXCEPTION(e) throw((e));
225#define TL_EXPECTED_THROW_EXCEPTION(e) std::terminate();
229#ifndef TL_TRAITS_MUTEX
230#define TL_TRAITS_MUTEX
235template <
class T>
using decay_t =
typename std::decay<T>::type;
236template <
bool E,
class T =
void>
238template <
bool B,
class T,
class F>
244template <
class B,
class... Bs>
246 : std::conditional<bool(B::value), conjunction<Bs...>, B>::type {};
248#if defined(_LIBCPP_VERSION) && __cplusplus == 201103L
249#define TL_TRAITS_LIBCXX_MEM_FN_WORKAROUND
255#ifdef TL_TRAITS_LIBCXX_MEM_FN_WORKAROUND
257struct is_pointer_to_non_const_member_func : std::false_type {};
258template <
class T,
class Ret,
class... Args>
259struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...)>
261template <
class T,
class Ret,
class... Args>
262struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...) &>
264template <
class T,
class Ret,
class... Args>
265struct is_pointer_to_non_const_member_func<Ret (
T::*)(Args...) &&>
267template <
class T,
class Ret,
class... Args>
268struct is_pointer_to_non_const_member_func<Ret (
T::*)(Args...) volatile>
270template <
class T,
class Ret,
class... Args>
271struct is_pointer_to_non_const_member_func<Ret (
T::*)(Args...) volatile &>
273template <
class T,
class Ret,
class... Args>
274struct is_pointer_to_non_const_member_func<Ret (
T::*)(Args...) volatile &&>
277template <
class T>
struct is_const_or_const_ref : std::false_type {};
278template <
class T>
struct is_const_or_const_ref<
T const &> : std::true_type {};
279template <
class T>
struct is_const_or_const_ref<
T const> : std::true_type {};
285 typename Fn,
typename... Args,
286#ifdef TL_TRAITS_LIBCXX_MEM_FN_WORKAROUND
287 typename =
enable_if_t<!(is_pointer_to_non_const_member_func<Fn>::value &&
288 is_const_or_const_ref<Args...>::value)>,
291constexpr auto invoke(Fn &&f, Args &&...args)
noexcept(
292 noexcept(std::mem_fn(f)(std::forward<Args>(args)...)))
293 ->
decltype(std::mem_fn(f)(std::forward<Args>(args)...)) {
294 return std::mem_fn(f)(std::forward<Args>(args)...);
297template <
typename Fn,
typename... Args,
299constexpr auto invoke(Fn &&f, Args &&...args)
noexcept(
300 noexcept(std::forward<Fn>(f)(std::forward<Args>(args)...)))
301 ->
decltype(std::forward<Fn>(f)(std::forward<Args>(args)...)) {
302 return std::forward<Fn>(f)(std::forward<Args>(args)...);
308template <
class F,
class... Us>
311 decltype(
detail::
invoke(std::declval<F>(), std::declval<Us>()...), void()),
314 decltype(
detail::invoke(std::declval<F>(), std::declval<Us>()...));
317template <
class F,
class... Us>
320template <
class F,
class... Us>
323#if defined(_MSC_VER) && _MSC_VER <= 1900
325template <
class T,
class U = T>
struct is_swappable : std::true_type {};
327template <
class T,
class U = T>
struct is_nothrow_swappable : std::true_type {};
336template <
class T, std::
size_t N>
tag swap(T (&a)[N], T (&b)[N]);
340template <
class,
class> std::false_type
can_swap(...) noexcept(false);
341template <class T, class U,
342 class = decltype(
swap(
std::declval<T &>(),
std::declval<U &>()))>
344 std::declval<U &>())));
347template <class T, class U>
353 :
std::integral_constant<
bool,
354 std::is_nothrow_move_constructible<T>::value &&
355 std::is_nothrow_move_assignable<T>::value> {};
357template <
class T, std::
size_t N>
360template <
class T,
class U>
362 : std::integral_constant<bool, noexcept(can_swap<T, U>(0))> {};
365template <
class T,
class U = T>
367 : std::integral_constant<
369 decltype(detail::swap_adl_tests::can_swap<T, U>(0))::value &&
370 (!decltype(detail::swap_adl_tests::uses_std<T, U>(0))::value ||
371 (std::is_move_assignable<T>::value &&
372 std::is_move_constructible<T>::value))> {};
374template <
class T, std::
size_t N>
376 : std::integral_constant<
378 decltype(detail::swap_adl_tests::can_swap<T[N], T[N]>(0))::value &&
379 (!decltype(detail::swap_adl_tests::uses_std<T[N], T[N]>(
381 is_swappable<T, T>::value)> {};
383template <
class T,
class U = T>
385 : std::integral_constant<
387 is_swappable<T, U>::value &&
388 ((decltype(detail::swap_adl_tests::uses_std<T, U>(0))::value &&
389 detail::swap_adl_tests::is_std_swap_noexcept<T>::value) ||
390 (!decltype(detail::swap_adl_tests::uses_std<T, U>(0))::value &&
391 detail::swap_adl_tests::is_adl_swap_noexcept<T, U>::value))> {};
397template <
class T,
class E>
401template <
class T,
class E,
class U>
403 std::is_constructible<T, U &&>::value &&
404 !std::is_same<detail::decay_t<U>,
in_place_t>::value &&
408template <
class T,
class E,
class U,
class G,
class UR,
class GR>
410 std::is_constructible<T, UR>::value &&
411 std::is_constructible<E, GR>::value &&
412 !std::is_constructible<T, expected<U, G> &>::value &&
413 !std::is_constructible<T, expected<U, G> &&>::value &&
414 !std::is_constructible<T, const expected<U, G> &>::value &&
415 !std::is_constructible<T, const expected<U, G> &&>::value &&
416 !std::is_convertible<expected<U, G> &, T>::value &&
417 !std::is_convertible<expected<U, G> &&, T>::value &&
418 !std::is_convertible<const expected<U, G> &, T>::value &&
419 !std::is_convertible<const expected<U, G> &&, T>::value>;
421template <
class T,
class U>
450template <class T, class E, bool = std::is_trivially_destructible<T>::value,
451 bool = std::is_trivially_destructible<E>::value>
456 template <
class... Args,
462 template <
class U,
class... Args,
464 T, std::initializer_list<U> &, Args &&...>::value> * =
nullptr>
468 template <
class... Args,
474 template <
class U,
class... Args,
476 E, std::initializer_list<U> &, Args &&...>::value> * =
nullptr>
478 std::initializer_list<U> il,
503 template <
class... Args,
509 template <
class U,
class... Args,
511 T, std::initializer_list<U> &, Args &&...>::value> * =
nullptr>
515 template <
class... Args,
521 template <
class U,
class... Args,
523 E, std::initializer_list<U> &, Args &&...>::value> * =
nullptr>
525 std::initializer_list<U> il,
548 template <
class... Args,
554 template <
class U,
class... Args,
556 T, std::initializer_list<U> &, Args &&...>::value> * =
nullptr>
560 template <
class... Args,
566 template <
class U,
class... Args,
568 E, std::initializer_list<U> &, Args &&...>::value> * =
nullptr>
570 std::initializer_list<U> il,
597 template <
class... Args,
603 template <
class U,
class... Args,
605 T, std::initializer_list<U> &, Args &&...>::value> * =
nullptr>
609 template <
class... Args,
615 template <
class U,
class... Args,
617 E, std::initializer_list<U> &, Args &&...>::value> * =
nullptr>
619 std::initializer_list<U> il,
653 template <
class... Args,
659 template <
class U,
class... Args,
661 E, std::initializer_list<U> &, Args &&...>::value> * =
nullptr>
663 std::initializer_list<U> il,
687 template <
class... Args,
693 template <
class U,
class... Args,
695 E, std::initializer_list<U> &, Args &&...>::value> * =
nullptr>
697 std::initializer_list<U> il,
720template <
class T,
class E>
724 template <
class... Args>
void construct(Args &&...args)
noexcept {
725 new (std::addressof(this->
m_val)) T(std::forward<Args>(args)...);
730 new (std::addressof(this->
m_val)) T(std::forward<Rhs>(rhs).
get());
740#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED
748 template <
class U = T,
752 if (!this->m_has_val && rhs.m_has_val) {
753 geterr().~unexpected<E>();
754 construct(rhs.get());
762 template <
class U =
T,
763 detail::enable_if_t<!std::is_nothrow_copy_constructible<U>::value &&
764 std::is_nothrow_move_constructible<U>::value>
767 if (!this->m_has_val && rhs.m_has_val) {
769 geterr().~unexpected<
E>();
770 construct(std::move(tmp));
781 template <
class U =
T,
782 detail::enable_if_t<!std::is_nothrow_copy_constructible<U>::value &&
783 !std::is_nothrow_move_constructible<U>::value>
786 if (!this->m_has_val && rhs.m_has_val) {
787 auto tmp = std::move(geterr());
788 geterr().~unexpected<
E>();
790#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED
792 construct(rhs.get());
794 geterr() = std::move(tmp);
798 construct(rhs.get());
806 template <
class U =
T,
807 detail::enable_if_t<std::is_nothrow_move_constructible<U>::value>
810 if (!this->m_has_val && rhs.m_has_val) {
811 geterr().~unexpected<
E>();
812 construct(std::move(rhs).get());
814 assign_common(std::move(rhs));
818 template <
class U =
T,
819 detail::enable_if_t<!std::is_nothrow_move_constructible<U>::value>
822 if (!this->m_has_val && rhs.m_has_val) {
823 auto tmp = std::move(geterr());
824 geterr().~unexpected<
E>();
825#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED
827 construct(std::move(rhs).get());
829 geterr() = std::move(tmp);
833 construct(std::move(rhs).get());
836 assign_common(std::move(rhs));
845 geterr().~unexpected<E>();
854 geterr().~unexpected<E>();
867 get() = std::forward<Rhs>(rhs).get();
873 if (!rhs.m_has_val) {
874 geterr() = std::forward<Rhs>(rhs).geterr();
882 constexpr const T &
get() const & {
return this->
m_val; }
884#ifndef TL_EXPECTED_NO_CONSTRR
885 constexpr const T &&
get() const && {
return std::move(this->
m_val); }
895#ifndef TL_EXPECTED_NO_CONSTRR
924 template <
class Rhs>
void assign(Rhs &&rhs)
noexcept {
927 geterr().~unexpected<E>();
930 geterr() = std::forward<Rhs>(rhs).geterr();
933 if (!rhs.m_has_val) {
948#ifndef TL_EXPECTED_NO_CONSTRR
961template <
class T,
class E,
965 std::is_copy_constructible<E>::value)>
971template <
class T,
class E>
979 this->construct_with(rhs);
981 this->construct_error(rhs.geterr());
995#ifndef TL_EXPECTED_GCC49
996template <
class T,
class E,
998 &&std::is_trivially_move_constructible<E>::value>
1005template <
class T,
class E>
1013 std::is_nothrow_move_constructible<T>::value)
1015 if (rhs.has_value()) {
1016 this->construct_with(std::move(rhs));
1018 this->construct_error(std::move(rhs.geterr()));
1026template <
class T,
class E,
1035 std::is_copy_constructible<E>::value &&
1037 std::is_copy_assignable<E>::value)>
1042template <
class T,
class E>
1063#ifndef TL_EXPECTED_GCC49
1064template <
class T,
class E,
1067 std::is_trivially_move_constructible<T>,
1068 std::is_trivially_move_assignable<T>>>::
1069 value &&std::is_trivially_destructible<E>::value
1070 &&std::is_trivially_move_constructible<E>::value
1071 &&std::is_trivially_move_assignable<E>::value>
1079template <
class T,
class E>
1094 std::is_nothrow_move_constructible<T>::value
1095 &&std::is_nothrow_move_assignable<T>::value) {
1096 this->
assign(std::move(rhs));
1103template <
class T,
class E,
1104 bool EnableCopy = (is_copy_constructible_or_void<T>::value &&
1105 std::is_copy_constructible<E>::value),
1106 bool EnableMove = (is_move_constructible_or_void<T>::value &&
1107 std::is_move_constructible<E>::value)>
1118template <class T, class E>
1129template <class T, class E>
1140template <class T, class E>
1154template <class T, class E,
1156 std::is_copy_constructible<E>::value &&
1158 std::is_copy_assignable<E>::value),
1160 std::is_move_constructible<E>::value &&
1162 std::is_move_assignable<E>::value)>
1174template <class T, class E>
1186template <class T, class E>
1198template <class T, class E>
1219template <
class T,
class E,
1221 std::is_default_constructible<T>::value || std::is_void<T>::value>
1256 virtual const char *
what() const noexcept
override {
1257 return "Bad expected access";
1260 const E &
error() const & {
return m_val; }
1262 const E &&
error() const && {
return std::move(m_val); }
1263 E &&
error() && {
return std::move(m_val); }
1276template <
class T,
class E>
1282 static_assert(!std::is_reference<T>::value,
"T must not be a reference");
1283 static_assert(!std::is_same<T, std::remove_cv<in_place_t>::type>
::value,
1284 "T must not be in_place_t");
1285 static_assert(!std::is_same<T, std::remove_cv<unexpect_t>::type>
::value,
1286 "T must not be unexpect_t");
1288 !std::is_same<T, typename std::remove_cv<unexpected<E>>::type>
::value,
1289 "T must not be unexpected<E>");
1290 static_assert(!std::is_reference<E>::value,
"E must not be a reference");
1292 T *valptr() {
return std::addressof(this->
m_val); }
1293 const T *valptr()
const {
return std::addressof(this->
m_val); }
1299 template <
class U = T,
1306 template <
class U = T,
1308 constexpr const U &val()
const {
1321#if defined(TL_EXPECTED_CXX14) && !defined(TL_EXPECTED_GCC49) && \
1322 !defined(TL_EXPECTED_GCC54) && !defined(TL_EXPECTED_GCC55)
1324 return and_then_impl(*
this, std::forward<F>(f));
1327 return and_then_impl(std::move(*
this), std::forward<F>(f));
1329 template <
class F>
constexpr auto and_then(F &&f)
const & {
1330 return and_then_impl(*
this, std::forward<F>(f));
1333#ifndef TL_EXPECTED_NO_CONSTRR
1334 template <
class F>
constexpr auto and_then(F &&f)
const && {
1342 and_then(F &&f) & ->
decltype(and_then_impl(std::declval<expected &>(),
1343 std::forward<F>(f))) {
1344 return and_then_impl(*
this, std::forward<F>(f));
1348 and_then(F &&f) && ->
decltype(and_then_impl(std::declval<expected &&>(),
1349 std::forward<F>(f))) {
1350 return and_then_impl(std::move(*
this), std::forward<F>(f));
1353 constexpr auto and_then(F &&f)
const & ->
decltype(and_then_impl(
1354 std::declval<expected const &>(), std::forward<F>(f))) {
1355 return and_then_impl(*
this, std::forward<F>(f));
1358#ifndef TL_EXPECTED_NO_CONSTRR
1360 constexpr auto and_then(F &&f)
const && ->
decltype(and_then_impl(
1361 std::declval<expected const &&>(), std::forward<F>(f))) {
1362 return and_then_impl(std::move(*
this), std::forward<F>(f));
1367#if defined(TL_EXPECTED_CXX14) && !defined(TL_EXPECTED_GCC49) && \
1368 !defined(TL_EXPECTED_GCC54) && !defined(TL_EXPECTED_GCC55)
1370 return expected_map_impl(*
this, std::forward<F>(f));
1373 return expected_map_impl(std::move(*
this), std::forward<F>(f));
1375 template <
class F>
constexpr auto map(F &&f)
const & {
1378 template <
class F>
constexpr auto map(F &&f)
const && {
1384 std::declval<expected &>(), std::declval<F &&>()))
1386 return expected_map_impl(*
this, std::forward<F>(f));
1390 std::declval<F &&>()))
1392 return expected_map_impl(std::move(*
this), std::forward<F>(f));
1395 constexpr decltype(expected_map_impl(std::declval<const expected &>(),
1396 std::declval<F &&>()))
1398 return expected_map_impl(*
this, std::forward<F>(f));
1401#ifndef TL_EXPECTED_NO_CONSTRR
1403 constexpr decltype(expected_map_impl(std::declval<const expected &&>(),
1404 std::declval<F &&>()))
1406 return expected_map_impl(std::move(*
this), std::forward<F>(f));
1411#if defined(TL_EXPECTED_CXX14) && !defined(TL_EXPECTED_GCC49) && \
1412 !defined(TL_EXPECTED_GCC54) && !defined(TL_EXPECTED_GCC55)
1414 return expected_map_impl(*
this, std::forward<F>(f));
1417 return expected_map_impl(std::move(*
this), std::forward<F>(f));
1419 template <
class F>
constexpr auto transform(F &&f)
const & {
1422 template <
class F>
constexpr auto transform(F &&f)
const && {
1428 std::declval<expected &>(), std::declval<F &&>()))
1430 return expected_map_impl(*
this, std::forward<F>(f));
1434 std::declval<F &&>()))
1436 return expected_map_impl(std::move(*
this), std::forward<F>(f));
1439 constexpr decltype(expected_map_impl(std::declval<const expected &>(),
1440 std::declval<F &&>()))
1442 return expected_map_impl(*
this, std::forward<F>(f));
1445#ifndef TL_EXPECTED_NO_CONSTRR
1447 constexpr decltype(expected_map_impl(std::declval<const expected &&>(),
1448 std::declval<F &&>()))
1450 return expected_map_impl(std::move(*
this), std::forward<F>(f));
1455#if defined(TL_EXPECTED_CXX14) && !defined(TL_EXPECTED_GCC49) && \
1456 !defined(TL_EXPECTED_GCC54) && !defined(TL_EXPECTED_GCC55)
1458 return map_error_impl(*
this, std::forward<F>(f));
1461 return map_error_impl(std::move(*
this), std::forward<F>(f));
1463 template <
class F>
constexpr auto map_error(F &&f)
const & {
1466 template <
class F>
constexpr auto map_error(F &&f)
const && {
1472 std::declval<F &&>()))
1474 return map_error_impl(*
this, std::forward<F>(f));
1478 std::declval<F &&>()))
1480 return map_error_impl(std::move(*
this), std::forward<F>(f));
1483 constexpr decltype(map_error_impl(std::declval<const expected &>(),
1484 std::declval<F &&>()))
1486 return map_error_impl(*
this, std::forward<F>(f));
1489#ifndef TL_EXPECTED_NO_CONSTRR
1491 constexpr decltype(map_error_impl(std::declval<const expected &&>(),
1492 std::declval<F &&>()))
1494 return map_error_impl(std::move(*
this), std::forward<F>(f));
1498#if defined(TL_EXPECTED_CXX14) && !defined(TL_EXPECTED_GCC49) && \
1499 !defined(TL_EXPECTED_GCC54) && !defined(TL_EXPECTED_GCC55)
1501 return map_error_impl(*
this, std::forward<F>(f));
1504 return map_error_impl(std::move(*
this), std::forward<F>(f));
1506 template <
class F>
constexpr auto transform_error(F &&f)
const & {
1509 template <
class F>
constexpr auto transform_error(F &&f)
const && {
1515 std::declval<F &&>()))
1517 return map_error_impl(*
this, std::forward<F>(f));
1521 std::declval<F &&>()))
1523 return map_error_impl(std::move(*
this), std::forward<F>(f));
1526 constexpr decltype(map_error_impl(std::declval<const expected &>(),
1527 std::declval<F &&>()))
1529 return map_error_impl(*
this, std::forward<F>(f));
1532#ifndef TL_EXPECTED_NO_CONSTRR
1534 constexpr decltype(map_error_impl(std::declval<const expected &&>(),
1535 std::declval<F &&>()))
1537 return map_error_impl(std::move(*
this), std::forward<F>(f));
1542 return or_else_impl(*
this, std::forward<F>(f));
1546 return or_else_impl(std::move(*
this), std::forward<F>(f));
1550 return or_else_impl(*
this, std::forward<F>(f));
1553#ifndef TL_EXPECTED_NO_CONSTRR
1555 return or_else_impl(std::move(*
this), std::forward<F>(f));
1564 template <
class... Args,
1568 : impl_base(in_place,
std::forward<Args>(args)...),
1569 ctor_base(
detail::default_constructor_tag{}) {}
1571 template <
class U,
class... Args,
1573 T, std::initializer_list<U> &, Args &&...>::value> * =
nullptr>
1575 : impl_base(in_place, il,
std::forward<Args>(args)...),
1576 ctor_base(
detail::default_constructor_tag{}) {}
1578 template <
class G = E,
1584 : impl_base(unexpect, e.
value()),
1585 ctor_base(
detail::default_constructor_tag{}) {}
1593 : impl_base(unexpect, e.
value()),
1594 ctor_base(
detail::default_constructor_tag{}) {}
1601 std::is_nothrow_constructible<E, G &&>::value)
1602 : impl_base(unexpect,
std::move(e.
value())),
1603 ctor_base(
detail::default_constructor_tag{}) {}
1610 std::is_nothrow_constructible<E, G &&>::value)
1611 : impl_base(unexpect,
std::move(e.
value())),
1612 ctor_base(
detail::default_constructor_tag{}) {}
1614 template <
class... Args,
1618 : impl_base(unexpect,
std::forward<Args>(args)...),
1619 ctor_base(
detail::default_constructor_tag{}) {}
1621 template <
class U,
class... Args,
1623 E, std::initializer_list<U> &, Args &&...>::value> * =
nullptr>
1626 : impl_base(unexpect, il,
std::forward<Args>(args)...),
1627 ctor_base(
detail::default_constructor_tag{}) {}
1629 template <
class U,
class G,
1631 std::is_convertible<G const &, E>::value)> * =
1636 : ctor_base(
detail::default_constructor_tag{}) {
1638 this->construct(*rhs);
1640 this->construct_error(rhs.error());
1644 template <
class U,
class G,
1646 std::is_convertible<G const &, E>::value)> * =
1651 : ctor_base(
detail::default_constructor_tag{}) {
1653 this->construct(*rhs);
1655 this->construct_error(rhs.error());
1662 std::is_convertible<G &&, E>::value)> * =
nullptr,
1665 : ctor_base(
detail::default_constructor_tag{}) {
1666 if (rhs.has_value()) {
1667 this->construct(std::move(*rhs));
1669 this->construct_error(std::move(rhs.error()));
1676 std::is_convertible<G &&, E>::value)> * =
nullptr,
1679 : ctor_base(
detail::default_constructor_tag{}) {
1680 if (rhs.has_value()) {
1681 this->construct(std::move(*rhs));
1683 this->construct_error(std::move(rhs.error()));
1702 class U = T,
class G = T,
1709 std::is_same<T, detail::decay_t<U>>>::value &&
1710 std::is_constructible<T, U>::value &&
1711 std::is_assignable<G &, U>::value &&
1712 std::is_nothrow_move_constructible<E>::value)> * =
nullptr>
1715 val() = std::forward<U>(v);
1717 err().~unexpected<E>();
1718 ::new (valptr()) T(std::forward<U>(v));
1726 class U = T,
class G = T,
1733 std::is_same<T, detail::decay_t<U>>>::value &&
1734 std::is_constructible<T, U>::value &&
1735 std::is_assignable<G &, U>::value &&
1736 std::is_nothrow_move_constructible<E>::value)> * =
nullptr>
1739 val() = std::forward<U>(v);
1741 auto tmp = std::move(err());
1742 err().~unexpected<E>();
1744#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED
1746 ::new (valptr()) T(std::forward<U>(v));
1749 err() = std::move(tmp);
1753 ::new (valptr()) T(std::forward<U>(v));
1761 template <
class G = E,
1763 std::is_assignable<G &, G>::value> * =
nullptr>
1776 template <
class G = E,
1778 std::is_move_assignable<G>::value> * =
nullptr>
1781 err() = std::move(rhs);
1792 T, Args &&...>::value> * =
nullptr>
1797 err().~unexpected<E>();
1800 ::new (valptr()) T(std::forward<Args>(args)...);
1804 T, Args &&...>::value> * =
nullptr>
1808 ::new (valptr()) T(std::forward<Args>(args)...);
1810 auto tmp = std::move(err());
1811 err().~unexpected<E>();
1813#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED
1815 ::new (valptr()) T(std::forward<Args>(args)...);
1818 err() = std::move(tmp);
1822 ::new (valptr()) T(std::forward<Args>(args)...);
1828 template <
class U,
class... Args,
1830 T, std::initializer_list<U> &, Args &&...>::value> * =
nullptr>
1831 void emplace(std::initializer_list<U> il, Args &&...args) {
1833 T t(il, std::forward<Args>(args)...);
1834 val() = std::move(t);
1836 err().~unexpected<E>();
1837 ::new (valptr()) T(il, std::forward<Args>(args)...);
1842 template <
class U,
class... Args,
1844 T, std::initializer_list<U> &, Args &&...>::value> * =
nullptr>
1845 void emplace(std::initializer_list<U> il, Args &&...args) {
1847 T t(il, std::forward<Args>(args)...);
1848 val() = std::move(t);
1850 auto tmp = std::move(err());
1851 err().~unexpected<E>();
1853#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED
1855 ::new (valptr()) T(il, std::forward<Args>(args)...);
1858 err() = std::move(tmp);
1862 ::new (valptr()) T(il, std::forward<Args>(args)...);
1869 using t_is_void = std::true_type;
1870 using t_is_not_void = std::false_type;
1871 using t_is_nothrow_move_constructible = std::true_type;
1872 using move_constructing_t_can_throw = std::false_type;
1873 using e_is_nothrow_move_constructible = std::true_type;
1874 using move_constructing_e_can_throw = std::false_type;
1876 void swap_where_both_have_value(
expected & , t_is_void)
noexcept {
1880 void swap_where_both_have_value(expected &rhs, t_is_not_void) {
1882 swap(val(), rhs.val());
1885 void swap_where_only_one_has_value(expected &rhs, t_is_void)
noexcept(
1886 std::is_nothrow_move_constructible<E>::value) {
1887 ::new (errptr()) unexpected_type(std::move(rhs.err()));
1888 rhs.err().~unexpected_type();
1889 std::swap(this->m_has_val, rhs.m_has_val);
1892 void swap_where_only_one_has_value(expected &rhs, t_is_not_void) {
1893 swap_where_only_one_has_value_and_t_is_not_void(
1894 rhs,
typename std::is_nothrow_move_constructible<T>::type{},
1895 typename std::is_nothrow_move_constructible<E>::type{});
1898 void swap_where_only_one_has_value_and_t_is_not_void(
1899 expected &rhs, t_is_nothrow_move_constructible,
1900 e_is_nothrow_move_constructible)
noexcept {
1901 auto temp = std::move(val());
1903 ::new (errptr()) unexpected_type(std::move(rhs.err()));
1904 rhs.err().~unexpected_type();
1905 ::new (rhs.valptr()) T(std::move(temp));
1906 std::swap(this->m_has_val, rhs.m_has_val);
1909 void swap_where_only_one_has_value_and_t_is_not_void(
1910 expected &rhs, t_is_nothrow_move_constructible,
1911 move_constructing_e_can_throw) {
1912 auto temp = std::move(val());
1914#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED
1916 ::new (errptr()) unexpected_type(std::move(rhs.err()));
1917 rhs.err().~unexpected_type();
1918 ::new (rhs.valptr()) T(std::move(temp));
1919 std::swap(this->m_has_val, rhs.m_has_val);
1921 val() = std::move(temp);
1925 ::new (errptr()) unexpected_type(std::move(rhs.err()));
1926 rhs.err().~unexpected_type();
1927 ::new (rhs.valptr()) T(std::move(temp));
1928 std::swap(this->m_has_val, rhs.m_has_val);
1932 void swap_where_only_one_has_value_and_t_is_not_void(
1933 expected &rhs, move_constructing_t_can_throw,
1934 e_is_nothrow_move_constructible) {
1935 auto temp = std::move(rhs.err());
1936 rhs.err().~unexpected_type();
1937#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED
1939 ::new (rhs.valptr()) T(std::move(val()));
1941 ::new (errptr()) unexpected_type(std::move(temp));
1942 std::swap(this->m_has_val, rhs.m_has_val);
1944 rhs.err() = std::move(temp);
1948 ::new (rhs.valptr()) T(std::move(val()));
1950 ::new (errptr()) unexpected_type(std::move(temp));
1951 std::swap(this->m_has_val, rhs.m_has_val);
1956 template <
class OT = T,
class OE = E>
1957 detail::enable_if_t<detail::is_swappable<OT>::value &&
1958 detail::is_swappable<OE>::value &&
1959 (std::is_nothrow_move_constructible<OT>::value ||
1960 std::is_nothrow_move_constructible<OE>::value)>
1962 std::is_nothrow_move_constructible<T>::value
1964 &&std::is_nothrow_move_constructible<E>::value
1967 swap_where_both_have_value(rhs,
typename std::is_void<T>::type{});
1968 }
else if (!
has_value() && rhs.has_value()) {
1971 swap_where_only_one_has_value(rhs,
typename std::is_void<T>::type{});
1974 swap(err(), rhs.err());
1987 template <
class U = T,
1993 template <
class U = T,
1999 template <
class U = T,
2003 return std::move(val());
2005 template <
class U = T,
2009 return std::move(val());
2012 constexpr bool has_value() const noexcept {
return this->m_has_val; }
2013 constexpr explicit operator bool() const noexcept {
return this->m_has_val; }
2015 template <
class U = T,
2022 template <
class U = T,
2029 template <
class U = T,
2034 return std::move(val());
2036 template <
class U = T,
2041 return std::move(val());
2046 return err().value();
2050 return err().value();
2054 return std::move(err().
value());
2058 return std::move(err().
value());
2061 template <
class U>
constexpr T
value_or(U &&v)
const & {
2062 static_assert(std::is_copy_constructible<T>::value &&
2063 std::is_convertible<U &&, T>::value,
2064 "T must be copy-constructible and convertible to from U&&");
2065 return bool(*
this) ? **this :
static_cast<T
>(std::forward<U>(v));
2068 static_assert(std::is_move_constructible<T>::value &&
2069 std::is_convertible<U &&, T>::value,
2070 "T must be move-constructible and convertible to from U&&");
2071 return bool(*
this) ? std::move(**
this) :
static_cast<T
>(std::forward<U>(v));
2080#ifdef TL_EXPECTED_CXX14
2081template <
class Exp,
class F,
2084 *std::declval<Exp>()))>
2088 return exp.has_value()
2090 : Ret(unexpect, std::forward<Exp>(exp).error());
2093template <
class Exp,
class F,
2096constexpr auto and_then_impl(Exp &&exp, F &&f) {
2100 : Ret(unexpect,
std::forward<Exp>(exp).error());
2103template <
class>
struct TC;
2104template <
class Exp,
class F,
2106 *std::declval<Exp>())),
2111 return exp.has_value()
2113 : Ret(unexpect, std::forward<Exp>(exp).error());
2116template <
class Exp,
class F,
2123 : Ret(unexpect, std::forward<Exp>(exp).error());
2127#ifdef TL_EXPECTED_CXX14
2128template <
class Exp,
class F,
2131 *std::declval<Exp>())),
2133constexpr auto expected_map_impl(Exp &&exp, F &&f) {
2134 using result = ret_t<Exp, detail::decay_t<Ret>>;
2135 return exp.has_value() ? result(
detail::invoke(std::forward<F>(f),
2136 *std::forward<Exp>(exp)))
2137 : result(unexpect,
std::forward<Exp>(exp).error());
2140template <
class Exp,
class F,
2141 detail::enable_if_t<!std::is_void<exp_t<Exp>>::value> * =
nullptr,
2142 class Ret =
decltype(detail::invoke(std::declval<F>(),
2143 *std::declval<Exp>())),
2144 detail::enable_if_t<std::is_void<Ret>::value> * =
nullptr>
2145auto expected_map_impl(Exp &&exp, F &&f) {
2146 using result = expected<void, err_t<Exp>>;
2147 if (exp.has_value()) {
2148 detail::invoke(std::forward<F>(f), *std::forward<Exp>(exp));
2152 return result(unexpect, std::forward<Exp>(exp).error());
2155template <
class Exp,
class F,
2156 detail::enable_if_t<std::is_void<exp_t<Exp>>::value> * =
nullptr,
2157 class Ret =
decltype(detail::invoke(std::declval<F>())),
2158 detail::enable_if_t<!std::is_void<Ret>::value> * =
nullptr>
2160 using result = ret_t<Exp, detail::decay_t<Ret>>;
2161 return exp.has_value() ? result(detail::invoke(std::forward<F>(f)))
2162 : result(unexpect, std::forward<Exp>(exp).error());
2165template <
class Exp,
class F,
2166 detail::enable_if_t<std::is_void<exp_t<Exp>>::value> * =
nullptr,
2167 class Ret =
decltype(detail::invoke(std::declval<F>())),
2168 detail::enable_if_t<std::is_void<Ret>::value> * =
nullptr>
2170 using result = expected<void, err_t<Exp>>;
2171 if (exp.has_value()) {
2172 detail::invoke(std::forward<F>(f));
2176 return result(unexpect, std::forward<Exp>(exp).error());
2179template <
class Exp,
class F,
2180 detail::enable_if_t<!std::is_void<exp_t<Exp>>::value> * =
nullptr,
2181 class Ret =
decltype(detail::invoke(std::declval<F>(),
2182 *std::declval<Exp>())),
2183 detail::enable_if_t<!std::is_void<Ret>::value> * =
nullptr>
2189 return exp.has_value() ? result(
detail::invoke(std::forward<F>(f),
2190 *std::forward<Exp>(exp)))
2191 : result(unexpect, std::forward<Exp>(exp).error());
2194template <
class Exp,
class F,
2197 *std::declval<Exp>())),
2201 if (exp.has_value()) {
2209template <
class Exp,
class F,
2218 return exp.has_value() ? result(
detail::invoke(std::forward<F>(f)))
2219 : result(unexpect, std::forward<Exp>(exp).error());
2222template <
class Exp,
class F,
2228 if (exp.has_value()) {
2237#if defined(TL_EXPECTED_CXX14) && !defined(TL_EXPECTED_GCC49) && \
2238 !defined(TL_EXPECTED_GCC54) && !defined(TL_EXPECTED_GCC55)
2239template <
class Exp,
class F,
2242 std::declval<Exp>().error())),
2244constexpr auto map_error_impl(Exp &&exp, F &&f) {
2246 return exp.has_value()
2247 ? result(*std::forward<Exp>(exp))
2248 : result(unexpect,
detail::invoke(
std::forward<F>(f),
2249 std::forward<Exp>(exp).error()));
2251template <
class Exp,
class F,
2252 detail::enable_if_t<!std::is_void<exp_t<Exp>>::value> * =
nullptr,
2253 class Ret =
decltype(detail::invoke(std::declval<F>(),
2254 std::declval<Exp>().error())),
2255 detail::enable_if_t<std::is_void<Ret>::value> * =
nullptr>
2256auto map_error_impl(Exp &&exp, F &&f) {
2257 using result = expected<exp_t<Exp>, monostate>;
2258 if (exp.has_value()) {
2259 return result(*std::forward<Exp>(exp));
2262 detail::invoke(std::forward<F>(f), std::forward<Exp>(exp).error());
2263 return result(unexpect, monostate{});
2265template <
class Exp,
class F,
2266 detail::enable_if_t<std::is_void<exp_t<Exp>>::value> * =
nullptr,
2267 class Ret =
decltype(detail::invoke(std::declval<F>(),
2268 std::declval<Exp>().error())),
2269 detail::enable_if_t<!std::is_void<Ret>::value> * =
nullptr>
2271 using result = expected<exp_t<Exp>, detail::decay_t<Ret>>;
2274 : result(unexpect, detail::
invoke(std::forward<
F>(f),
2275 std::forward<Exp>(exp).error()));
2277template <
class Exp,
class F,
2278 detail::enable_if_t<std::is_void<exp_t<Exp>>::value> * =
nullptr,
2279 class Ret =
decltype(detail::invoke(std::declval<F>(),
2280 std::declval<Exp>().error())),
2281 detail::enable_if_t<std::is_void<Ret>::value> * =
nullptr>
2283 using result = expected<exp_t<Exp>, monostate>;
2284 if (exp.has_value()) {
2288 detail::invoke(std::forward<F>(f), std::forward<Exp>(exp).error());
2289 return result(unexpect, monostate{});
2292template <
class Exp,
class F,
2293 detail::enable_if_t<!std::is_void<exp_t<Exp>>::value> * =
nullptr,
2294 class Ret =
decltype(detail::invoke(std::declval<F>(),
2295 std::declval<Exp>().error())),
2296 detail::enable_if_t<!std::is_void<Ret>::value> * =
nullptr>
2301 return exp.has_value()
2302 ? result(*std::forward<Exp>(exp))
2304 std::forward<Exp>(exp).error()));
2307template <
class Exp,
class F,
2310 std::declval<Exp>().error())),
2314 if (exp.has_value()) {
2315 return result(*std::forward<Exp>(exp));
2318 detail::invoke(std::forward<F>(f), std::forward<Exp>(exp).error());
2322template <
class Exp,
class F,
2325 std::declval<Exp>().error())),
2331 return exp.has_value()
2334 std::forward<Exp>(exp).error()));
2337template <
class Exp,
class F,
2340 std::declval<Exp>().error())),
2344 if (exp.has_value()) {
2348 detail::invoke(std::forward<F>(f), std::forward<Exp>(exp).error());
2353#ifdef TL_EXPECTED_CXX14
2354template <
class Exp,
class F,
2356 std::declval<Exp>().error())),
2358constexpr auto or_else_impl(Exp &&exp, F &&f) {
2360 return exp.has_value() ? std::forward<Exp>(exp)
2362 std::forward<Exp>(exp).error());
2365template <
class Exp,
class F,
2366 class Ret =
decltype(detail::invoke(std::declval<F>(),
2367 std::declval<Exp>().error())),
2368 detail::enable_if_t<std::is_void<Ret>::value> * =
nullptr>
2369detail::decay_t<Exp> or_else_impl(Exp &&exp, F &&f) {
2370 return exp.has_value() ? std::forward<Exp>(exp)
2371 : (detail::invoke(
std::forward<F>(f),
2372 std::forward<Exp>(exp).error()),
2373 std::forward<Exp>(exp));
2376template <
class Exp,
class F,
2377 class Ret =
decltype(detail::invoke(std::declval<F>(),
2378 std::declval<Exp>().error())),
2379 detail::enable_if_t<!std::is_void<Ret>::value> * =
nullptr>
2382 return exp.has_value() ? std::forward<Exp>(exp)
2384 std::forward<Exp>(exp).error());
2387template <
class Exp,
class F,
2389 std::declval<Exp>().error())),
2392 return exp.has_value() ? std::forward<Exp>(exp)
2394 std::forward<Exp>(exp).error()),
2395 std::forward<Exp>(exp));
2400template <
class T,
class E,
class U,
class F>
2407template <
class T,
class E,
class U,
class F>
2414template <
class E,
class F>
2421template <
class E,
class F>
2429template <
class T,
class E,
class U>
2433template <
class T,
class E,
class U>
2437template <
class T,
class E,
class U>
2441template <
class T,
class E,
class U>
2446template <
class T,
class E>
2450template <
class T,
class E>
2454template <
class T,
class E>
2458template <
class T,
class E>
2463template <
class T,
class E,
2464 detail::enable_if_t<(std::is_void<T>::value ||
2465 std::is_move_constructible<T>::value) &&
2466 detail::is_swappable<T>::value &&
2467 std::is_move_constructible<E>::value &&
2468 detail::is_swappable<E>::value> * =
nullptr>
Definition expected.hpp:1252
bad_expected_access(E e)
Definition expected.hpp:1254
E & error() &
Definition expected.hpp:1261
virtual const char * what() const noexcept override
Definition expected.hpp:1256
const E & error() const &
Definition expected.hpp:1260
E && error() &&
Definition expected.hpp:1263
const E && error() const &&
Definition expected.hpp:1262
An expected<T, E> object is an object that contains the storage for another object and manages the li...
Definition expected.hpp:1281
constexpr T * operator->()
Definition expected.hpp:1982
constexpr U & operator*() &
Definition expected.hpp:1995
constexpr T value_or(U &&v) &&
Definition expected.hpp:2067
constexpr expected(const unexpected< G > &e)
Definition expected.hpp:1583
expected & operator=(const expected &rhs)=default
constexpr T value_or(U &&v) const &
Definition expected.hpp:2061
constexpr decltype(map_error_impl(std::declval< expected & >(), std::declval< F && >())) transform_error(F &&f) &
Definition expected.hpp:1516
constexpr decltype(map_error_impl(std::declval< const expected && >(), std::declval< F && >())) transform_error(F &&f) const &&
Definition expected.hpp:1536
constexpr auto and_then(F &&f) const &&-> decltype(and_then_impl(std::declval< expected const && >(), std::forward< F >(f)))
Definition expected.hpp:1360
constexpr const E && error() const &&
Definition expected.hpp:2052
constexpr U && operator*() &&
Definition expected.hpp:2007
constexpr decltype(expected_map_impl(std::declval< const expected && >(), std::declval< F && >())) transform(F &&f) const &&
Definition expected.hpp:1449
constexpr expected(expected< U, G > &&rhs)
Definition expected.hpp:1664
void emplace(std::initializer_list< U > il, Args &&...args)
Definition expected.hpp:1831
constexpr expected(const expected &rhs)=default
constexpr decltype(expected_map_impl(std::declval< expected >(), std::declval< F && >())) map(F &&f) &&
Definition expected.hpp:1391
constexpr decltype(expected_map_impl(std::declval< expected & >(), std::declval< F && >())) map(F &&f) &
Definition expected.hpp:1385
constexpr decltype(expected_map_impl(std::declval< expected >(), std::declval< F && >())) transform(F &&f) &&
Definition expected.hpp:1435
constexpr const E & error() const &
Definition expected.hpp:2044
constexpr const U && value() const &&
Definition expected.hpp:2031
constexpr bool has_value() const noexcept
Definition expected.hpp:2012
constexpr expected()=default
constexpr auto and_then(F &&f) const &-> decltype(and_then_impl(std::declval< expected const & >(), std::forward< F >(f)))
Definition expected.hpp:1353
constexpr expected(unexpected< G > &&e) noexcept(std::is_nothrow_constructible< E, G && >::value)
Definition expected.hpp:1600
constexpr expected(unexpect_t, Args &&...args)
Definition expected.hpp:1617
constexpr decltype(map_error_impl(std::declval< expected && >(), std::declval< F && >())) map_error(F &&f) &&
Definition expected.hpp:1479
constexpr const T * operator->() const
Definition expected.hpp:1978
constexpr decltype(expected_map_impl(std::declval< expected & >(), std::declval< F && >())) transform(F &&f) &
Definition expected.hpp:1429
constexpr decltype(expected_map_impl(std::declval< const expected & >(), std::declval< F && >())) transform(F &&f) const &
Definition expected.hpp:1441
constexpr const U & value() const &
Definition expected.hpp:2017
constexpr E & error() &
Definition expected.hpp:2048
constexpr expected(unexpected< G > const &e)
Definition expected.hpp:1592
constexpr expected(U &&v)
Definition expected.hpp:1691
expected & operator=(const unexpected< G > &rhs)
Definition expected.hpp:1764
constexpr auto and_then(F &&f) &&-> decltype(and_then_impl(std::declval< expected && >(), std::forward< F >(f)))
Definition expected.hpp:1348
detail::enable_if_t< detail::is_swappable< OT >::value &&detail::is_swappable< OE >::value &&(std::is_nothrow_move_constructible< OT >::value||std::is_nothrow_move_constructible< OE >::value)> swap(expected &rhs) noexcept(std::is_nothrow_move_constructible< T >::value &&detail::is_nothrow_swappable< T >::value &&std::is_nothrow_move_constructible< E >::value &&detail::is_nothrow_swappable< E >::value)
Definition expected.hpp:1961
void emplace(Args &&...args)
Definition expected.hpp:1793
constexpr auto and_then(F &&f) &-> decltype(and_then_impl(std::declval< expected & >(), std::forward< F >(f)))
Definition expected.hpp:1342
constexpr decltype(map_error_impl(std::declval< expected && >(), std::declval< F && >())) transform_error(F &&f) &&
Definition expected.hpp:1522
expected & operator=(U &&v)
Definition expected.hpp:1713
constexpr expected(unexpect_t, std::initializer_list< U > il, Args &&...args)
Definition expected.hpp:1624
constexpr expected(const expected< U, G > &rhs)
Definition expected.hpp:1635
constexpr decltype(map_error_impl(std::declval< const expected & >(), std::declval< F && >())) map_error(F &&f) const &
Definition expected.hpp:1485
expected constexpr or_else(F &&f) const &
Definition expected.hpp:1549
T value_type
Definition expected.hpp:1317
constexpr expected(in_place_t, std::initializer_list< U > il, Args &&...args)
Definition expected.hpp:1574
expected constexpr or_else(F &&f) &
Definition expected.hpp:1541
constexpr expected(expected &&rhs)=default
expected constexpr or_else(F &&f) &&
Definition expected.hpp:1545
constexpr decltype(map_error_impl(std::declval< expected & >(), std::declval< F && >())) map_error(F &&f) &
Definition expected.hpp:1473
constexpr decltype(map_error_impl(std::declval< const expected && >(), std::declval< F && >())) map_error(F &&f) const &&
Definition expected.hpp:1493
E error_type
Definition expected.hpp:1318
constexpr const U & operator*() const &
Definition expected.hpp:1989
constexpr expected(in_place_t, Args &&...args)
Definition expected.hpp:1567
constexpr U & value() &
Definition expected.hpp:2024
unexpected< E > unexpected_type
Definition expected.hpp:1319
expected & operator=(expected &&rhs)=default
expected constexpr or_else(F &&f) const &&
Definition expected.hpp:1554
expected & operator=(unexpected< G > &&rhs) noexcept
Definition expected.hpp:1779
constexpr const U && operator*() const &&
Definition expected.hpp:2001
constexpr decltype(map_error_impl(std::declval< const expected & >(), std::declval< F && >())) transform_error(F &&f) const &
Definition expected.hpp:1528
constexpr U && value() &&
Definition expected.hpp:2038
constexpr E && error() &&
Definition expected.hpp:2056
constexpr decltype(expected_map_impl(std::declval< const expected & >(), std::declval< F && >())) map(F &&f) const &
Definition expected.hpp:1397
constexpr decltype(expected_map_impl(std::declval< const expected && >(), std::declval< F && >())) map(F &&f) const &&
Definition expected.hpp:1405
Definition expected.hpp:146
Definition expected.hpp:154
constexpr unexpected(const E &e)
Definition expected.hpp:159
constexpr unexpected(Args &&...args)
Definition expected.hpp:165
constexpr E && value() &&
Definition expected.hpp:176
constexpr const E & value() const &
Definition expected.hpp:174
constexpr unexpected(std::initializer_list< U > l, Args &&...args)
Definition expected.hpp:171
constexpr E & value() &
Definition expected.hpp:175
constexpr const E && value() const &&
Definition expected.hpp:177
constexpr unexpected(E &&e)
Definition expected.hpp:161
#define TL_EXPECTED_IS_TRIVIALLY_DESTRUCTIBLE(T)
Definition expected.hpp:114
#define TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T)
Definition expected.hpp:110
#define TL_EXPECTED_NODISCARD
Definition expected.hpp:138
#define TL_EXPECTED_MSVC2015_CONSTEXPR
Definition expected.hpp:36
#define TL_ASSERT(x)
Definition expected.hpp:66
#define TL_EXPECTED_IS_TRIVIALLY_COPY_ASSIGNABLE(T)
Definition expected.hpp:112
#define TL_EXPECTED_THROW_EXCEPTION(e)
Definition expected.hpp:225
#define TL_EXPECTED_11_CONSTEXPR
Definition expected.hpp:132
@ E
Definition AcceleratorCodes.hpp:82
@ U
Definition AcceleratorCodes.hpp:98
@ F
Definition AcceleratorCodes.hpp:83
@ T
Definition AcceleratorCodes.hpp:97
Definition expected.hpp:330
std::false_type uses_std(...)
std::false_type can_swap(...) noexcept(false)
Definition expected.hpp:228
typename std::remove_reference< T >::type remove_reference_t
Definition expected.hpp:234
invoke_result_impl< F, void, Us... > invoke_result
Definition expected.hpp:318
is_void_or< T, std::is_move_assignable< T > > is_move_assignable_or_void
Definition expected.hpp:436
typename std::enable_if< E, T >::type enable_if_t
Definition expected.hpp:237
is_void_or< T, std::is_copy_assignable< T > > is_copy_assignable_or_void
Definition expected.hpp:433
typename std::decay< T >::type decay_t
Definition expected.hpp:235
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)...))
Definition expected.hpp:291
typename detail::decay_t< Exp >::error_type err_t
Definition expected.hpp:2077
conditional_t< std::is_void< T >::value, std::true_type, U > is_void_or
Definition expected.hpp:422
detail::enable_if_t< std::is_constructible< T, U && >::value && !std::is_same< detail::decay_t< U >, in_place_t >::value && !std::is_same< expected< T, E >, detail::decay_t< U > >::value && !std::is_same< unexpected< E >, detail::decay_t< U > >::value > expected_enable_forward_value
Definition expected.hpp:402
typename std::remove_const< T >::type remove_const_t
Definition expected.hpp:232
constexpr auto map_error_impl(Exp &&exp, F &&f) -> expected< exp_t< Exp >, detail::decay_t< Ret > >
Definition expected.hpp:2297
auto and_then_impl(Exp &&exp, F &&f) -> Ret
Definition expected.hpp:2108
is_expected_impl< decay_t< T > > is_expected
Definition expected.hpp:399
typename std::conditional< B, T, F >::type conditional_t
Definition expected.hpp:239
is_void_or< T, std::is_copy_constructible< T > > is_copy_constructible_or_void
Definition expected.hpp:425
expected< Ret, err_t< Exp > > ret_t
Definition expected.hpp:2078
typename invoke_result< F, Us... >::type invoke_result_t
Definition expected.hpp:321
auto or_else_impl(Exp &&exp, F &&f) -> Ret
Definition expected.hpp:2380
detail::enable_if_t< std::is_constructible< T, UR >::value && std::is_constructible< E, GR >::value && !std::is_constructible< T, expected< U, G > & >::value && !std::is_constructible< T, expected< U, G > && >::value && !std::is_constructible< T, const expected< U, G > & >::value && !std::is_constructible< T, const expected< U, G > && >::value && !std::is_convertible< expected< U, G > &, T >::value && !std::is_convertible< expected< U, G > &&, T >::value && !std::is_convertible< const expected< U, G > &, T >::value && !std::is_convertible< const expected< U, G > &&, T >::value > expected_enable_from_other
Definition expected.hpp:409
constexpr auto expected_map_impl(Exp &&exp, F &&f) -> ret_t< Exp, detail::decay_t< Ret > >
Definition expected.hpp:2185
is_void_or< T, std::is_move_constructible< T > > is_move_constructible_or_void
Definition expected.hpp:429
typename detail::decay_t< Exp >::value_type exp_t
Definition expected.hpp:2076
Definition expected.hpp:141
constexpr bool operator>=(const unexpected< E > &lhs, const unexpected< E > &rhs)
Definition expected.hpp:208
constexpr bool operator>(const unexpected< E > &lhs, const unexpected< E > &rhs)
Definition expected.hpp:204
constexpr bool operator!=(const unexpected< E > &lhs, const unexpected< E > &rhs)
Definition expected.hpp:192
constexpr bool operator==(const unexpected< E > &lhs, const unexpected< E > &rhs)
Definition expected.hpp:188
constexpr bool operator<=(const unexpected< E > &lhs, const unexpected< E > &rhs)
Definition expected.hpp:200
constexpr bool operator<(const unexpected< E > &lhs, const unexpected< E > &rhs)
Definition expected.hpp:196
unexpected< typename std::decay< E >::type > make_unexpected(E &&e)
Definition expected.hpp:213
void swap(expected< T, E > &lhs, expected< T, E > &rhs) noexcept(noexcept(lhs.swap(rhs)))
Definition expected.hpp:2469
Definition expected.hpp:2103
Definition expected.hpp:242
Definition expected.hpp:1212
constexpr default_constructor_tag()=default
expected_copy_assign_base & operator=(expected_copy_assign_base &&rhs)=default
expected_copy_assign_base(expected_copy_assign_base &&rhs)=default
expected_copy_assign_base()=default
expected_copy_assign_base(const expected_copy_assign_base &rhs)=default
expected_copy_assign_base & operator=(const expected_copy_assign_base &rhs)
Definition expected.hpp:1050
Definition expected.hpp:1038
expected_copy_base(expected_copy_base &&rhs)=default
expected_copy_base & operator=(const expected_copy_base &rhs)=default
expected_copy_base(const expected_copy_base &rhs)
Definition expected.hpp:976
expected_copy_base()=default
expected_copy_base & operator=(expected_copy_base &&rhs)=default
Definition expected.hpp:966
constexpr expected_default_ctor_base() noexcept=delete
Definition expected.hpp:1222
constexpr expected_default_ctor_base() noexcept=default
expected_delete_assign_base(expected_delete_assign_base &&) noexcept=default
expected_delete_assign_base()=default
expected_delete_assign_base(const expected_delete_assign_base &)=default
expected_delete_assign_base(expected_delete_assign_base &&) noexcept=default
expected_delete_assign_base()=default
expected_delete_assign_base(const expected_delete_assign_base &)=default
expected_delete_assign_base(const expected_delete_assign_base &)=default
expected_delete_assign_base()=default
expected_delete_assign_base(expected_delete_assign_base &&) noexcept=default
Definition expected.hpp:1163
expected_delete_assign_base(const expected_delete_assign_base &)=default
expected_delete_assign_base(expected_delete_assign_base &&) noexcept=default
expected_delete_assign_base()=default
expected_delete_ctor_base(expected_delete_ctor_base &&) noexcept=delete
expected_delete_ctor_base()=default
expected_delete_ctor_base(const expected_delete_ctor_base &)=delete
expected_delete_ctor_base(expected_delete_ctor_base &&) noexcept=default
expected_delete_ctor_base(const expected_delete_ctor_base &)=delete
expected_delete_ctor_base()=default
expected_delete_ctor_base()=default
expected_delete_ctor_base(expected_delete_ctor_base &&) noexcept=delete
expected_delete_ctor_base(const expected_delete_ctor_base &)=default
Definition expected.hpp:1108
expected_delete_ctor_base()=default
expected_delete_ctor_base(const expected_delete_ctor_base &)=default
expected_delete_ctor_base(expected_delete_ctor_base &&) noexcept=default
expected_move_assign_base()=default
expected_move_assign_base & operator=(expected_move_assign_base &&rhs) noexcept(std::is_nothrow_move_constructible< T >::value &&std::is_nothrow_move_assignable< T >::value)
Definition expected.hpp:1093
expected_move_assign_base(expected_move_assign_base &&rhs)=default
expected_move_assign_base(const expected_move_assign_base &rhs)=default
expected_move_assign_base & operator=(const expected_move_assign_base &rhs)=default
Definition expected.hpp:1072
expected_move_base & operator=(expected_move_base &&rhs)=default
expected_move_base & operator=(const expected_move_base &rhs)=default
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< T >::value)
Definition expected.hpp:1012
Definition expected.hpp:999
void construct() noexcept
Definition expected.hpp:910
constexpr const unexpected< E > && geterr() const &&
Definition expected.hpp:949
constexpr const unexpected< E > & geterr() const &
Definition expected.hpp:944
void assign(Rhs &&rhs) noexcept
Definition expected.hpp:924
void construct_error(Args &&...args) noexcept
Definition expected.hpp:918
void construct_with(Rhs &&) noexcept
Definition expected.hpp:914
bool has_value() const
Definition expected.hpp:939
constexpr unexpected< E > && geterr() &&
Definition expected.hpp:945
constexpr void destroy_val()
Definition expected.hpp:954
constexpr unexpected< E > & geterr() &
Definition expected.hpp:941
Definition expected.hpp:721
constexpr const T && get() const &&
Definition expected.hpp:885
constexpr void destroy_val()
Definition expected.hpp:901
constexpr unexpected< E > && geterr() &&
Definition expected.hpp:892
constexpr const unexpected< E > & geterr() const &
Definition expected.hpp:891
constexpr const T & get() const &
Definition expected.hpp:882
constexpr unexpected< E > & geterr() &
Definition expected.hpp:888
constexpr const unexpected< E > && geterr() const &&
Definition expected.hpp:896
void construct(Args &&...args) noexcept
Definition expected.hpp:724
void assign(const expected_operations_base &rhs) noexcept
Definition expected.hpp:843
constexpr T & get() &
Definition expected.hpp:881
void construct_with(Rhs &&rhs) noexcept
Definition expected.hpp:729
void construct_error(Args &&...args) noexcept
Definition expected.hpp:734
void assign_common(Rhs &&rhs)
Definition expected.hpp:864
constexpr T && get() &&
Definition expected.hpp:883
void assign(expected_operations_base &&rhs) noexcept
Definition expected.hpp:852
bool has_value() const
Definition expected.hpp:879
~expected_storage_base()
Definition expected.hpp:627
bool m_has_val
Definition expected.hpp:637
expected_storage_base & operator=(expected_storage_base &&)=default
expected_storage_base & operator=(const expected_storage_base &)=default
expected_storage_base(expected_storage_base &&)=default
T m_val
Definition expected.hpp:633
constexpr expected_storage_base(in_place_t, std::initializer_list< U > il, Args &&...args)
Definition expected.hpp:606
constexpr expected_storage_base(no_init_t)
Definition expected.hpp:595
expected_storage_base(const expected_storage_base &)=default
char m_no_init
Definition expected.hpp:635
constexpr expected_storage_base(in_place_t, Args &&...args)
Definition expected.hpp:600
constexpr expected_storage_base()
Definition expected.hpp:594
constexpr expected_storage_base(unexpect_t, Args &&...args)
Definition expected.hpp:612
constexpr expected_storage_base(unexpect_t, std::initializer_list< U > il, Args &&...args)
Definition expected.hpp:618
unexpected< E > m_unexpect
Definition expected.hpp:634
bool m_has_val
Definition expected.hpp:589
~expected_storage_base()
Definition expected.hpp:578
constexpr expected_storage_base()
Definition expected.hpp:544
expected_storage_base & operator=(const expected_storage_base &)=default
T m_val
Definition expected.hpp:585
constexpr expected_storage_base(unexpect_t, std::initializer_list< U > il, Args &&...args)
Definition expected.hpp:569
constexpr expected_storage_base(unexpect_t, Args &&...args)
Definition expected.hpp:563
expected_storage_base & operator=(expected_storage_base &&)=default
unexpected< E > m_unexpect
Definition expected.hpp:586
expected_storage_base(expected_storage_base &&)=default
char m_no_init
Definition expected.hpp:587
constexpr expected_storage_base(no_init_t)
Definition expected.hpp:545
constexpr expected_storage_base(in_place_t, Args &&...args)
Definition expected.hpp:551
constexpr expected_storage_base(in_place_t, std::initializer_list< U > il, Args &&...args)
Definition expected.hpp:557
expected_storage_base(const expected_storage_base &)=default
constexpr expected_storage_base()
Definition expected.hpp:500
constexpr expected_storage_base(no_init_t)
Definition expected.hpp:501
~expected_storage_base()=default
expected_storage_base & operator=(const expected_storage_base &)=default
constexpr expected_storage_base(in_place_t, Args &&...args)
Definition expected.hpp:506
constexpr expected_storage_base(in_place_t, std::initializer_list< U > il, Args &&...args)
Definition expected.hpp:512
bool m_has_val
Definition expected.hpp:539
constexpr expected_storage_base(unexpect_t, Args &&...args)
Definition expected.hpp:518
char m_no_init
Definition expected.hpp:537
T m_val
Definition expected.hpp:535
expected_storage_base & operator=(expected_storage_base &&)=default
expected_storage_base(expected_storage_base &&)=default
constexpr expected_storage_base(unexpect_t, std::initializer_list< U > il, Args &&...args)
Definition expected.hpp:524
expected_storage_base(const expected_storage_base &)=default
unexpected< E > m_unexpect
Definition expected.hpp:536
constexpr expected_storage_base(in_place_t)
Definition expected.hpp:685
constexpr expected_storage_base()
Definition expected.hpp:682
constexpr expected_storage_base(unexpect_t, std::initializer_list< U > il, Args &&...args)
Definition expected.hpp:696
expected_storage_base(expected_storage_base &&)=default
bool m_has_val
Definition expected.hpp:715
unexpected< E > m_unexpect
Definition expected.hpp:712
char m_dummy
Definition expected.hpp:713
~expected_storage_base()
Definition expected.hpp:705
constexpr expected_storage_base(unexpect_t, Args &&...args)
Definition expected.hpp:690
expected_storage_base(const expected_storage_base &)=default
expected_storage_base & operator=(const expected_storage_base &)=default
constexpr expected_storage_base(no_init_t)
Definition expected.hpp:683
expected_storage_base & operator=(expected_storage_base &&)=default
Definition expected.hpp:672
constexpr expected_storage_base(in_place_t)
Definition expected.hpp:651
expected_storage_base(expected_storage_base &&)=default
constexpr expected_storage_base(no_init_t)
Definition expected.hpp:649
dummy m_val
Definition expected.hpp:675
constexpr expected_storage_base(unexpect_t, Args &&...args)
Definition expected.hpp:656
expected_storage_base(const expected_storage_base &)=default
~expected_storage_base()=default
expected_storage_base & operator=(expected_storage_base &&)=default
constexpr expected_storage_base(unexpect_t, std::initializer_list< U > il, Args &&...args)
Definition expected.hpp:662
expected_storage_base & operator=(const expected_storage_base &)=default
expected_storage_base()
Definition expected.hpp:647
unexpected< E > m_unexpect
Definition expected.hpp:674
bool m_has_val
Definition expected.hpp:677
T m_val
Definition expected.hpp:490
constexpr expected_storage_base(unexpect_t, Args &&...args)
Definition expected.hpp:471
constexpr expected_storage_base(no_init_t)
Definition expected.hpp:454
bool m_has_val
Definition expected.hpp:494
~expected_storage_base()
Definition expected.hpp:482
constexpr expected_storage_base()
Definition expected.hpp:453
constexpr expected_storage_base(in_place_t, std::initializer_list< U > il, Args &&...args)
Definition expected.hpp:465
char m_no_init
Definition expected.hpp:492
constexpr expected_storage_base(in_place_t, Args &&...args)
Definition expected.hpp:459
unexpected< E > m_unexpect
Definition expected.hpp:491
constexpr expected_storage_base(unexpect_t, std::initializer_list< U > il, Args &&...args)
Definition expected.hpp:477
decltype(detail::invoke(std::declval< F >(), std::declval< Us >()...)) type
Definition expected.hpp:313
Definition expected.hpp:306
Definition expected.hpp:396
Definition expected.hpp:391
Definition expected.hpp:372
Definition expected.hpp:441
Definition expected.hpp:362
Definition expected.hpp:355
Definition expected.hpp:333
Definition expected.hpp:148
Definition expected.hpp:217