10#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_RESULT_RESULT_HPP_
11#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_RESULT_RESULT_HPP_
19#include "arene/base/compiler_support/attributes.hpp"
20#include "arene/base/constraints/constraints.hpp"
21#include "arene/base/contracts/contract.hpp"
22#include "arene/base/functional/invoke.hpp"
23#include "arene/base/memory/construct_at.hpp"
24#include "arene/base/monostate/monostate.hpp"
25#include "arene/base/result/detail/in_place_error.hpp"
26#include "arene/base/result/detail/in_place_value.hpp"
27#include "arene/base/result/detail/result_base.hpp"
28#include "arene/base/stdlib_choice/addressof.hpp"
29#include "arene/base/stdlib_choice/cstddef.hpp"
30#include "arene/base/stdlib_choice/declval.hpp"
31#include "arene/base/stdlib_choice/enable_if.hpp"
32#include "arene/base/stdlib_choice/forward.hpp"
33#include "arene/base/stdlib_choice/hash.hpp"
34#include "arene/base/stdlib_choice/ignore.hpp"
35#include "arene/base/stdlib_choice/is_constructible.hpp"
36#include "arene/base/stdlib_choice/is_convertible.hpp"
37#include "arene/base/stdlib_choice/is_copy_assignable.hpp"
38#include "arene/base/stdlib_choice/is_copy_constructible.hpp"
39#include "arene/base/stdlib_choice/is_move_assignable.hpp"
40#include "arene/base/stdlib_choice/is_move_constructible.hpp"
41#include "arene/base/stdlib_choice/is_object.hpp"
42#include "arene/base/stdlib_choice/is_same.hpp"
43#include "arene/base/stdlib_choice/is_void.hpp"
44#include "arene/base/stdlib_choice/move.hpp"
45#include "arene/base/stdlib_choice/remove_const.hpp"
46#include "arene/base/stdlib_choice/remove_cv.hpp"
47#include "arene/base/stdlib_choice/remove_reference.hpp"
48#include "arene/base/type_manipulation/non_constructible_dummy.hpp"
49#include "arene/base/type_traits/all_of.hpp"
50#include "arene/base/type_traits/comparison_traits.hpp"
51#include "arene/base/type_traits/conditional.hpp"
52#include "arene/base/type_traits/decays_to.hpp"
53#include "arene/base/type_traits/has_overloaded_address_operator.hpp"
54#include "arene/base/type_traits/is_instantiation_of.hpp"
55#include "arene/base/type_traits/is_invocable.hpp"
56#include "arene/base/type_traits/is_swappable.hpp"
57#include "arene/base/type_traits/remove_cvref.hpp"
58#include "arene/base/utility/forward_like.hpp"
59#include "arene/base/utility/swap.hpp"
102template <
class T,
class E>
110 "The value type stored in result must not have an overloaded address-of operator"
116 using value_type = T;
120 using error_type = E;
125 "value_type must be an unqualified type, non-reference type."
129 "error_type must be an unqualified type, non-reference type."
135 "monostate as an error_type is not supported"
191 static constexpr bool is_copy_assignable{
210 if (&other !=
this) {
211 std::ignore = assign(other);
220 constexpr auto operator=(deleted_copy_assign_arg
const& other)
noexcept ->
result& =
delete;
224 static constexpr bool is_move_assignable{
243 std::ignore = assign(std::move(other));
251 constexpr auto operator=(deleted_move_assign_arg&& other)
noexcept ->
result& =
delete;
320 ARENE_PRECONDITION(
this->has_value());
321 return this->storage().unsafe_value();
330 ARENE_PRECONDITION(
this->has_value());
331 return this->storage().unsafe_value();
340 ARENE_PRECONDITION(
this->has_value());
341 return std::move(
this->storage().unsafe_value());
351 ARENE_PRECONDITION(
this->has_value());
352 return std::move(
this->storage().unsafe_value());
530 template <
typename F>
534 template <
typename F>
538 template <
typename F>
543 template <
typename F>
566 template <
typename F>
570 template <
typename F>
574 template <
typename F>
579 template <
typename F>
603 template <
typename F>
607 template <
typename F>
611 template <
typename F>
616 template <
typename F>
637 template <
typename F>
641 template <
typename F>
645 template <
typename F>
650 template <
typename F>
748 "The result returned from handle_value's error channel must be the same as this result's error channel"
775 "The result returned from handle_error's value channel must be the same as this result's value channel"
899 using value_type =
void;
903 using error_type = E;
908 "value_type must be an unqualified type, non-reference type."
912 "error_type must be an unqualified type, non-reference type."
918 "monostate as an error_type is not supported"
971 static constexpr bool is_copy_assignable{
988 if (&other !=
this) {
989 std::ignore = assign(other);
997 constexpr auto operator=(deleted_copy_assign_arg
const& other)
noexcept ->
result& =
delete;
1001 static constexpr bool is_move_assignable{
1018 std::ignore = assign(std::move(other));
1025 constexpr auto operator=(deleted_move_assign_arg&& other)
noexcept ->
result& =
delete;
1039 constexpr void operator*()
const&
noexcept {
return value(); }
1044 constexpr void value()
const&
noexcept { ARENE_PRECONDITION(
this->has_value()); }
1048 constexpr void value() &&
noexcept { ARENE_PRECONDITION(
this->has_value()); }
1059 ARENE_PRECONDITION(
this->has_error());
1060 return this->storage().unsafe_error();
1064 ARENE_PRECONDITION(
this->has_error());
1065 return this->storage().unsafe_error();
1069 ARENE_PRECONDITION(
this->has_error());
1070 return std::move(
this->storage().unsafe_error());
1075 ARENE_PRECONDITION(
this->has_error());
1076 return std::move(
this->storage().unsafe_error());
1149 this->discriminator() = result_detail::discriminator_type::holds_value;
1150 ::arene::base::construct_at(std::addressof(
this->storage().unsafe_value()), monostate{});
1174 template <
typename F>
1176 return result::and_then(*
this, std::forward<F>(handle_value));
1178 template <
typename F>
1180 return result::and_then(*
this, std::forward<F>(handle_value));
1182 template <
typename F>
1184 return result::and_then(std::move(*
this), std::forward<F>(handle_value));
1186 template <
typename F>
1188 return result::and_then(std::move(*
this), std::forward<F>(handle_value));
1211 template <
typename F>
1213 return result::or_else(*
this, std::forward<F>(handle_error));
1215 template <
typename F>
1217 return result::or_else(*
this, std::forward<F>(handle_error));
1219 template <
typename F>
1221 return result::or_else(std::move(*
this), std::forward<F>(handle_error));
1223 template <
typename F>
1224 constexpr auto or_else(F&& handle_error)
const&& {
1225 return result::or_else(std::move(*
this), std::forward<F>(handle_error));
1247 template <
typename F>
1249 return result::transform(*
this, std::forward<F>(handle_value));
1251 template <
typename F>
1253 return result::transform(*
this, std::forward<F>(handle_value));
1255 template <
typename F>
1257 return result::transform(std::move(*
this), std::forward<F>(handle_value));
1260 template <
typename F>
1262 return result::transform(std::move(*
this), std::forward<F>(handle_value));
1283 template <
typename F>
1285 return result::transform_error(*
this, std::forward<F>(handle_error));
1300 template <
typename F>
1302 return result::transform_error(*
this, std::forward<F>(handle_error));
1317 template <
typename F>
1319 return result::transform_error(std::move(*
this), std::forward<F>(handle_error));
1334 template <
typename F>
1336 return result::transform_error(std::move(*
this), std::forward<F>(handle_error));
1350 static_assert(is_equality_comparable_v<error_type>,
"Error type must be equality comparable");
1351 if (lhs.has_value()) {
1352 return rhs.has_value();
1354 return rhs.has_error(lhs.storage().unsafe_error());
1370 return !(lhs == rhs);
1425 "The result returned from handle_value's error channel must be the same as this result's error channel"
1449 "The result returned from handle_error's value channel must be the same as this result's value channel"
1586template <
typename ValueType>
1593 template <
typename Error>
1597 return {in_place_value, value_};
1601 template <
typename Error>
1605 return {in_place_value, std::move(value_)};
1655 template <
typename Error>
1671template <
typename ErrorType>
1678 template <
typename Value>
1682 return {in_place_error, error_};
1687 template <
typename Value>
1691 return {in_place_error, std::move(error_)};
1795template <
typename V,
typename E>
1796struct hash<::arene::base::result<V, E>> {
1806 return value.has_value() ? hash<V>{}(value.value()) : hash<E>{}(value.error());
1819template <
typename E>
Intermediary type for constructing a result with a given error_type .
Definition result.hpp:1672
constexpr operator result< Value, ErrorType >() const &noexcept(noexcept(result< Value, ErrorType >(in_place_error, std::declval< ErrorType const & >())))
Instantiates a result<Value,ErrorType> from the contained error instance.
Definition result.hpp:1680
constexpr error_result_t(error_result_t &&)=default
Move constructor.
~error_result_t()=default
destructor
constexpr operator result< Value, ErrorType >() &&noexcept(noexcept(result< Value, ErrorType >(in_place_error, std::declval< ErrorType && >())))
Instantiates a result<Value,ErrorType> from the contained error instance, moving the error value into...
Definition result.hpp:1689
constexpr auto operator=(error_result_t &&) -> error_result_t &=default
Move constructor.
constexpr auto operator=(error_result_t const &) -> error_result_t &=default
Copy assignment.
constexpr auto transform(F &&handle_value) const &
Calls a provided functor with the value channel if it is populated, and produces a new result with th...
Definition result.hpp:1252
~result()=default
Destroy the stored value or error.
ARENE_NODISCARD friend constexpr auto operator==(result const &lhs, result const &rhs) noexcept(noexcept(lhs.has_error(rhs.error()))) -> bool
Compare two results for equality.
Definition result.hpp:1347
constexpr auto or_else(F &&handle_error) const &&
Monadic API which invokes a functor with the contents of error() if the error channel is populated.
Definition result.hpp:1224
constexpr result()=default
Constructs a result with the value-channel engaged.
constexpr auto or_else(F &&handle_error) const &
Monadic API which invokes a functor with the contents of error() if the error channel is populated.
Definition result.hpp:1216
ARENE_NODISCARD constexpr auto error() &&noexcept -> error_type &&
Accesses a reference to the content of the error channel.
Definition result.hpp:1068
constexpr auto transform(F &&handle_value) &&
Calls a provided functor with the value channel if it is populated, and produces a new result with th...
Definition result.hpp:1256
constexpr auto and_then(F &&handle_value) const &
Monadic API which invokes a functor with the contents of value() if the value channel is populated.
Definition result.hpp:1179
constexpr auto and_then(F &&handle_value) const &&
Monadic API which invokes a functor with the contents of value() if the value channel is populated.
Definition result.hpp:1187
constexpr auto operator=(move_assign_arg &&other) noexcept -> result &
Move-assignment for the case that error_type satisfies std::is_nothrow_move_constructible and std::is...
Definition result.hpp:1017
constexpr auto transform_error(F &&handle_error) &
Calls a provided functor with the error channel if it is populated, and produces a new result with th...
Definition result.hpp:1284
constexpr void value() const &noexcept
Access the content of the value channel.
Definition result.hpp:1044
constexpr auto transform_error(F &&handle_error) &&
Calls a provided functor with the error channel if it is populated, and produces a new result with th...
Definition result.hpp:1318
constexpr auto operator=(copy_assign_arg const &other) noexcept -> result &
Copy-assignment for the case that error_type satisfies std::is_nothrow_copy_constructible and std::is...
Definition result.hpp:987
constexpr result(result &&move) noexcept(noexcept(base_type(std::declval< result && >())))=default
Default move constructor.
ARENE_NODISCARD constexpr auto error() const &&noexcept -> error_type const &&
Accesses a reference to the content of the error channel.
Definition result.hpp:1074
ARENE_NODISCARD constexpr auto error() const &noexcept -> error_type const &
Accesses a reference to the content of the error channel.
Definition result.hpp:1063
constexpr auto transform_error(F &&handle_error) const &
Calls a provided functor with the error channel if it is populated, and produces a new result with th...
Definition result.hpp:1301
constexpr auto or_else(F &&handle_error) &&
Monadic API which invokes a functor with the contents of error() if the error channel is populated.
Definition result.hpp:1220
ARENE_NODISCARD friend constexpr auto operator!=(result const &lhs, result const &rhs) noexcept(noexcept(lhs==rhs)) -> bool
Compare two results for inequality.
Definition result.hpp:1368
constexpr auto or_else(F &&handle_error) &
Monadic API which invokes a functor with the contents of error() if the error channel is populated.
Definition result.hpp:1212
constexpr auto and_then(F &&handle_value) &
Monadic API which invokes a functor with the contents of value() if the value channel is populated.
Definition result.hpp:1175
constexpr void value() &&noexcept
Access the content of the value channel.
Definition result.hpp:1048
ARENE_NODISCARD constexpr auto error() &noexcept -> error_type &
Accesses a reference to the content of the error channel.
Definition result.hpp:1058
constexpr auto transform(F &&handle_value) const &&
Calls a provided functor with the value channel if it is populated, and produces a new result with th...
Definition result.hpp:1261
constexpr void operator*() const &noexcept
Access the content of the value channel.
Definition result.hpp:1039
constexpr auto transform(F &&handle_value) &
Calls a provided functor with the value channel if it is populated, and produces a new result with th...
Definition result.hpp:1248
constexpr auto and_then(F &&handle_value) &&
Monadic API which invokes a functor with the contents of value() if the value channel is populated.
Definition result.hpp:1183
void emplace(in_place_value_t) noexcept
Emplaces the void value into the result.
Definition result.hpp:1147
constexpr auto transform_error(F &&handle_error) const &&
Calls a provided functor with the error channel if it is populated, and produces a new result with th...
Definition result.hpp:1335
A sum type which can hold either a value or an error. Similar to std::expected.
Definition result.hpp:104
~result()=default
Destroy the stored value or error.
ARENE_NODISCARD constexpr auto value() const &noexcept -> value_type const &
Accesses a reference to the content of the value channel.
Definition result.hpp:329
constexpr auto operator=(move_assign_arg &&other) noexcept -> result &
Move-assignment for the case that value_type and error_type satisfy std::is_nothrow_move_constructibl...
Definition result.hpp:242
constexpr result(result &&move) noexcept(noexcept(base_type(std::declval< result && >())))=default
Default move constructor.
constexpr auto operator=(copy_assign_arg const &other) noexcept -> result &
Copy-assignment for the case that value_type and error_type satisfy std::is_nothrow_copy_constructibl...
Definition result.hpp:209
ARENE_NODISCARD constexpr auto value() const &&noexcept -> value_type const &&
Accesses a reference to the content of the value channel.
Definition result.hpp:350
ARENE_NODISCARD constexpr auto operator->() noexcept -> value_type *
Accesses a pointer to the content of the value channel.
Definition result.hpp:280
ARENE_NODISCARD constexpr auto operator*() &noexcept -> value_type &
Accesses a reference to the content of the value channel.
Definition result.hpp:292
ARENE_NODISCARD constexpr auto operator->() const noexcept -> value_type const *
Accesses a pointer to the content of the value channel.
Definition result.hpp:286
ARENE_NODISCARD constexpr auto operator*() const &&noexcept -> value_type const &&
Accesses a reference to the content of the value channel.
Definition result.hpp:311
constexpr result()=default
Constructs a result with a default-constructed value_type . Does not participate in overload resoluti...
ARENE_NODISCARD constexpr auto operator*() const &noexcept -> value_type const &
Accesses a reference to the content of the value channel.
Definition result.hpp:298
ARENE_NODISCARD constexpr auto value() &noexcept -> value_type &
Accesses a reference to the content of the value channel.
Definition result.hpp:319
ARENE_NODISCARD constexpr auto operator*() &&noexcept -> value_type &&
Accesses a reference to the content of the value channel.
Definition result.hpp:304
ARENE_NODISCARD constexpr auto value() &&noexcept -> value_type &&
Accesses a reference to the content of the value channel.
Definition result.hpp:339
constexpr operator result< void, Error >() noexcept
Instantiates a result<Value,Error> from the contained value instance. Consumes the container.
Definition result.hpp:1657
Intermediary type for constructing a result with a given value_type .
Definition result.hpp:1587
constexpr auto operator=(value_result_t const &) -> value_result_t &=default
Copy assignment.
constexpr auto operator=(value_result_t &&) -> value_result_t &=default
Move constructor.
constexpr value_result_t(value_result_t &&)=default
Move constructor.
constexpr operator result< ValueType, Error >() const &noexcept(noexcept(result< ValueType, Error >(in_place_value, std::declval< ValueType const & >())))
Instantiates a result<ValueType,Error> from the contained value instance. Consumes the container.
Definition result.hpp:1595
~value_result_t()=default
destructor
constexpr operator result< ValueType, Error >() &&noexcept(noexcept(result< ValueType, Error >(in_place_value, std::declval< ValueType && >())))
Instantiates a result<ValueType,Error> from the contained value instance. Consumes the container.
Definition result.hpp:1603
Definition array_exceptions_disabled.cpp:11
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10
constexpr auto operator()(::arene::base::result< V, E > const &value) const noexcept(noexcept(hash< E >{}(std::declval< E const & >())) &&noexcept(hash< V >{}(std::declval< V const & >()))) -> std::size_t
Calculate the hash of a result.
Definition result.hpp:1803
constexpr auto operator()(::arene::base::result< void, E > const &value) const noexcept(noexcept(hash< E >{}(std::declval< E const & >()))) -> std::size_t
Calculate the hash of a result.
Definition result.hpp:1827