10#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_RESULT_RESULT_HPP_
11#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_RESULT_RESULT_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"
102template <
class T,
class E>
104class result : result_detail::result_base<T, E> {
106 using base_type = result_detail::result_base<T, E>;
110 "The value type stored in result must not have an overloaded address-of operator"
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"
161 constexpr result(in_place_value_t, P&&... args)
noexcept(
noexcept(base_type(in_place_value,
std::forward<P>(args)...))
163 : base_type(in_place_value,
std::forward<P>(args)...) {}
177 constexpr result(in_place_error_t, P&&... args)
noexcept(
noexcept(base_type(in_place_error,
std::forward<P>(args)...))
179 : base_type(in_place_error,
std::forward<P>(args)...) {}
191 static constexpr bool is_copy_assignable{
210 if (&other !=
this) {
220 constexpr auto operator=(deleted_copy_assign_arg
const& other)
noexcept ->
result& =
delete;
224 static constexpr bool is_move_assignable{
251 constexpr auto operator=(deleted_move_assign_arg&& other)
noexcept ->
result& =
delete;
254 using base_type::has_value;
261 template <
typename U = value_type, constra
ints<std::enable_if_t<is_equality_comparable_v<U>>> =
nullptr>
265 return val == this->storage().unsafe_value();
271 using base_type::has_error;
274 using base_type::operator bool;
321 return this->storage().unsafe_value();
331 return this->storage().unsafe_value();
341 return std::move(this->storage().unsafe_value());
352 return std::move(this->storage().unsafe_value());
361 template <typename U = T, constraints<std::enable_if_t<std::is_convertible<U, value_type>::value>> =
nullptr>
371 template <typename U = T, constraints<std::enable_if_t<std::is_convertible<U, value_type>::value>> =
nullptr>
384 return this->storage().unsafe_error();
394 return this->storage().unsafe_error();
403 return std::move(this->storage().unsafe_error());
413 return std::move(this->storage().unsafe_error());
429 typename SourceValueType = T,
430 typename SourceErrorType = E,
439 if (other.has_value()) {
443 static_cast<void>(other.emplace(in_place_value,
std::move(this->storage().unsafe_value())));
446 }
else if (this->has_error()) {
447 if (other.has_error()) {
451 static_cast<void>(other.emplace(in_place_error,
std::move(this->storage().unsafe_error())));
473 typename SourceValueType = T,
474 typename SourceErrorType = E,
486 using base_type::emplace;
499 typename... ArgTypes,
503 this->discriminator() = result_detail::discriminator_type::holds_value;
504 return *::arene::base::construct_at(
530 template <
typename F>
534 template <
typename F>
538 template <
typename F>
543 template <
typename F>
544 constexpr auto and_then(F&& handle_value)
const&& {
566 template <
typename F>
570 template <
typename F>
571 constexpr auto or_else(F&& handle_error)
const& {
574 template <
typename F>
579 template <
typename F>
580 constexpr auto or_else(F&& handle_error)
const&& {
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>
668 noexcept(lhs.has_value(rhs.value())) &&
noexcept(lhs.has_error(rhs.error()))
672 if (lhs.has_value()) {
673 return rhs.has_value(lhs.storage().unsafe_value());
675 return rhs.has_error(lhs.storage().unsafe_error());
691 return !(lhs == rhs);
709 template <
typename OtherType, constra
ints<std::enable_if_t<decays_to_v<OtherType, result>>> =
nullptr>
710 constexpr auto assign(OtherType&& other)
noexcept ->
result& {
712 if (other.has_value()) {
713 this->storage().unsafe_value() =
723 if (other.has_error()) {
741 template <
typename SelfType,
typename F, constra
ints<std::enable_if<decays_to_v<SelfType, result>>> =
nullptr>
742 static constexpr auto and_then(SelfType&& self, F&& handle_value) {
747 std::is_same<typename f_result_t::error_type, typename remove_cvref_t<SelfType>::error_type>
::value,
748 "The result returned from handle_value's error channel must be the same as this result's error channel"
750 if (self.has_value()) {
751 return ::arene::base::invoke(
768 template <
typename SelfType,
typename F, constra
ints<std::enable_if<decays_to_v<SelfType, result>>> =
nullptr>
769 static constexpr auto or_else(SelfType&& self, F&& handle_error) {
775 "The result returned from handle_error's value channel must be the same as this result's value channel"
777 if (self.has_error()) {
778 return ::arene::base::invoke(
801 std::enable_if<decays_to_v<SelfType, result>>,
805 static constexpr auto
transform(SelfType&& self, F&& handle_value) {
809 if (self.has_value()) {
834 std::enable_if<decays_to_v<SelfType, result>>,
838 static constexpr auto
transform(SelfType&& self, F&& handle_value) {
840 if (self.has_value()) {
841 ::arene::base::invoke(
842 std::forward<F>(handle_value),
843 forward_like<SelfType>(std::forward<SelfType>(self).storage().unsafe_value())
861 template <
typename SelfType,
typename F, constra
ints<std::enable_if<decays_to_v<SelfType, result>>> =
nullptr>
862 static constexpr auto transform_error(SelfType&& self, F&& handle_error) {
866 if (self.has_error()) {
893 using base_type = result_detail::result_base<monostate, E>;
907 "value_type must be an unqualified type, non-reference type."
911 "error_type must be an unqualified type, non-reference type."
917 "monostate as an error_type is not supported"
934 constexpr result(in_place_value_t)
noexcept(
noexcept(base_type(in_place_value,
monostate{})))
935 : base_type(in_place_value,
monostate{}) {}
941 : base_type(in_place_value,
monostate{}) {}
956 constexpr result(in_place_error_t, P&&... args)
noexcept(
noexcept(base_type(in_place_error,
std::forward<P>(args)...))
958 : base_type(in_place_error,
std::forward<P>(args)...) {}
970 static constexpr bool is_copy_assignable{
987 if (&other !=
this) {
996 constexpr auto operator=(deleted_copy_assign_arg
const& other)
noexcept ->
result& =
delete;
1000 static constexpr bool is_move_assignable{
1027 using base_type::has_value;
1030 using base_type::has_error;
1033 using base_type::operator bool;
1059 return this->storage().unsafe_error();
1064 return this->storage().unsafe_error();
1069 return std::move(this->storage().unsafe_error());
1075 return std::move(this->storage().unsafe_error());
1093 typename SourceErrorType = E,
1099 if (other.has_value()) {
1103 static_cast<void>(this->
emplace(in_place_error,
std::move(other.storage().unsafe_error())));
1104 other.emplace(in_place_value);
1105 }
else if (this->has_error()) {
1106 if (other.has_error()) {
1109 static_cast<void>(other.emplace(in_place_error,
std::move(this->storage().unsafe_error())));
1110 this->
emplace(in_place_value);
1129 typename SourceErrorType = E,
1139 using base_type::emplace;
1148 this->discriminator() = result_detail::discriminator_type::holds_value;
1173 template <
typename F>
1177 template <
typename F>
1181 template <
typename F>
1185 template <
typename F>
1210 template <
typename F>
1214 template <
typename F>
1218 template <
typename F>
1222 template <
typename F>
1223 constexpr auto or_else(F&& handle_error)
const&& {
1246 template <
typename F>
1250 template <
typename F>
1254 template <
typename F>
1259 template <
typename F>
1282 template <
typename F>
1299 template <
typename F>
1316 template <
typename F>
1333 template <
typename F>
1347 noexcept(lhs.has_error(rhs.error()))
1350 if (lhs.has_value()) {
1351 return rhs.has_value();
1353 return rhs.has_error(lhs.storage().unsafe_error());
1369 return !(lhs == rhs);
1387 template <
typename OtherType, constra
ints<std::enable_if_t<decays_to_v<OtherType, result>>> =
nullptr>
1388 constexpr auto assign(OtherType&& other)
noexcept ->
result& {
1389 if (this->has_value()) {
1390 if (other.has_value()) {
1400 if (other.has_error()) {
1401 this->storage().unsafe_error() = forward_like<OtherType>(
std::forward<OtherType>(other).storage().unsafe_error());
1405 this->emplace(in_place_value);
1418 template <
typename SelfType,
typename F, constra
ints<std::enable_if<decays_to_v<SelfType, result>>> =
nullptr>
1419 static constexpr auto and_then(SelfType&& self, F&& handle_value) {
1420 using f_result_t = invoke_result_t<F>;
1421 static_assert(is_instantiation_of_v<f_result_t, ::arene::base::result>,
"handle_value must return a result!");
1423 std::is_same<typename f_result_t::error_type, typename remove_cvref_t<SelfType>::error_type>::value,
1424 "The result returned from handle_value's error channel must be the same as this result's error channel"
1426 if (self.has_value()) {
1429 return f_result_t{in_place_error, forward_like<SelfType>(
std::forward<SelfType>(self).storage().unsafe_error())};
1441 template <
typename SelfType,
typename F, constra
ints<std::enable_if<decays_to_v<SelfType, result>>> =
nullptr>
1442 static constexpr auto or_else(SelfType&& self, F&& handle_error) {
1444 invoke_result_t<F, decltype(forward_like<SelfType>(
std::forward<SelfType>(self).storage().unsafe_error()))>;
1445 static_assert(is_instantiation_of_v<f_result_t, ::arene::base::result>,
"handle_error must return a result!");
1447 std::is_same<typename f_result_t::value_type, typename remove_cvref_t<SelfType>::value_type>::value,
1448 "The result returned from handle_error's value channel must be the same as this result's value channel"
1450 if (self.has_error()) {
1451 return ::arene::base::invoke(
1456 return f_result_t{};
1474 std::enable_if<decays_to_v<SelfType, result>>,
1476 static constexpr auto transform(SelfType&& self, F&& handle_value) {
1477 using f_value_t = invoke_result_t<F>;
1478 using result_t = result<f_value_t, error_type>;
1479 if (self.has_value()) {
1482 return result_t{in_place_error, forward_like<SelfType>(
std::forward<SelfType>(self).storage().unsafe_error())};
1498 std::enable_if<decays_to_v<SelfType, result>>,
1500 static constexpr auto transform(SelfType&& self, F&& handle_value) {
1501 using result_t = result<void, error_type>;
1502 if (self.has_value()) {
1506 return result_t{in_place_error, forward_like<SelfType>(
std::forward<SelfType>(self).storage().unsafe_error())};
1520 template <
typename SelfType,
typename F, constra
ints<std::enable_if<decays_to_v<SelfType, result>>> =
nullptr>
1521 static constexpr auto transform_error(SelfType&& self, F&& handle_error) {
1523 invoke_result_t<F, decltype(forward_like<SelfType>(
std::forward<SelfType>(self).storage().unsafe_error()))>;
1524 using result_t = result<void, f_error_t>;
1525 if (self.has_error()) {
1563 invoke_result_t<OnValue, decltype(std::declval<ResultType>().value())>,
1567 OnValue&& on_expected,
1568 OnError&& on_unexpected
1571 if (self.has_value()) {
1585template <
typename ValueType>
1592 template <
typename Error>
1595 ) const& noexcept(noexcept(
result<ValueType, Error>(in_place_value,
std::declval<ValueType const&>()))) {
1596 return {in_place_value, value_};
1600 template <
typename Error>
1604 return {in_place_value,
std::move(value_)};
1613 typename... ArgTypes,
1618 : value_(
std::forward<ArgTypes>(args)...) {}
1654 template <
typename Error>
1670template <
typename ErrorType>
1677 template <
typename Value>
1680 ) const& noexcept(noexcept(
result<Value, ErrorType>(in_place_error,
std::declval<ErrorType const&>()))) {
1681 return {in_place_error, error_};
1686 template <
typename Value>
1690 return {in_place_error,
std::move(error_)};
1699 typename... ArgTypes,
1704 : error_(
std::forward<ArgTypes>(args)...) {}
1741template <
typename ValueType>
1770template <
typename ErrorType>
1794template <
typename V,
typename E>
1805 return value.has_value() ? hash<V>{}(
value.value()) : hash<E>{}(
value.error());
1818template <
typename E>
Intermediary type for constructing a result with a given error_type .
Definition result.hpp:1671
constexpr error_result_t(error_result_t &&)=default
Move constructor.
~error_result_t()=default
destructor
constexpr auto operator=(error_result_t &&) -> error_result_t &=default
Move constructor.
constexpr error_result_t(ArgTypes &&... args) noexcept(std::is_nothrow_constructible< ErrorType, ArgTypes... >::value)
Construct the stored error from the specified arguments.
Definition result.hpp:1703
constexpr auto operator=(error_result_t const &) -> error_result_t &=default
Copy assignment.
constexpr error_result_t(error_result_t const &)=default
Copy constructor.
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:1251
~result()=default
Destroy the stored value or error.
friend constexpr void swap(result &lhs, result &rhs) noexcept(noexcept(lhs.swap(rhs)))
Swaps the state of two results.
Definition result.hpp:1133
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:1346
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:1223
constexpr result(in_place_value_t) noexcept(noexcept(base_type(in_place_value, monostate{})))
Constructs a result with the value-channel engaged.
Definition result.hpp:934
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:1215
E error_type
The type when the result contains an error.
Definition result.hpp:902
ARENE_NODISCARD constexpr auto error() &&noexcept -> error_type &&
Accesses a reference to the content of the error channel.
Definition result.hpp:1067
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:1255
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:1178
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:1186
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:1016
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:1283
constexpr void value() const &noexcept
Access the content of the value channel.
Definition result.hpp:1043
constexpr void swap(result &other) noexcept(is_nothrow_swappable_v< SourceErrorType >)
Swaps the state of two results.
Definition result.hpp:1097
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:1317
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:986
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:1073
ARENE_NODISCARD constexpr auto error() const &noexcept -> error_type const &
Accesses a reference to the content of the error channel.
Definition result.hpp:1062
constexpr result(in_place_value_t, monostate) noexcept(noexcept(base_type(in_place_value, monostate{})))
Constructs a result with the value-channel engaged. Provided for backwards compatibility.
Definition result.hpp:940
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:1300
constexpr result(result const ©) noexcept(noexcept(base_type(std::declval< result const & >())))=default
Default copy constructor.
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:1219
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:1367
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:1211
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:1174
constexpr void value() &&noexcept
Access the content of the value channel.
Definition result.hpp:1047
constexpr auto operator=(deleted_move_assign_arg &&other) noexcept -> result &=delete
Deleted Move-assignment if error_type does not satisfy std::is_nothrow_move_constructible and std::is...
ARENE_NODISCARD constexpr auto error() &noexcept -> error_type &
Accesses a reference to the content of the error channel.
Definition result.hpp:1057
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:1260
void value_type
The type when the result contains a value.
Definition result.hpp:898
constexpr auto operator=(deleted_copy_assign_arg const &other) noexcept -> result &=delete
Deleted Copy-assignment if error_type does not satisfy std::is_nothrow_copy_constructible and std::is...
constexpr void operator*() const &noexcept
Access the content of the value channel.
Definition result.hpp:1038
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:1247
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:1182
void emplace(in_place_value_t) noexcept
Emplaces the void value into the result.
Definition result.hpp:1146
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:1334
constexpr result(in_place_error_t, P &&... args) noexcept(noexcept(base_type(in_place_error, std::forward< P >(args)...)))
Constructs a result containing the error_type by way of direct-non-list-initialization.
Definition result.hpp:956
A sum type which can hold either a value or an error. Similar to std::expected.
Definition result.hpp:104
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:531
~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 void swap(result &other) noexcept(is_nothrow_swappable_v< SourceValueType > &&is_nothrow_swappable_v< SourceErrorType >)
Swaps the state of two results.
Definition result.hpp:436
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 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:535
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:567
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
auto emplace(in_place_value_t, ArgTypes &&... args) noexcept -> value_type &
Emplaces a value into the result.
Definition result.hpp:501
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:604
ARENE_NODISCARD constexpr auto value() const &&noexcept -> value_type const &&
Accesses a reference to the content of the value channel.
Definition result.hpp:350
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:608
ulp_distance_error error_type
Definition result.hpp:120
constexpr auto operator=(deleted_move_assign_arg &&other) noexcept -> result &=delete
Deleted Move-assignment if value_type or error_type do not satisfy std::is_nothrow_move_constructible...
ARENE_NODISCARD constexpr auto operator->() noexcept -> value_type *
Accesses a pointer to the content of the value channel.
Definition result.hpp:280
friend constexpr void swap(result &lhs, result &rhs) noexcept(noexcept(lhs.swap(rhs)))
Swaps the state of two results.
Definition result.hpp:480
ARENE_NODISCARD constexpr auto error() &&noexcept -> error_type &&
Accesses a reference to the content of the error channel.
Definition result.hpp:401
constexpr auto operator=(deleted_copy_assign_arg const &other) noexcept -> result &=delete
Deleted Copy-assignment if value_type or error_type do not satisfy std::is_nothrow_copy_constructible...
constexpr result(result const ©) noexcept(noexcept(base_type(std::declval< result const & >())))=default
Default copy constructor.
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:617
ARENE_NODISCARD constexpr auto operator*() &noexcept -> value_type &
Accesses a reference to the content of the value channel.
Definition result.hpp:292
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:651
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:571
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:638
constexpr result(in_place_error_t, P &&... args) noexcept(noexcept(base_type(in_place_error, std::forward< P >(args)...)))
Constructs a result containing the error_type by way of direct-non-list-initialization.
Definition result.hpp:177
ARENE_NODISCARD constexpr auto operator->() const noexcept -> value_type const *
Accesses a pointer to the content of the value channel.
Definition result.hpp:286
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:575
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:689
ARENE_NODISCARD constexpr auto operator*() const &&noexcept -> value_type const &&
Accesses a reference to the content of the value channel.
Definition result.hpp:311
ARENE_NODISCARD constexpr auto value_or(U &&default_value) const &noexcept -> value_type
Returns the value if the value channel is populated, else another value. Not declared if T is void .
Definition result.hpp:362
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:539
ARENE_NODISCARD constexpr auto value_or(U &&default_value) &&noexcept -> value_type
Returns the value if the value channel is populated, else another value. Not declared if T is void .
Definition result.hpp:372
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
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:612
ARENE_NODISCARD constexpr auto value() &noexcept -> value_type &
Definition result.hpp:319
ARENE_NODISCARD constexpr auto has_value(value_type const &val) const noexcept(noexcept(val==std::declval< value_type >())) -> bool
Checks if the value channel contains a specific value.
Definition result.hpp:262
ARENE_NODISCARD friend constexpr auto operator==(result const &lhs, result const &rhs) noexcept(noexcept(lhs.has_value(rhs.value())) &&noexcept(lhs.has_error(rhs.error()))) -> bool
Compare two results for equality.
Definition result.hpp:667
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:544
constexpr result(in_place_value_t, P &&... args) noexcept(noexcept(base_type(in_place_value, std::forward< P >(args)...)))
Constructs a result containing the value_type by way of direct-non-list-initialization.
Definition result.hpp:161
ARENE_NODISCARD constexpr auto operator*() &&noexcept -> value_type &&
Accesses a reference to the content of the value channel.
Definition result.hpp:304
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:580
ARENE_NODISCARD constexpr auto error() &noexcept -> error_type &
Accesses a reference to the content of the error channel.
Definition result.hpp:382
ARENE_NODISCARD constexpr auto value() &&noexcept -> value_type &&
Accesses a reference to the content of the value channel.
Definition result.hpp:339
ARENE_NODISCARD constexpr auto error() const &noexcept -> error_type const &
Accesses a reference to the content of the error channel.
Definition result.hpp:392
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:642
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:646
ARENE_NODISCARD constexpr auto error() const &&noexcept -> error_type const &&
Accesses a reference to the content of the error channel.
Definition result.hpp:411
ResultValue value_type
Definition result.hpp:116
Intermediary type for constructing a result with a given value_type .
Definition result.hpp:1586
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.
~value_result_t()=default
destructor
constexpr value_result_t(value_result_t const &)=default
Copy constructor.
constexpr value_result_t(ArgTypes &&... args) noexcept(std::is_nothrow_constructible< ValueType, ArgTypes... >::value)
Construct the stored value from the specified arguments.
Definition result.hpp:1617
static constexpr value_type value
Definition integral_constant.hpp:34
Type trait to detect if a type is constructible from arguments of the specified types.
Definition is_constructible.hpp:29
Type trait to detect if a type is constructible from arguments of the specified types and is noexcept...
Definition is_constructible.hpp:84
Trait to detect if the two template parameters are the same or not. The value member is true if the t...
Definition is_same.hpp:35
#define ARENE_PRECONDITION(condition)
Check that a precondition holds, and terminate the application if it does not.
Definition contract.hpp:150
Provides the decays_to_v<T, U> trait.
Implementation of a backport of std::forward_like.
static ARENE_MAYBE_UNUSED constexpr auto const & swap
A Customization Point Object implementation of the constexpr compatible std::swap from C++17.
Definition swap.hpp:130
Definition accumulate.hpp:37
constexpr bool is_nothrow_swappable_v
Trait query indicating if a type can be noexcept-swapped.
constexpr auto move(InIterator first, InIterator last, OutIterator output) noexcept(noexcept(*first++) &&noexcept(output++) &&//CODEQLFP(EXP52-CPP) CODEQLFP(A5-2-6) noexcept(first !=last) &&//CODEQLFP(A5-2-6) std::is_nothrow_assignable<, typename std::iterator_traits< InIterator >::value_type >::value) -> OutIterator
Moves the elements in the range [first, last), to another range beginning at output,...
Definition move.hpp:46
constexpr bool is_instantiation_of_v
Definition is_instantiation_of.hpp:16
typename static_if< B >::template then_else< T, F > conditional_t
lazily select between two types based on a boolean condition
Definition conditional.hpp:28
constexpr auto copy(InputIterator first, InputIterator last, OutputIterator output) noexcept(noexcept(*(++output)) &&noexcept(*(++first)) &&noexcept(first !=last) &&std::is_nothrow_assignable<, typename std::iterator_traits< InputIterator >::reference >::value) -> OutputIterator
Copies the elements in the range, defined by [first, last), to another range beginning at output.
Definition copy.hpp:40
typename invoke_result< Fn, Args... >::type invoke_result_t
The return type of a functor invoked with the specified arguments.
Definition is_invocable.hpp:271
constexpr auto error_result(ErrorType &&error) noexcept(std::is_nothrow_constructible< typename std::remove_reference< ErrorType >::type, ErrorType && >::value) -> error_result_t< std::remove_reference_t< ErrorType > >
Convenience function to construct a result<Value,ErrorType> containing the ErrorType from any referen...
Definition result.hpp:1771
constexpr auto invoke(F &&func, Args &&... args) noexcept(is_nothrow_invocable_v< F, Args... >) ->
Implementation of std::invoke from C++23: invokes the specified callable with the specified arguments...
Definition invoke.hpp:281
constexpr bool has_overloaded_address_operator_v
Type trait to check if a type has an overloaded address operator; the value is true if the type has a...
constexpr bool is_nothrow_invocable_v
Determine if a functor type is no-throw invocable with the specified argument types.
constexpr auto forward_like
A backport of C++23's std::forward_like, which allows forwarding a type with the same reference and c...
typename constraints_impl::constraints< EnableIfs... >::type constraints
Helper used to express template constraints in a consistent way using std::enable_if_t.
Definition constraints.hpp:51
constexpr auto value_result(ValueType &&value) noexcept(std::is_nothrow_constructible< typename std::remove_reference< ValueType >::type, ValueType && >::value) -> value_result_t< std::remove_reference_t< ValueType > >
Convenience function to construct a result<ValueType,Error> containing the ValueType from any referen...
Definition result.hpp:1742
constexpr auto expand_result(ResultType &&self, OnValue &&on_expected, OnError &&on_unexpected) noexcept(is_nothrow_invocable_v< OnValue, > &&is_nothrow_invocable_v< OnError, >) ->
Visit the contained value or error with two independent functors.
Definition result.hpp:1565
constexpr bool is_equality_comparable_v
Definition accumulate.hpp:36
constexpr Type integral_constant< Type, Value >::value
Out-of-line definition for the value constant.
Definition integral_constant.hpp:64
constexpr auto move(T &&value) noexcept -> remove_reference_t< T > &&
Cast a value to an rvalue.
Definition move.hpp:30
::size_t size_t
A type suitable for holding the size of an object.
Definition cstddef.hpp:29
typename enable_if< Condition, Type >::type enable_if_t
Type alias to support constraining templates. Is an alias for the specified type if the Condition is ...
Definition enable_if.hpp:41
auto declval() noexcept -> T &&
A dummy function that is declared but not defined, with a user-specified return type,...
static constexpr auto const & ignore
An object to which anything can be assigned, which ignores the assigned value.
Definition ignore.hpp:72
constexpr auto addressof(T &value) noexcept -> T *
Obtains the actual address of the object or function arg, even in presence of overloaded operator&.
Definition addressof.hpp:24
typename remove_reference< T >::type remove_reference_t
An alias for T, but with top-level reference qualifiers removed.
Definition remove_reference.hpp:47
constexpr auto forward(remove_reference_t< T > &value) noexcept -> T &&
Cast a value to an rvalue if T is an rvalue or rvalue reference, otherwise forward an lvalue referenc...
Definition forward.hpp:24
#define ARENE_NODISCARD
An alias for [[nodiscard]] , or a no-op if the attribute is not supported.
Definition nodiscard.hpp:26
A monostate type that is a well-behaved empty value for variants.
Definition monostate.hpp:28
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:1802
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:1826
hash function primary template
Definition hash.hpp:179
Provides the all_of_v<bool...> trait.