16#ifndef WPI_EXPECTED_HPP
17#define WPI_EXPECTED_HPP
19#define WPI_EXPECTED_VERSION_MAJOR 1
20#define WPI_EXPECTED_VERSION_MINOR 1
21#define WPI_EXPECTED_VERSION_PATCH 0
28#if defined(__EXCEPTIONS) || defined(_CPPUNWIND)
29#define WPI_EXPECTED_EXCEPTIONS_ENABLED
32#if (defined(_MSC_VER) && _MSC_VER == 1900)
33#define WPI_EXPECTED_MSVC2015
34#define WPI_EXPECTED_MSVC2015_CONSTEXPR
36#define WPI_EXPECTED_MSVC2015_CONSTEXPR constexpr
39#if (defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ <= 9 && \
41#define WPI_EXPECTED_GCC49
44#if (defined(__GNUC__) && __GNUC__ == 5 && __GNUC_MINOR__ <= 4 && \
46#define WPI_EXPECTED_GCC54
49#if (defined(__GNUC__) && __GNUC__ == 5 && __GNUC_MINOR__ <= 5 && \
51#define WPI_EXPECTED_GCC55
54#if !defined(WPI_ASSERT)
56#if (__cplusplus > 201103L) && !defined(WPI_EXPECTED_GCC49)
58#define WPI_ASSERT(x) assert(x)
64#if (defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ <= 9 && \
68#define WPI_EXPECTED_NO_CONSTRR
70#define WPI_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) \
71 std::has_trivial_copy_constructor<T>
72#define WPI_EXPECTED_IS_TRIVIALLY_COPY_ASSIGNABLE(T) \
73 std::has_trivial_copy_assign<T>
76#define WPI_EXPECTED_IS_TRIVIALLY_DESTRUCTIBLE(T) \
77 std::is_trivially_destructible<T>
81#elif (defined(__GNUC__) && __GNUC__ < 8 && !defined(__clang__))
82#ifndef WPI_GCC_LESS_8_TRIVIALLY_COPY_CONSTRUCTIBLE_MUTEX
83#define WPI_GCC_LESS_8_TRIVIALLY_COPY_CONSTRUCTIBLE_MUTEX
85namespace detail_expected {
87struct is_trivially_copy_constructible
88 : std::is_trivially_copy_constructible<T> {};
90template <
class T,
class A>
91struct is_trivially_copy_constructible<
std::vector<T, A>> : std::false_type {};
97#define WPI_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) \
98 wpi::detail_expected::is_trivially_copy_constructible<T>
99#define WPI_EXPECTED_IS_TRIVIALLY_COPY_ASSIGNABLE(T) \
100 std::is_trivially_copy_assignable<T>
101#define WPI_EXPECTED_IS_TRIVIALLY_DESTRUCTIBLE(T) \
102 std::is_trivially_destructible<T>
104#define WPI_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) \
105 std::is_trivially_copy_constructible<T>
106#define WPI_EXPECTED_IS_TRIVIALLY_COPY_ASSIGNABLE(T) \
107 std::is_trivially_copy_assignable<T>
108#define WPI_EXPECTED_IS_TRIVIALLY_DESTRUCTIBLE(T) \
109 std::is_trivially_destructible<T>
112#if __cplusplus > 201103L
113#define WPI_EXPECTED_CXX14
116#ifdef WPI_EXPECTED_GCC49
117#define WPI_EXPECTED_GCC49_CONSTEXPR
119#define WPI_EXPECTED_GCC49_CONSTEXPR constexpr
122#if (__cplusplus == 201103L || defined(WPI_EXPECTED_MSVC2015) || \
123 defined(WPI_EXPECTED_GCC49))
124#define WPI_EXPECTED_11_CONSTEXPR
126#define WPI_EXPECTED_11_CONSTEXPR constexpr
130template <
class T,
class E>
class expected;
132#ifndef WPI_MONOSTATE_INPLACE_MUTEX
133#define WPI_MONOSTATE_INPLACE_MUTEX
144 static_assert(!std::is_same<E, void>::value,
"E must not be void");
151 template <
class... Args,
typename std::enable_if<std::is_constructible<
152 E, Args &&...>
::value>::type * =
nullptr>
154 : m_val(
std::forward<Args>(args)...) {}
156 class U,
class... Args,
157 typename std::enable_if<std::is_constructible<
158 E, std::initializer_list<U> &, Args &&...>
::value>::type * =
nullptr>
159 constexpr explicit unexpected(std::initializer_list<U> l, Args &&...args)
160 : m_val(l,
std::forward<Args>(args)...) {}
162 constexpr const E &
value() const & {
return m_val; }
165 constexpr const E &&
value() const && {
return std::move(m_val); }
171#ifdef __cpp_deduction_guides
172template <
class E> unexpected(E) -> unexpected<E>;
210namespace detail_expected {
213#ifdef WPI_EXPECTED_EXCEPTIONS_ENABLED
214 throw std::forward<E>(e);
220 __builtin_unreachable();
225#ifndef WPI_TRAITS_MUTEX
226#define WPI_TRAITS_MUTEX
231template <
class T>
using decay_t =
typename std::decay<T>::type;
232template <
bool E,
class T =
void>
234template <
bool B,
class T,
class F>
240template <
class B,
class... Bs>
242 : std::conditional<bool(B::value), conjunction<Bs...>, B>::type {};
244#if defined(_LIBCPP_VERSION) && __cplusplus == 201103L
245#define WPI_TRAITS_LIBCXX_MEM_FN_WORKAROUND
251#ifdef WPI_TRAITS_LIBCXX_MEM_FN_WORKAROUND
253struct is_pointer_to_non_const_member_func : std::false_type {};
254template <
class T,
class Ret,
class... Args>
255struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...)>
257template <
class T,
class Ret,
class... Args>
258struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...) &>
260template <
class T,
class Ret,
class... Args>
261struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...) &&>
263template <
class T,
class Ret,
class... Args>
264struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...) volatile>
266template <
class T,
class Ret,
class... Args>
267struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...) volatile &>
269template <
class T,
class Ret,
class... Args>
270struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...) volatile &&>
273template <
class T>
struct is_const_or_const_ref : std::false_type {};
274template <
class T>
struct is_const_or_const_ref<T const &> : std::true_type {};
275template <
class T>
struct is_const_or_const_ref<T const> : std::true_type {};
281 typename Fn,
typename... Args,
282#ifdef WPI_TRAITS_LIBCXX_MEM_FN_WORKAROUND
283 typename =
enable_if_t<!(is_pointer_to_non_const_member_func<Fn>::value &&
284 is_const_or_const_ref<Args...>::value)>,
287constexpr auto invoke(Fn &&f, Args &&...args)
noexcept(
288 noexcept(std::mem_fn(f)(std::forward<Args>(args)...)))
289 ->
decltype(std::mem_fn(f)(std::forward<Args>(args)...)) {
290 return std::mem_fn(f)(std::forward<Args>(args)...);
293template <
typename Fn,
typename... Args,
295constexpr auto invoke(Fn &&f, Args &&...args)
noexcept(
296 noexcept(std::forward<Fn>(f)(std::forward<Args>(args)...)))
297 ->
decltype(std::forward<Fn>(f)(std::forward<Args>(args)...)) {
298 return std::forward<Fn>(f)(std::forward<Args>(args)...);
304template <
class F,
class... Us>
307 decltype(detail_expected::
invoke(std::declval<F>(), std::declval<Us>()...), void()),
313template <
class F,
class... Us>
316template <
class F,
class... Us>
319#if defined(_MSC_VER) && _MSC_VER <= 1900
321template <
class T,
class U = T>
struct is_swappable : std::true_type {};
323template <
class T,
class U = T>
struct is_nothrow_swappable : std::true_type {};
326namespace swap_adl_tests {
332template <
class T, std::
size_t N>
tag swap(T (&a)[N], T (&b)[N]);
336template <
class,
class> std::false_type
can_swap(...) noexcept(false);
337template <class T, class U,
338 class = decltype(swap(
std::declval<T &>(),
std::declval<U &>()))>
340 std::declval<U &>())));
343template <class T, class U>
344std::is_same<decltype(swap(
std::declval<T &>(),
std::declval<U &>())),
tag>
349 :
std::integral_constant<
bool,
350 std::is_nothrow_move_constructible<T>::value &&
351 std::is_nothrow_move_assignable<T>::value> {};
353template <
class T, std::
size_t N>
356template <
class T,
class U>
358 : std::integral_constant<bool, noexcept(can_swap<T, U>(0))> {};
361template <
class T,
class U = T>
363 : std::integral_constant<
365 decltype(detail_expected::swap_adl_tests::can_swap<T, U>(0))::value &&
366 (!decltype(detail_expected::swap_adl_tests::uses_std<T, U>(0))::value ||
367 (std::is_move_assignable<T>::value &&
368 std::is_move_constructible<T>::value))> {};
370template <
class T, std::
size_t N>
372 : std::integral_constant<
374 decltype(detail_expected::swap_adl_tests::can_swap<T[N], T[N]>(0))::value &&
375 (!decltype(detail_expected::swap_adl_tests::uses_std<T[N], T[N]>(
377 is_swappable<T, T>::value)> {};
379template <
class T,
class U = T>
381 : std::integral_constant<
383 is_swappable<T, U>::value &&
384 ((decltype(detail_expected::swap_adl_tests::uses_std<T, U>(0))::value &&
385 detail_expected::swap_adl_tests::is_std_swap_noexcept<T>::value) ||
386 (!decltype(detail_expected::swap_adl_tests::uses_std<T, U>(0))::value &&
387 detail_expected::swap_adl_tests::is_adl_swap_noexcept<T, U>::value))> {};
393template <
class T,
class E>
397template <
class T,
class E,
class U>
399 std::is_constructible<T, U &&>::value &&
400 !std::is_same<detail_expected::decay_t<U>,
in_place_t>::value &&
404template <
class T,
class E,
class U,
class G,
class UR,
class GR>
406 std::is_constructible<T, UR>::value &&
407 std::is_constructible<E, GR>::value &&
408 !std::is_constructible<T, expected<U, G> &>::value &&
409 !std::is_constructible<T, expected<U, G> &&>::value &&
410 !std::is_constructible<T, const expected<U, G> &>::value &&
411 !std::is_constructible<T, const expected<U, G> &&>::value &&
412 !std::is_convertible<expected<U, G> &, T>::value &&
413 !std::is_convertible<expected<U, G> &&, T>::value &&
414 !std::is_convertible<const expected<U, G> &, T>::value &&
415 !std::is_convertible<const expected<U, G> &&, T>::value>;
417template <
class T,
class U>
436namespace detail_expected {
446template <class T, class E, bool = std::is_trivially_destructible<T>::value,
447 bool = std::is_trivially_destructible<E>::value>
452 template <
class... Args,
458 template <
class U,
class... Args,
460 T, std::initializer_list<U> &, Args &&...>::value> * =
nullptr>
464 template <
class... Args,
470 template <
class U,
class... Args,
472 E, std::initializer_list<U> &, Args &&...>::value> * =
nullptr>
474 std::initializer_list<U> il,
499 template <
class... Args,
503 : m_val(
std::forward<Args>(args)...), m_has_val(true) {}
505 template <
class U,
class... Args,
507 T, std::initializer_list<U> &, Args &&...>::value> * =
nullptr>
510 : m_val(il,
std::forward<Args>(args)...), m_has_val(true) {}
511 template <
class... Args,
515 : m_unexpect(
std::forward<Args>(args)...), m_has_val(false) {}
517 template <
class U,
class... Args,
519 E, std::initializer_list<U> &, Args &&...>::value> * =
nullptr>
521 std::initializer_list<U> il,
523 : m_unexpect(il,
std::forward<Args>(args)...), m_has_val(false) {}
538 : m_no_init(), m_has_val(false) {}
540 template <
class... Args,
544 : m_val(
std::forward<Args>(args)...), m_has_val(true) {}
546 template <
class U,
class... Args,
548 T, std::initializer_list<U> &, Args &&...>::value> * =
nullptr>
551 : m_val(il,
std::forward<Args>(args)...), m_has_val(true) {}
552 template <
class... Args,
556 : m_unexpect(
std::forward<Args>(args)...), m_has_val(false) {}
558 template <
class U,
class... Args,
560 E, std::initializer_list<U> &, Args &&...>::value> * =
nullptr>
562 std::initializer_list<U> il,
564 : m_unexpect(il,
std::forward<Args>(args)...), m_has_val(false) {}
568 m_unexpect.~unexpected<E>();
585 template <
class... Args,
589 : m_val(
std::forward<Args>(args)...), m_has_val(true) {}
591 template <
class U,
class... Args,
593 T, std::initializer_list<U> &, Args &&...>::value> * =
nullptr>
596 : m_val(il,
std::forward<Args>(args)...), m_has_val(true) {}
597 template <
class... Args,
601 : m_unexpect(
std::forward<Args>(args)...), m_has_val(false) {}
603 template <
class U,
class... Args,
605 E, std::initializer_list<U> &, Args &&...>::value> * =
nullptr>
607 std::initializer_list<U> il,
609 : m_unexpect(il,
std::forward<Args>(args)...), m_has_val(false) {}
637 template <
class... Args,
641 : m_unexpect(
std::forward<Args>(args)...), m_has_val(false) {}
643 template <
class U,
class... Args,
645 E, std::initializer_list<U> &, Args &&...>::value> * =
nullptr>
647 std::initializer_list<U> il,
649 : m_unexpect(il,
std::forward<Args>(args)...), m_has_val(false) {}
667 template <
class... Args,
671 : m_unexpect(
std::forward<Args>(args)...), m_has_val(false) {}
673 template <
class U,
class... Args,
675 E, std::initializer_list<U> &, Args &&...>::value> * =
nullptr>
677 std::initializer_list<U> il,
679 : m_unexpect(il,
std::forward<Args>(args)...), m_has_val(false) {}
683 m_unexpect.~unexpected<E>();
696template <
class T,
class E>
700 template <
class... Args>
void construct(Args &&...args)
noexcept {
701 new (std::addressof(this->m_val)) T(std::forward<Args>(args)...);
702 this->m_has_val =
true;
706 new (std::addressof(this->m_val)) T(std::forward<Rhs>(rhs).
get());
707 this->m_has_val =
true;
711 new (std::addressof(this->m_unexpect))
713 this->m_has_val =
false;
716#ifdef WPI_EXPECTED_EXCEPTIONS_ENABLED
724 template <
class U = T,
728 if (!this->m_has_val && rhs.m_has_val) {
729 geterr().~unexpected<E>();
730 construct(rhs.get());
738 template <
class U = T,
739 detail_expected::enable_if_t<!std::is_nothrow_copy_constructible<U>::value &&
740 std::is_nothrow_move_constructible<U>::value>
742 void assign(
const expected_operations_base &rhs)
noexcept {
743 if (!this->m_has_val && rhs.m_has_val) {
745 geterr().~unexpected<E>();
757 template <
class U = T,
758 detail_expected::enable_if_t<!std::is_nothrow_copy_constructible<U>::value &&
759 !std::is_nothrow_move_constructible<U>::value>
761 void assign(
const expected_operations_base &rhs) {
762 if (!this->m_has_val && rhs.m_has_val) {
763 auto tmp = std::move(geterr());
764 geterr().~unexpected<E>();
766#ifdef WPI_EXPECTED_EXCEPTIONS_ENABLED
770 geterr() = std::move(tmp);
782 template <
class U = T,
783 detail_expected::enable_if_t<std::is_nothrow_move_constructible<U>::value>
785 void assign(expected_operations_base &&rhs)
noexcept {
786 if (!this->m_has_val && rhs.m_has_val) {
787 geterr().~unexpected<E>();
790 assign_common(std::move(rhs));
794 template <
class U = T,
795 detail_expected::enable_if_t<!std::is_nothrow_move_constructible<U>::value>
797 void assign(expected_operations_base &&rhs) {
798 if (!this->m_has_val && rhs.m_has_val) {
799 auto tmp = std::move(geterr());
800 geterr().~unexpected<E>();
801#ifdef WPI_EXPECTED_EXCEPTIONS_ENABLED
805 geterr() = std::move(tmp);
812 assign_common(std::move(rhs));
820 if (!this->m_has_val && rhs.m_has_val) {
821 geterr().~unexpected<E>();
822 construct(rhs.get());
829 if (!this->m_has_val && rhs.m_has_val) {
830 geterr().~unexpected<E>();
831 construct(std::move(rhs).
get());
833 assign_common(std::move(rhs));
841 if (this->m_has_val) {
843 get() = std::forward<Rhs>(rhs).get();
846 construct_error(std::forward<Rhs>(rhs).geterr());
849 if (!rhs.m_has_val) {
850 geterr() = std::forward<Rhs>(rhs).geterr();
858 constexpr const T &
get() const & {
return this->m_val; }
860#ifndef WPI_EXPECTED_NO_CONSTRR
861 constexpr const T &&
get() const && {
return std::move(this->m_val); }
865 return this->m_unexpect;
869 return std::move(this->m_unexpect);
871#ifndef WPI_EXPECTED_NO_CONSTRR
873 return std::move(this->m_unexpect);
900 template <
class Rhs>
void assign(Rhs &&rhs)
noexcept {
903 geterr().~unexpected<E>();
906 geterr() = std::forward<Rhs>(rhs).geterr();
909 if (!rhs.m_has_val) {
924#ifndef WPI_EXPECTED_NO_CONSTRR
937template <
class T,
class E,
945template <
class T,
class E>
953 this->construct_with(rhs);
955 this->construct_error(rhs.geterr());
969#ifndef WPI_EXPECTED_GCC49
970template <
class T,
class E,
972 &&std::is_trivially_move_constructible<E>::value>
979template <
class T,
class E>
987 std::is_nothrow_move_constructible<T>::value)
989 if (rhs.has_value()) {
990 this->construct_with(std::move(rhs));
992 this->construct_error(std::move(rhs.geterr()));
1000template <
class T,
class E,
1012template <
class T,
class E>
1033#ifndef WPI_EXPECTED_GCC49
1034template <
class T,
class E,
1037 std::is_trivially_move_constructible<T>,
1038 std::is_trivially_move_assignable<T>>>::
1039 value &&std::is_trivially_destructible<E>::value
1040 &&std::is_trivially_move_constructible<E>::value
1041 &&std::is_trivially_move_assignable<E>::value>
1049template <
class T,
class E>
1064 std::is_nothrow_move_constructible<T>::value
1065 &&std::is_nothrow_move_assignable<T>::value) {
1066 this->
assign(std::move(rhs));
1073template <
class T,
class E,
1074 bool EnableCopy = (is_copy_constructible_or_void<T>::value &&
1075 std::is_copy_constructible<E>::value),
1076 bool EnableMove = (is_move_constructible_or_void<T>::value &&
1077 std::is_move_constructible<E>::value)>
1088template <class T, class E>
1099template <class T, class E>
1110template <class T, class E>
1124template <class T, class E,
1126 std::is_copy_constructible<E>::value &&
1128 std::is_copy_assignable<E>::value),
1130 std::is_move_constructible<E>::value &&
1132 std::is_move_assignable<E>::value)>
1144template <class T, class E>
1156template <class T, class E>
1168template <class T, class E>
1189template <
class T,
class E,
1191 std::is_default_constructible<T>::value || std::is_void<T>::value>
1226 virtual const char *
what() const noexcept
override {
1227 return "Bad expected access";
1230 const E &
error() const & {
return m_val; }
1232 const E &&
error() const && {
return std::move(m_val); }
1233 E &&
error() && {
return std::move(m_val); }
1246template <
class T,
class E>
1251 static_assert(!std::is_reference<T>::value,
"T must not be a reference");
1252 static_assert(!std::is_same<T, std::remove_cv<in_place_t>::type>::value,
1253 "T must not be in_place_t");
1254 static_assert(!std::is_same<T, std::remove_cv<unexpect_t>::type>::value,
1255 "T must not be unexpect_t");
1257 !std::is_same<T, typename std::remove_cv<unexpected<E>>::type>::value,
1258 "T must not be unexpected<E>");
1259 static_assert(!std::is_reference<E>::value,
"E must not be a reference");
1261 T *valptr() {
return std::addressof(this->m_val); }
1262 const T *valptr()
const {
return std::addressof(this->m_val); }
1263 unexpected<E> *errptr() {
return std::addressof(this->m_unexpect); }
1265 return std::addressof(this->m_unexpect);
1268 template <
class U = T,
1275 template <
class U = T,
1277 constexpr const U &val()
const {
1280 constexpr const unexpected<E> &err()
const {
return this->m_unexpect; }
1290#if defined(WPI_EXPECTED_CXX14) && !defined(WPI_EXPECTED_GCC49) && \
1291 !defined(WPI_EXPECTED_GCC54) && !defined(WPI_EXPECTED_GCC55)
1293 return and_then_impl(*
this, std::forward<F>(f));
1296 return and_then_impl(std::move(*
this), std::forward<F>(f));
1298 template <
class F>
constexpr auto and_then(F &&f)
const & {
1299 return and_then_impl(*
this, std::forward<F>(f));
1302#ifndef WPI_EXPECTED_NO_CONSTRR
1303 template <
class F>
constexpr auto and_then(F &&f)
const && {
1311 and_then(F &&f) & ->
decltype(and_then_impl(std::declval<expected &>(),
1312 std::forward<F>(f))) {
1313 return and_then_impl(*
this, std::forward<F>(f));
1317 and_then(F &&f) && ->
decltype(and_then_impl(std::declval<expected &&>(),
1318 std::forward<F>(f))) {
1319 return and_then_impl(std::move(*
this), std::forward<F>(f));
1322 constexpr auto and_then(F &&f)
const & ->
decltype(and_then_impl(
1323 std::declval<expected const &>(), std::forward<F>(f))) {
1324 return and_then_impl(*
this, std::forward<F>(f));
1327#ifndef WPI_EXPECTED_NO_CONSTRR
1329 constexpr auto and_then(F &&f)
const && ->
decltype(and_then_impl(
1330 std::declval<expected const &&>(), std::forward<F>(f))) {
1331 return and_then_impl(std::move(*
this), std::forward<F>(f));
1336#if defined(WPI_EXPECTED_CXX14) && !defined(WPI_EXPECTED_GCC49) && \
1337 !defined(WPI_EXPECTED_GCC54) && !defined(WPI_EXPECTED_GCC55)
1339 return expected_map_impl(*
this, std::forward<F>(f));
1342 return expected_map_impl(std::move(*
this), std::forward<F>(f));
1344 template <
class F>
constexpr auto map(F &&f)
const & {
1347 template <
class F>
constexpr auto map(F &&f)
const && {
1353 std::declval<expected &>(), std::declval<F &&>()))
1355 return expected_map_impl(*
this, std::forward<F>(f));
1359 std::declval<F &&>()))
1361 return expected_map_impl(std::move(*
this), std::forward<F>(f));
1364 constexpr decltype(expected_map_impl(std::declval<const expected &>(),
1365 std::declval<F &&>()))
1367 return expected_map_impl(*
this, std::forward<F>(f));
1370#ifndef WPI_EXPECTED_NO_CONSTRR
1372 constexpr decltype(expected_map_impl(std::declval<const expected &&>(),
1373 std::declval<F &&>()))
1375 return expected_map_impl(std::move(*
this), std::forward<F>(f));
1380#if defined(WPI_EXPECTED_CXX14) && !defined(WPI_EXPECTED_GCC49) && \
1381 !defined(WPI_EXPECTED_GCC54) && !defined(WPI_EXPECTED_GCC55)
1383 return expected_map_impl(*
this, std::forward<F>(f));
1386 return expected_map_impl(std::move(*
this), std::forward<F>(f));
1388 template <
class F>
constexpr auto transform(F &&f)
const & {
1391 template <
class F>
constexpr auto transform(F &&f)
const && {
1397 std::declval<expected &>(), std::declval<F &&>()))
1399 return expected_map_impl(*
this, std::forward<F>(f));
1403 std::declval<F &&>()))
1405 return expected_map_impl(std::move(*
this), std::forward<F>(f));
1408 constexpr decltype(expected_map_impl(std::declval<const expected &>(),
1409 std::declval<F &&>()))
1411 return expected_map_impl(*
this, std::forward<F>(f));
1414#ifndef WPI_EXPECTED_NO_CONSTRR
1416 constexpr decltype(expected_map_impl(std::declval<const expected &&>(),
1417 std::declval<F &&>()))
1419 return expected_map_impl(std::move(*
this), std::forward<F>(f));
1424#if defined(WPI_EXPECTED_CXX14) && !defined(WPI_EXPECTED_GCC49) && \
1425 !defined(WPI_EXPECTED_GCC54) && !defined(WPI_EXPECTED_GCC55)
1427 return map_error_impl(*
this, std::forward<F>(f));
1430 return map_error_impl(std::move(*
this), std::forward<F>(f));
1432 template <
class F>
constexpr auto map_error(F &&f)
const & {
1435 template <
class F>
constexpr auto map_error(F &&f)
const && {
1441 std::declval<F &&>()))
1443 return map_error_impl(*
this, std::forward<F>(f));
1447 std::declval<F &&>()))
1449 return map_error_impl(std::move(*
this), std::forward<F>(f));
1452 constexpr decltype(map_error_impl(std::declval<const expected &>(),
1453 std::declval<F &&>()))
1455 return map_error_impl(*
this, std::forward<F>(f));
1458#ifndef WPI_EXPECTED_NO_CONSTRR
1460 constexpr decltype(map_error_impl(std::declval<const expected &&>(),
1461 std::declval<F &&>()))
1463 return map_error_impl(std::move(*
this), std::forward<F>(f));
1467#if defined(WPI_EXPECTED_CXX14) && !defined(WPI_EXPECTED_GCC49) && \
1468 !defined(WPI_EXPECTED_GCC54) && !defined(WPI_EXPECTED_GCC55)
1470 return map_error_impl(*
this, std::forward<F>(f));
1473 return map_error_impl(std::move(*
this), std::forward<F>(f));
1475 template <
class F>
constexpr auto transform_error(F &&f)
const & {
1478 template <
class F>
constexpr auto transform_error(F &&f)
const && {
1484 std::declval<F &&>()))
1486 return map_error_impl(*
this, std::forward<F>(f));
1490 std::declval<F &&>()))
1492 return map_error_impl(std::move(*
this), std::forward<F>(f));
1495 constexpr decltype(map_error_impl(std::declval<const expected &>(),
1496 std::declval<F &&>()))
1498 return map_error_impl(*
this, std::forward<F>(f));
1501#ifndef WPI_EXPECTED_NO_CONSTRR
1503 constexpr decltype(map_error_impl(std::declval<const expected &&>(),
1504 std::declval<F &&>()))
1506 return map_error_impl(std::move(*
this), std::forward<F>(f));
1511 return or_else_impl(*
this, std::forward<F>(f));
1515 return or_else_impl(std::move(*
this), std::forward<F>(f));
1519 return or_else_impl(*
this, std::forward<F>(f));
1522#ifndef WPI_EXPECTED_NO_CONSTRR
1524 return or_else_impl(std::move(*
this), std::forward<F>(f));
1533 template <
class... Args,
1538 ctor_base(detail_expected::default_constructor_tag{}) {}
1540 template <
class U,
class... Args,
1542 T, std::initializer_list<U> &, Args &&...>::value> * =
nullptr>
1545 ctor_base(detail_expected::default_constructor_tag{}) {}
1547 template <
class G = E,
1554 ctor_base(detail_expected::default_constructor_tag{}) {}
1563 ctor_base(detail_expected::default_constructor_tag{}) {}
1570 std::is_nothrow_constructible<E, G &&>::value)
1572 ctor_base(detail_expected::default_constructor_tag{}) {}
1579 std::is_nothrow_constructible<E, G &&>::value)
1581 ctor_base(detail_expected::default_constructor_tag{}) {}
1583 template <
class... Args,
1588 ctor_base(detail_expected::default_constructor_tag{}) {}
1590 template <
class U,
class... Args,
1592 E, std::initializer_list<U> &, Args &&...>::value> * =
nullptr>
1596 ctor_base(detail_expected::default_constructor_tag{}) {}
1598 template <
class U,
class G,
1600 std::is_convertible<G const &, E>::value)> * =
1605 :
ctor_base(detail_expected::default_constructor_tag{}) {
1607 this->construct(*rhs);
1609 this->construct_error(rhs.error());
1613 template <
class U,
class G,
1615 std::is_convertible<G const &, E>::value)> * =
1620 :
ctor_base(detail_expected::default_constructor_tag{}) {
1622 this->construct(*rhs);
1624 this->construct_error(rhs.error());
1631 std::is_convertible<G &&, E>::value)> * =
nullptr,
1634 :
ctor_base(detail_expected::default_constructor_tag{}) {
1635 if (rhs.has_value()) {
1636 this->construct(std::move(*rhs));
1638 this->construct_error(std::move(rhs.error()));
1645 std::is_convertible<G &&, E>::value)> * =
nullptr,
1648 :
ctor_base(detail_expected::default_constructor_tag{}) {
1649 if (rhs.has_value()) {
1650 this->construct(std::move(*rhs));
1652 this->construct_error(std::move(rhs.error()));
1671 class U = T,
class G = T,
1678 std::is_same<T, detail_expected::decay_t<U>>>::value &&
1679 std::is_constructible<T, U>::value &&
1680 std::is_assignable<G &, U>::value &&
1681 std::is_nothrow_move_constructible<E>::value)> * =
nullptr>
1684 val() = std::forward<U>(v);
1686 err().~unexpected<E>();
1687 ::new (valptr()) T(std::forward<U>(v));
1688 this->m_has_val =
true;
1695 class U = T,
class G = T,
1702 std::is_same<T, detail_expected::decay_t<U>>>::value &&
1703 std::is_constructible<T, U>::value &&
1704 std::is_assignable<G &, U>::value &&
1705 std::is_nothrow_move_constructible<E>::value)> * =
nullptr>
1708 val() = std::forward<U>(v);
1710 auto tmp = std::move(err());
1711 err().~unexpected<E>();
1713#ifdef WPI_EXPECTED_EXCEPTIONS_ENABLED
1715 ::new (valptr()) T(std::forward<U>(v));
1716 this->m_has_val =
true;
1718 err() = std::move(tmp);
1722 ::new (valptr()) T(std::forward<U>(v));
1723 this->m_has_val =
true;
1730 template <
class G = E,
1732 std::is_assignable<G &, G>::value> * =
nullptr>
1737 this->destroy_val();
1739 this->m_has_val =
false;
1745 template <
class G = E,
1747 std::is_move_assignable<G>::value> * =
nullptr>
1750 err() = std::move(rhs);
1752 this->destroy_val();
1754 this->m_has_val =
false;
1761 T, Args &&...>::value> * =
nullptr>
1766 err().~unexpected<E>();
1767 this->m_has_val =
true;
1769 ::new (valptr()) T(std::forward<Args>(args)...);
1773 T, Args &&...>::value> * =
nullptr>
1777 ::new (valptr()) T(std::forward<Args>(args)...);
1779 auto tmp = std::move(err());
1780 err().~unexpected<E>();
1782#ifdef WPI_EXPECTED_EXCEPTIONS_ENABLED
1784 ::new (valptr()) T(std::forward<Args>(args)...);
1785 this->m_has_val =
true;
1787 err() = std::move(tmp);
1791 ::new (valptr()) T(std::forward<Args>(args)...);
1792 this->m_has_val =
true;
1797 template <
class U,
class... Args,
1799 T, std::initializer_list<U> &, Args &&...>::value> * =
nullptr>
1800 void emplace(std::initializer_list<U> il, Args &&...args) {
1802 T t(il, std::forward<Args>(args)...);
1803 val() = std::move(t);
1805 err().~unexpected<E>();
1806 ::new (valptr()) T(il, std::forward<Args>(args)...);
1807 this->m_has_val =
true;
1811 template <
class U,
class... Args,
1813 T, std::initializer_list<U> &, Args &&...>::value> * =
nullptr>
1814 void emplace(std::initializer_list<U> il, Args &&...args) {
1816 T t(il, std::forward<Args>(args)...);
1817 val() = std::move(t);
1819 auto tmp = std::move(err());
1820 err().~unexpected<E>();
1822#ifdef WPI_EXPECTED_EXCEPTIONS_ENABLED
1824 ::new (valptr()) T(il, std::forward<Args>(args)...);
1825 this->m_has_val =
true;
1827 err() = std::move(tmp);
1831 ::new (valptr()) T(il, std::forward<Args>(args)...);
1832 this->m_has_val =
true;
1838 using t_is_void = std::true_type;
1839 using t_is_not_void = std::false_type;
1840 using t_is_nothrow_move_constructible = std::true_type;
1841 using move_constructing_t_can_throw = std::false_type;
1842 using e_is_nothrow_move_constructible = std::true_type;
1843 using move_constructing_e_can_throw = std::false_type;
1845 void swap_where_both_have_value(
expected & , t_is_void)
noexcept {
1849 void swap_where_both_have_value(expected &rhs, t_is_not_void) {
1851 swap(val(), rhs.val());
1854 void swap_where_only_one_has_value(expected &rhs, t_is_void)
noexcept(
1855 std::is_nothrow_move_constructible<E>::value) {
1856 ::new (errptr()) unexpected_type(
std::move(rhs.err()));
1857 rhs.err().~unexpected_type();
1858 std::swap(this->m_has_val, rhs.m_has_val);
1861 void swap_where_only_one_has_value(expected &rhs, t_is_not_void) {
1862 swap_where_only_one_has_value_and_t_is_not_void(
1863 rhs,
typename std::is_nothrow_move_constructible<T>::type{},
1864 typename std::is_nothrow_move_constructible<E>::type{});
1867 void swap_where_only_one_has_value_and_t_is_not_void(
1868 expected &rhs, t_is_nothrow_move_constructible,
1869 e_is_nothrow_move_constructible)
noexcept {
1870 auto temp = std::move(val());
1872 ::new (errptr()) unexpected_type(
std::move(rhs.err()));
1873 rhs.err().~unexpected_type();
1874 ::new (rhs.valptr()) T(
std::move(temp));
1875 std::swap(this->m_has_val, rhs.m_has_val);
1878 void swap_where_only_one_has_value_and_t_is_not_void(
1879 expected &rhs, t_is_nothrow_move_constructible,
1880 move_constructing_e_can_throw) {
1881 auto temp = std::move(val());
1883#ifdef WPI_EXPECTED_EXCEPTIONS_ENABLED
1885 ::new (errptr()) unexpected_type(
std::move(rhs.err()));
1886 rhs.err().~unexpected_type();
1887 ::new (rhs.valptr()) T(
std::move(temp));
1888 std::swap(this->m_has_val, rhs.m_has_val);
1890 val() = std::move(temp);
1894 ::new (errptr()) unexpected_type(
std::move(rhs.err()));
1895 rhs.err().~unexpected_type();
1896 ::new (rhs.valptr()) T(
std::move(temp));
1897 std::swap(this->m_has_val, rhs.m_has_val);
1901 void swap_where_only_one_has_value_and_t_is_not_void(
1902 expected &rhs, move_constructing_t_can_throw,
1903 e_is_nothrow_move_constructible) {
1904 auto temp = std::move(rhs.err());
1905 rhs.err().~unexpected_type();
1906#ifdef WPI_EXPECTED_EXCEPTIONS_ENABLED
1908 ::new (rhs.valptr()) T(
std::move(val()));
1910 ::new (errptr()) unexpected_type(
std::move(temp));
1911 std::swap(this->m_has_val, rhs.m_has_val);
1913 rhs.err() = std::move(temp);
1917 ::new (rhs.valptr()) T(
std::move(val()));
1919 ::new (errptr()) unexpected_type(
std::move(temp));
1920 std::swap(this->m_has_val, rhs.m_has_val);
1925 template <
class OT = T,
class OE = E>
1926 detail_expected::enable_if_t<detail_expected::is_swappable<OT>::value &&
1927 detail_expected::is_swappable<OE>::value &&
1928 (std::is_nothrow_move_constructible<OT>::value ||
1929 std::is_nothrow_move_constructible<OE>::value)>
1931 std::is_nothrow_move_constructible<T>::value
1933 &&std::is_nothrow_move_constructible<E>::value
1935 if (has_value() && rhs.has_value()) {
1936 swap_where_both_have_value(rhs,
typename std::is_void<T>::type{});
1937 }
else if (!has_value() && rhs.has_value()) {
1939 }
else if (has_value()) {
1940 swap_where_only_one_has_value(rhs,
typename std::is_void<T>::type{});
1943 swap(err(), rhs.err());
1956 template <
class U = T,
1962 template <
class U = T,
1968 template <
class U = T,
1972 return std::move(val());
1974 template <
class U = T,
1978 return std::move(val());
1981 constexpr bool has_value() const noexcept {
return this->m_has_val; }
1982 constexpr explicit operator bool() const noexcept {
return this->m_has_val; }
1984 template <
class U = T,
1991 template <
class U = T,
1998 template <
class U = T,
2003 return std::move(val());
2005 template <
class U = T,
2010 return std::move(val());
2015 return err().value();
2019 return err().value();
2023 return std::move(err().value());
2027 return std::move(err().value());
2030 template <
class U>
constexpr T
value_or(U &&v)
const & {
2031 static_assert(std::is_copy_constructible<T>::value &&
2032 std::is_convertible<U &&, T>::value,
2033 "T must be copy-constructible and convertible to from U&&");
2034 return bool(*
this) ? **this :
static_cast<T
>(std::forward<U>(v));
2037 static_assert(std::is_move_constructible<T>::value &&
2038 std::is_convertible<U &&, T>::value,
2039 "T must be move-constructible and convertible to from U&&");
2040 return bool(*
this) ? std::move(**
this) :
static_cast<T
>(std::forward<U>(v));
2044namespace detail_expected {
2049#ifdef WPI_EXPECTED_CXX14
2050template <
class Exp,
class F,
2052 class Ret =
decltype(detail_expected::invoke(std::declval<F>(),
2053 *std::declval<Exp>()))>
2057 return exp.has_value()
2058 ? detail_expected::invoke(std::forward<F>(f), *std::forward<Exp>(
exp))
2062template <
class Exp,
class F,
2064 class Ret =
decltype(detail_expected::invoke(std::declval<F>()))>
2065constexpr auto and_then_impl(Exp &&
exp, F &&f) {
2068 return exp.has_value() ? detail_expected::invoke(std::forward<F>(f))
2072template <
class>
struct TC;
2073template <
class Exp,
class F,
2074 class Ret =
decltype(detail_expected::invoke(std::declval<F>(),
2075 *std::declval<Exp>())),
2080 return exp.has_value()
2081 ? detail_expected::invoke(std::forward<F>(f), *std::forward<Exp>(
exp))
2085template <
class Exp,
class F,
2086 class Ret =
decltype(detail_expected::invoke(std::declval<F>())),
2091 return exp.has_value() ? detail_expected::invoke(std::forward<F>(f))
2096#ifdef WPI_EXPECTED_CXX14
2097template <
class Exp,
class F,
2099 class Ret =
decltype(detail_expected::invoke(std::declval<F>(),
2100 *std::declval<Exp>())),
2102constexpr auto expected_map_impl(Exp &&
exp, F &&f) {
2103 using result = ret_t<Exp, detail_expected::decay_t<Ret>>;
2104 return exp.has_value() ? result(detail_expected::invoke(std::forward<F>(f),
2105 *std::forward<Exp>(
exp)))
2109template <
class Exp,
class F,
2110 detail_expected::enable_if_t<!std::is_void<exp_t<Exp>>::value> * =
nullptr,
2111 class Ret =
decltype(detail_expected::invoke(std::declval<F>(),
2112 *std::declval<Exp>())),
2113 detail_expected::enable_if_t<std::is_void<Ret>::value> * =
nullptr>
2114auto expected_map_impl(Exp &&
exp, F &&f) {
2115 using result = expected<void, err_t<Exp>>;
2116 if (
exp.has_value()) {
2117 detail_expected::invoke(std::forward<F>(f), *std::forward<Exp>(
exp));
2121 return result(unexpect, std::forward<Exp>(
exp).
error());
2124template <
class Exp,
class F,
2125 detail_expected::enable_if_t<std::is_void<exp_t<Exp>>::value> * =
nullptr,
2126 class Ret =
decltype(detail_expected::invoke(std::declval<F>())),
2127 detail_expected::enable_if_t<!std::is_void<Ret>::value> * =
nullptr>
2129 using result = ret_t<Exp, detail_expected::decay_t<Ret>>;
2130 return exp.has_value() ? result(detail_expected::invoke(std::forward<F>(f)))
2134template <
class Exp,
class F,
2135 detail_expected::enable_if_t<std::is_void<exp_t<Exp>>::value> * =
nullptr,
2136 class Ret =
decltype(detail_expected::invoke(std::declval<F>())),
2137 detail_expected::enable_if_t<std::is_void<Ret>::value> * =
nullptr>
2139 using result = expected<void, err_t<Exp>>;
2140 if (
exp.has_value()) {
2141 detail_expected::invoke(std::forward<F>(f));
2145 return result(unexpect, std::forward<Exp>(
exp).
error());
2148template <
class Exp,
class F,
2149 detail_expected::enable_if_t<!std::is_void<exp_t<Exp>>::value> * =
nullptr,
2150 class Ret =
decltype(detail_expected::invoke(std::declval<F>(),
2151 *std::declval<Exp>())),
2152 detail_expected::enable_if_t<!std::is_void<Ret>::value> * =
nullptr>
2158 return exp.
has_value() ? result(detail_expected::invoke(std::forward<F>(f),
2159 *std::forward<Exp>(
exp)))
2160 : result(
unexpect, std::forward<Exp>(
exp).error());
2163template <
class Exp,
class F,
2165 class Ret =
decltype(detail_expected::invoke(std::declval<F>(),
2166 *std::declval<Exp>())),
2170 if (
exp.has_value()) {
2171 detail_expected::invoke(std::forward<F>(f), *std::forward<Exp>(
exp));
2178template <
class Exp,
class F,
2180 class Ret =
decltype(detail_expected::invoke(std::declval<F>())),
2183constexpr auto expected_map_impl(Exp &&
exp, F &&f)
2184 -> ret_t<Exp, detail_expected::decay_t<Ret>> {
2185 using result = ret_t<Exp, detail_expected::decay_t<Ret>>;
2187 return exp.has_value() ? result(detail_expected::invoke(std::forward<F>(f)))
2191template <
class Exp,
class F,
2192 detail_expected::enable_if_t<std::is_void<exp_t<Exp>>::value> * =
nullptr,
2193 class Ret =
decltype(detail_expected::invoke(std::declval<F>())),
2194 detail_expected::enable_if_t<std::is_void<Ret>::value> * =
nullptr>
2196auto expected_map_impl(Exp &&
exp, F &&f) -> expected<void, err_t<Exp>> {
2197 if (
exp.has_value()) {
2198 detail_expected::invoke(std::forward<F>(f));
2202 return unexpected<err_t<Exp>>(std::forward<Exp>(
exp).error());
2206#if defined(WPI_EXPECTED_CXX14) && !defined(WPI_EXPECTED_GCC49) && \
2207 !defined(WPI_EXPECTED_GCC54) && !defined(WPI_EXPECTED_GCC55)
2208template <
class Exp,
class F,
2209 detail_expected::enable_if_t<!std::is_void<exp_t<Exp>>::value> * =
nullptr,
2210 class Ret =
decltype(detail_expected::invoke(std::declval<F>(),
2211 std::declval<Exp>().
error())),
2212 detail_expected::enable_if_t<!std::is_void<Ret>::value> * =
nullptr>
2214 using result = expected<exp_t<Exp>, detail_expected::decay_t<Ret>>;
2215 return exp.has_value()
2216 ? result(*std::forward<Exp>(
exp))
2220template <
class Exp,
class F,
2221 detail_expected::enable_if_t<!std::is_void<exp_t<Exp>>::value> * =
nullptr,
2222 class Ret =
decltype(detail_expected::invoke(std::declval<F>(),
2223 std::declval<Exp>().
error())),
2224 detail_expected::enable_if_t<std::is_void<Ret>::value> * =
nullptr>
2226 using result = expected<exp_t<Exp>,
monostate>;
2227 if (
exp.has_value()) {
2228 return result(*std::forward<Exp>(
exp));
2231 detail_expected::invoke(std::forward<F>(f), std::forward<Exp>(
exp).
error());
2234template <
class Exp,
class F,
2235 detail_expected::enable_if_t<std::is_void<exp_t<Exp>>::value> * =
nullptr,
2236 class Ret =
decltype(detail_expected::invoke(std::declval<F>(),
2237 std::declval<Exp>().
error())),
2238 detail_expected::enable_if_t<!std::is_void<Ret>::value> * =
nullptr>
2240 using result = expected<exp_t<Exp>, detail_expected::decay_t<Ret>>;
2241 return exp.has_value()
2246template <
class Exp,
class F,
2247 detail_expected::enable_if_t<std::is_void<exp_t<Exp>>::value> * =
nullptr,
2248 class Ret =
decltype(detail_expected::invoke(std::declval<F>(),
2249 std::declval<Exp>().
error())),
2250 detail_expected::enable_if_t<std::is_void<Ret>::value> * =
nullptr>
2252 using result = expected<exp_t<Exp>,
monostate>;
2253 if (
exp.has_value()) {
2257 detail_expected::invoke(std::forward<F>(f), std::forward<Exp>(
exp).
error());
2261template <
class Exp,
class F,
2262 detail_expected::enable_if_t<!std::is_void<exp_t<Exp>>::value> * =
nullptr,
2263 class Ret =
decltype(detail_expected::invoke(std::declval<F>(),
2264 std::declval<Exp>().
error())),
2265 detail_expected::enable_if_t<!std::is_void<Ret>::value> * =
nullptr>
2271 ? result(*std::forward<Exp>(
exp))
2272 : result(
unexpect, detail_expected::invoke(std::forward<F>(f),
2273 std::forward<Exp>(
exp).error()));
2276template <
class Exp,
class F,
2278 class Ret =
decltype(detail_expected::invoke(std::declval<F>(),
2279 std::declval<Exp>().error())),
2283 if (
exp.has_value()) {
2284 return result(*std::forward<Exp>(
exp));
2287 detail_expected::invoke(std::forward<F>(f), std::forward<Exp>(
exp).error());
2291template <
class Exp,
class F,
2293 class Ret =
decltype(detail_expected::invoke(std::declval<F>(),
2294 std::declval<Exp>().error())),
2296constexpr auto map_error_impl(Exp &&
exp, F &&f)
2302 : result(
unexpect, detail_expected::invoke(
std::forward<F>(f),
2303 std::forward<Exp>(
exp).error()));
2306template <
class Exp,
class F,
2307 detail_expected::enable_if_t<std::is_void<exp_t<Exp>>::value> * =
nullptr,
2308 class Ret =
decltype(detail_expected::invoke(std::declval<F>(),
2309 std::declval<Exp>().error())),
2310 detail_expected::enable_if_t<std::is_void<Ret>::value> * =
nullptr>
2311auto map_error_impl(Exp &&
exp, F &&f) -> expected<exp_t<Exp>,
monostate> {
2312 using result = expected<exp_t<Exp>,
monostate>;
2313 if (
exp.has_value()) {
2317 detail_expected::invoke(std::forward<F>(f), std::forward<Exp>(
exp).
error());
2322#ifdef WPI_EXPECTED_CXX14
2323template <
class Exp,
class F,
2324 class Ret =
decltype(detail_expected::invoke(std::declval<F>(),
2325 std::declval<Exp>().
error())),
2326 detail_expected::enable_if_t<!std::is_void<Ret>::value> * =
nullptr>
2328 static_assert(detail_expected::is_expected<Ret>::value,
"F must return an expected");
2329 return exp.has_value() ? std::forward<Exp>(
exp)
2334template <
class Exp,
class F,
2335 class Ret =
decltype(detail_expected::invoke(std::declval<F>(),
2336 std::declval<Exp>().
error())),
2337 detail_expected::enable_if_t<std::is_void<Ret>::value> * =
nullptr>
2339 return exp.has_value() ? std::forward<Exp>(
exp)
2345template <
class Exp,
class F,
2346 class Ret =
decltype(detail_expected::invoke(std::declval<F>(),
2347 std::declval<Exp>().
error())),
2348 detail_expected::enable_if_t<!std::is_void<Ret>::value> * =
nullptr>
2351 return exp.has_value() ? std::forward<Exp>(
exp)
2352 : detail_expected::invoke(std::forward<F>(f),
2353 std::forward<Exp>(
exp).error());
2356template <
class Exp,
class F,
2357 class Ret =
decltype(detail_expected::invoke(std::declval<F>(),
2358 std::declval<Exp>().error())),
2361 return exp.has_value() ? std::forward<Exp>(
exp)
2362 : (detail_expected::invoke(std::forward<F>(f),
2363 std::forward<Exp>(
exp).error()),
2364 std::forward<Exp>(
exp));
2369template <
class T,
class E,
class U,
class F>
2376template <
class T,
class E,
class U,
class F>
2383template <
class E,
class F>
2390template <
class E,
class F>
2398template <
class T,
class E,
class U>
2402template <
class T,
class E,
class U>
2406template <
class T,
class E,
class U>
2410template <
class T,
class E,
class U>
2415template <
class T,
class E>
2419template <
class T,
class E>
2423template <
class T,
class E>
2427template <
class T,
class E>
2432template <
class T,
class E,
2433 detail_expected::enable_if_t<(std::is_void<T>::value ||
2434 std::is_move_constructible<T>::value) &&
2435 detail_expected::is_swappable<T>::value &&
2436 std::is_move_constructible<E>::value &&
2437 detail_expected::is_swappable<E>::value> * =
nullptr>
const E & error() const &
Definition expected:1230
bad_expected_access(E e)
Definition expected:1224
E && error() &&
Definition expected:1233
const E && error() const &&
Definition expected:1232
E & error() &
Definition expected:1231
virtual const char * what() const noexcept override
Definition expected:1226
An expected<T, E> object is an object that contains the storage for another object and manages the li...
Definition expected:1250
constexpr expected(unexpect_t, Args &&...args)
Definition expected:1586
constexpr expected(const expected &rhs)=default
expected & operator=(const expected &rhs)=default
WPI_EXPECTED_11_CONSTEXPR U & value() &
Definition expected:1993
constexpr expected(unexpected< G > const &e)
Definition expected:1561
constexpr expected(unexpect_t, std::initializer_list< U > il, Args &&...args)
Definition expected:1593
WPI_EXPECTED_11_CONSTEXPR decltype(map_error_impl(std::declval< expected & >(), std::declval< F && >())) transform_error(F &&f) &
Definition expected:1485
WPI_EXPECTED_11_CONSTEXPR E & error() &
Definition expected:2017
WPI_EXPECTED_11_CONSTEXPR decltype(map_error_impl(std::declval< expected & >(), std::declval< F && >())) map_error(F &&f) &
Definition expected:1442
constexpr const E & error() const &
Definition expected:2013
WPI_EXPECTED_11_CONSTEXPR const U && value() const &&
Definition expected:2000
constexpr bool has_value() const noexcept
Definition expected:1981
constexpr decltype(expected_map_impl(std::declval< const expected & >(), std::declval< F && >())) transform(F &&f) const &
Definition expected:1410
expected & operator=(expected &&rhs)=default
WPI_EXPECTED_11_CONSTEXPR U && operator*() &&
Definition expected:1976
E error_type
Definition expected:1287
WPI_EXPECTED_MSVC2015_CONSTEXPR expected(U &&v)
Definition expected:1660
constexpr decltype(map_error_impl(std::declval< const expected && >(), std::declval< F && >())) map_error(F &&f) const &&
Definition expected:1462
expected WPI_EXPECTED_11_CONSTEXPR or_else(F &&f) &&
Definition expected:1514
WPI_EXPECTED_11_CONSTEXPR const U & value() const &
Definition expected:1986
WPI_EXPECTED_11_CONSTEXPR decltype(expected_map_impl(std::declval< expected >(), std::declval< F && >())) transform(F &&f) &&
Definition expected:1404
expected & operator=(U &&v)
Definition expected:1682
WPI_EXPECTED_11_CONSTEXPR expected(const expected< U, G > &rhs)
Definition expected:1604
unexpected< E > unexpected_type
Definition expected:1288
constexpr decltype(expected_map_impl(std::declval< const expected & >(), std::declval< F && >())) map(F &&f) const &
Definition expected:1366
constexpr auto and_then(F &&f) const &-> decltype(and_then_impl(std::declval< expected const & >(), std::forward< F >(f)))
Definition expected:1322
void emplace(Args &&...args)
Definition expected:1762
WPI_EXPECTED_11_CONSTEXPR decltype(map_error_impl(std::declval< expected && >(), std::declval< F && >())) transform_error(F &&f) &&
Definition expected:1491
constexpr decltype(map_error_impl(std::declval< const expected && >(), std::declval< F && >())) transform_error(F &&f) const &&
Definition expected:1505
detail_expected::enable_if_t< detail_expected::is_swappable< OT >::value &&detail_expected::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_expected::is_nothrow_swappable< T >::value &&std::is_nothrow_move_constructible< E >::value &&detail_expected::is_nothrow_swappable< E >::value)
Definition expected:1930
constexpr decltype(expected_map_impl(std::declval< const expected && >(), std::declval< F && >())) transform(F &&f) const &&
Definition expected:1418
WPI_EXPECTED_11_CONSTEXPR U && value() &&
Definition expected:2007
constexpr const U && operator*() const &&
Definition expected:1970
WPI_EXPECTED_11_CONSTEXPR expected(expected< U, G > &&rhs)
Definition expected:1633
constexpr expected(in_place_t, std::initializer_list< U > il, Args &&...args)
Definition expected:1543
void emplace(std::initializer_list< U > il, Args &&...args)
Definition expected:1800
WPI_EXPECTED_11_CONSTEXPR decltype(expected_map_impl(std::declval< expected & >(), std::declval< F && >())) map(F &&f) &
Definition expected:1354
expected & operator=(unexpected< G > &&rhs) noexcept
Definition expected:1748
expected constexpr or_else(F &&f) const &&
Definition expected:1523
constexpr auto and_then(F &&f) const &&-> decltype(and_then_impl(std::declval< expected const && >(), std::forward< F >(f)))
Definition expected:1329
expected & operator=(const unexpected< G > &rhs)
Definition expected:1733
constexpr decltype(map_error_impl(std::declval< const expected & >(), std::declval< F && >())) transform_error(F &&f) const &
Definition expected:1497
WPI_EXPECTED_11_CONSTEXPR decltype(expected_map_impl(std::declval< expected & >(), std::declval< F && >())) transform(F &&f) &
Definition expected:1398
WPI_EXPECTED_11_CONSTEXPR decltype(expected_map_impl(std::declval< expected >(), std::declval< F && >())) map(F &&f) &&
Definition expected:1360
constexpr expected(in_place_t, Args &&...args)
Definition expected:1536
WPI_EXPECTED_11_CONSTEXPR E && error() &&
Definition expected:2025
T value_type
Definition expected:1286
WPI_EXPECTED_11_CONSTEXPR T * operator->()
Definition expected:1951
constexpr expected()=default
constexpr T value_or(U &&v) const &
Definition expected:2030
WPI_EXPECTED_11_CONSTEXPR T value_or(U &&v) &&
Definition expected:2036
constexpr const U & operator*() const &
Definition expected:1958
WPI_EXPECTED_11_CONSTEXPR auto and_then(F &&f) &-> decltype(and_then_impl(std::declval< expected & >(), std::forward< F >(f)))
Definition expected:1311
WPI_EXPECTED_11_CONSTEXPR decltype(map_error_impl(std::declval< expected && >(), std::declval< F && >())) map_error(F &&f) &&
Definition expected:1448
constexpr expected(unexpected< G > &&e) noexcept(std::is_nothrow_constructible< E, G && >::value)
Definition expected:1569
WPI_EXPECTED_11_CONSTEXPR auto and_then(F &&f) &&-> decltype(and_then_impl(std::declval< expected && >(), std::forward< F >(f)))
Definition expected:1317
constexpr const E && error() const &&
Definition expected:2021
expected WPI_EXPECTED_11_CONSTEXPR or_else(F &&f) &
Definition expected:1510
expected constexpr or_else(F &&f) const &
Definition expected:1518
constexpr expected(expected &&rhs)=default
constexpr const T * operator->() const
Definition expected:1947
WPI_EXPECTED_11_CONSTEXPR U & operator*() &
Definition expected:1964
constexpr expected(const unexpected< G > &e)
Definition expected:1552
constexpr decltype(expected_map_impl(std::declval< const expected && >(), std::declval< F && >())) map(F &&f) const &&
Definition expected:1374
constexpr decltype(map_error_impl(std::declval< const expected & >(), std::declval< F && >())) map_error(F &&f) const &
Definition expected:1454
constexpr unexpected(const E &e)
Definition expected:147
constexpr const E & value() const &
Definition expected:162
constexpr const E && value() const &&
Definition expected:165
constexpr unexpected(E &&e)
Definition expected:149
constexpr unexpected(std::initializer_list< U > l, Args &&...args)
Definition expected:159
WPI_EXPECTED_11_CONSTEXPR E & value() &
Definition expected:163
constexpr unexpected(Args &&...args)
Definition expected:153
WPI_EXPECTED_11_CONSTEXPR E && value() &&
Definition expected:164
#define WPI_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T)
Definition expected:104
#define WPI_EXPECTED_MSVC2015_CONSTEXPR
Definition expected:36
#define WPI_EXPECTED_11_CONSTEXPR
Definition expected:126
#define WPI_EXPECTED_IS_TRIVIALLY_DESTRUCTIBLE(T)
Definition expected:108
#define WPI_ASSERT(x)
Definition expected:60
#define WPI_EXPECTED_IS_TRIVIALLY_COPY_ASSIGNABLE(T)
Definition expected:106
bool operator==(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
Definition json_pointer.h:931
bool operator!=(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
Definition json_pointer.h:956
Allocating channel that is out of range Attempted to reuse an allocated resource A pointer parameter to a method is nullptr Compass manufacturer doesn t match HiTechnic The object is in an incompatible mode Attempted to read AnalogTrigger pulse output Task error
Definition Errors.h:23
Implement std::hash so that hash_code can be used in STL containers.
Definition PointerIntPair.h:280
WPI_BASIC_JSON_TPL_DECLARATION void swap(wpi::WPI_BASIC_JSON_TPL &j1, wpi::WPI_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name, cert-dcl58-cpp) is_nothrow_move_constructible< wpi::WPI_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression, cppcoreguidelines-noexcept-swap, performance-noexcept-swap) is_nothrow_move_assignable< wpi::WPI_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
Definition json.h:5258
std::false_type can_swap(...) noexcept(false)
std::false_type uses_std(...)
typename std::remove_const< T >::type remove_const_t
Definition expected:228
typename std::remove_reference< T >::type remove_reference_t
Definition expected:230
typename invoke_result< F, Us... >::type invoke_result_t
Definition expected:317
auto and_then_impl(Exp &&exp, F &&f) -> Ret
Definition expected:2077
typename detail_expected::decay_t< Exp >::value_type exp_t
Definition expected:2045
detail_expected::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:405
typename std::conditional< B, T, F >::type conditional_t
Definition expected:235
typename std::decay< T >::type decay_t
Definition expected:231
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:287
detail_expected::enable_if_t< std::is_constructible< T, U && >::value && !std::is_same< detail_expected::decay_t< U >, in_place_t >::value && !std::is_same< expected< T, E >, detail_expected::decay_t< U > >::value && !std::is_same< unexpected< E >, detail_expected::decay_t< U > >::value > expected_enable_forward_value
Definition expected:398
constexpr auto expected_map_impl(Exp &&exp, F &&f) -> ret_t< Exp, detail_expected::decay_t< Ret > >
Definition expected:2154
is_void_or< T, std::is_copy_assignable< T > > is_copy_assignable_or_void
Definition expected:429
static constexpr no_init_t no_init
Definition expected:438
is_void_or< T, std::is_copy_constructible< T > > is_copy_constructible_or_void
Definition expected:421
conditional_t< std::is_void< T >::value, std::true_type, U > is_void_or
Definition expected:418
is_void_or< T, std::is_move_assignable< T > > is_move_assignable_or_void
Definition expected:432
typename std::enable_if< E, T >::type enable_if_t
Definition expected:233
WPI_EXPECTED_11_CONSTEXPR void throw_exception(E &&e)
Definition expected:212
is_void_or< T, std::is_move_constructible< T > > is_move_constructible_or_void
Definition expected:425
typename detail_expected::decay_t< Exp >::error_type err_t
Definition expected:2046
auto or_else_impl(Exp &&exp, F &&f) -> Ret
Definition expected:2349
constexpr auto map_error_impl(Exp &&exp, F &&f) -> expected< exp_t< Exp >, detail_expected::decay_t< Ret > >
Definition expected:2266
void construct(std::true_type, T *cur, T *end, Args &&... args)
Definition smart_ptr.hpp:45
T && forward(typename std::remove_reference< T >::type &t) noexcept
Definition utility.hpp:31
Foonathan namespace.
Definition ntcore_cpp.h:26
constexpr bool operator>(const unexpected< E > &lhs, const unexpected< E > &rhs)
Definition expected:192
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
Definition PointerIntPair.h:270
unexpected< typename std::decay< E >::type > make_unexpected(E &&e)
Definition expected:201
constexpr bool operator<(const unexpected< E > &lhs, const unexpected< E > &rhs)
Definition expected:184
constexpr bool operator<=(const unexpected< E > &lhs, const unexpected< E > &rhs)
Definition expected:188
static constexpr unexpect_t unexpect
Definition expected:208
bool operator==(const DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT > &LHS, const DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT > &RHS)
Equality comparison for DenseMap.
Definition DenseMap.h:729
static constexpr in_place_t in_place
Definition expected:139
constexpr bool operator>=(const unexpected< E > &lhs, const unexpected< E > &rhs)
Definition expected:196
bool operator!=(const DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT > &LHS, const DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT > &RHS)
Inequality comparison for DenseMap.
Definition DenseMap.h:749
constexpr default_constructor_tag()=default
expected_copy_assign_base()=default
expected_copy_assign_base & operator=(const expected_copy_assign_base &rhs)
Definition expected:1020
expected_copy_assign_base(expected_copy_assign_base &&rhs)=default
expected_copy_assign_base(const expected_copy_assign_base &rhs)=default
expected_copy_assign_base & operator=(expected_copy_assign_base &&rhs)=default
expected_copy_base & operator=(expected_copy_base &&rhs)=default
expected_copy_base(expected_copy_base &&rhs)=default
expected_copy_base()=default
expected_copy_base(const expected_copy_base &rhs)
Definition expected:950
expected_copy_base & operator=(const expected_copy_base &rhs)=default
constexpr expected_default_ctor_base() noexcept=delete
constexpr expected_default_ctor_base() noexcept=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()=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(expected_delete_assign_base &&) noexcept=default
expected_delete_assign_base(const expected_delete_assign_base &)=default
expected_delete_assign_base()=default
expected_delete_ctor_base()=default
expected_delete_ctor_base(const expected_delete_ctor_base &)=delete
expected_delete_ctor_base(expected_delete_ctor_base &&) noexcept=delete
expected_delete_ctor_base()=default
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(expected_delete_ctor_base &&) noexcept=delete
expected_delete_ctor_base(const 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_delete_ctor_base()=default
expected_move_assign_base(const expected_move_assign_base &rhs)=default
expected_move_assign_base(expected_move_assign_base &&rhs)=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:1063
expected_move_assign_base()=default
expected_move_assign_base & operator=(const expected_move_assign_base &rhs)=default
expected_move_base(const expected_move_base &rhs)=default
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(expected_move_base &&rhs) noexcept(std::is_nothrow_move_constructible< T >::value)
Definition expected:986
void assign(Rhs &&rhs) noexcept
Definition expected:900
void construct_with(Rhs &&) noexcept
Definition expected:890
constexpr const unexpected< E > & geterr() const &
Definition expected:920
WPI_EXPECTED_11_CONSTEXPR void destroy_val()
Definition expected:930
WPI_EXPECTED_11_CONSTEXPR unexpected< E > & geterr() &
Definition expected:917
void construct() noexcept
Definition expected:886
void construct_error(Args &&...args) noexcept
Definition expected:894
WPI_EXPECTED_11_CONSTEXPR unexpected< E > && geterr() &&
Definition expected:921
bool has_value() const
Definition expected:915
constexpr const unexpected< E > && geterr() const &&
Definition expected:925
WPI_EXPECTED_11_CONSTEXPR unexpected< E > & geterr() &
Definition expected:864
constexpr const T && get() const &&
Definition expected:861
WPI_EXPECTED_11_CONSTEXPR void destroy_val()
Definition expected:877
void construct(Args &&...args) noexcept
Definition expected:700
WPI_EXPECTED_11_CONSTEXPR unexpected< E > && geterr() &&
Definition expected:868
void construct_error(Args &&...args) noexcept
Definition expected:710
bool has_value() const
Definition expected:855
void construct_with(Rhs &&rhs) noexcept
Definition expected:705
WPI_EXPECTED_11_CONSTEXPR T & get() &
Definition expected:857
void assign(expected_operations_base &&rhs) noexcept
Definition expected:828
void assign(const expected_operations_base &rhs) noexcept
Definition expected:819
constexpr const unexpected< E > & geterr() const &
Definition expected:867
constexpr const unexpected< E > && geterr() const &&
Definition expected:872
constexpr const T & get() const &
Definition expected:858
void assign_common(Rhs &&rhs)
Definition expected:840
WPI_EXPECTED_11_CONSTEXPR T && get() &&
Definition expected:859
constexpr expected_storage_base(no_init_t)
Definition expected:583
unexpected< E > m_unexpect
Definition expected:618
constexpr expected_storage_base(unexpect_t, std::initializer_list< U > il, Args &&...args)
Definition expected:606
constexpr expected_storage_base()
Definition expected:582
bool m_has_val
Definition expected:621
constexpr expected_storage_base(unexpect_t, Args &&...args)
Definition expected:600
~expected_storage_base()
Definition expected:611
T m_val
Definition expected:617
constexpr expected_storage_base(in_place_t, Args &&...args)
Definition expected:588
char m_no_init
Definition expected:619
constexpr expected_storage_base(in_place_t, std::initializer_list< U > il, Args &&...args)
Definition expected:594
char m_no_init
Definition expected:575
constexpr expected_storage_base(unexpect_t, std::initializer_list< U > il, Args &&...args)
Definition expected:561
WPI_EXPECTED_MSVC2015_CONSTEXPR expected_storage_base(no_init_t)
Definition expected:537
T m_val
Definition expected:573
~expected_storage_base()
Definition expected:566
constexpr expected_storage_base(unexpect_t, Args &&...args)
Definition expected:555
bool m_has_val
Definition expected:577
constexpr expected_storage_base(in_place_t, Args &&...args)
Definition expected:543
constexpr expected_storage_base(in_place_t, std::initializer_list< U > il, Args &&...args)
Definition expected:549
constexpr expected_storage_base()
Definition expected:536
unexpected< E > m_unexpect
Definition expected:574
~expected_storage_base()=default
bool m_has_val
Definition expected:531
constexpr expected_storage_base(unexpect_t, std::initializer_list< U > il, Args &&...args)
Definition expected:520
constexpr expected_storage_base(in_place_t, Args &&...args)
Definition expected:502
constexpr expected_storage_base(unexpect_t, Args &&...args)
Definition expected:514
constexpr expected_storage_base(no_init_t)
Definition expected:497
char m_no_init
Definition expected:529
constexpr expected_storage_base()
Definition expected:496
T m_val
Definition expected:527
constexpr expected_storage_base(in_place_t, std::initializer_list< U > il, Args &&...args)
Definition expected:508
unexpected< E > m_unexpect
Definition expected:528
char m_dummy
Definition expected:689
constexpr expected_storage_base(in_place_t)
Definition expected:665
constexpr expected_storage_base(unexpect_t, std::initializer_list< U > il, Args &&...args)
Definition expected:676
constexpr expected_storage_base(no_init_t)
Definition expected:663
bool m_has_val
Definition expected:691
constexpr expected_storage_base(unexpect_t, Args &&...args)
Definition expected:670
~expected_storage_base()
Definition expected:681
unexpected< E > m_unexpect
Definition expected:688
constexpr expected_storage_base()
Definition expected:662
constexpr expected_storage_base(unexpect_t, Args &&...args)
Definition expected:640
expected_storage_base()
Definition expected:631
constexpr expected_storage_base(unexpect_t, std::initializer_list< U > il, Args &&...args)
Definition expected:646
unexpected< E > m_unexpect
Definition expected:654
bool m_has_val
Definition expected:657
dummy m_val
Definition expected:655
constexpr expected_storage_base(in_place_t)
Definition expected:635
constexpr expected_storage_base(no_init_t)
Definition expected:633
~expected_storage_base()=default
constexpr expected_storage_base()
Definition expected:449
constexpr expected_storage_base(unexpect_t, std::initializer_list< U > il, Args &&...args)
Definition expected:473
bool m_has_val
Definition expected:490
constexpr expected_storage_base(no_init_t)
Definition expected:450
unexpected< E > m_unexpect
Definition expected:487
constexpr expected_storage_base(unexpect_t, Args &&...args)
Definition expected:467
constexpr expected_storage_base(in_place_t, std::initializer_list< U > il, Args &&...args)
Definition expected:461
T m_val
Definition expected:486
~expected_storage_base()
Definition expected:478
constexpr expected_storage_base(in_place_t, Args &&...args)
Definition expected:455
char m_no_init
Definition expected:488
decltype(detail_expected::invoke(std::declval< F >(), std::declval< Us >()...)) type
Definition expected:309
typename std::enable_if< B, T >::type enable_if_t
Definition base.h:297