Skip to content

Commit

Permalink
move isresult out
Browse files Browse the repository at this point in the history
  • Loading branch information
altalk23 authored Nov 21, 2024
1 parent c088c7a commit d1251ac
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions include/Geode/Result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,6 @@ namespace geode {
using ErrType = ErrType2;
};

template <class Type>
concept IsResult = IsResultImpl<Type>::value;

template <class Type>
using ResultOkType = typename IsResultImpl<Type>::OkType;

Expand All @@ -250,6 +247,9 @@ namespace geode {
concept IsStringStreamable = requires(std::stringstream ss, Type t) { ss << t; };
}

template <class Type>
concept IsResult = impl::IsResultImpl<Type>::value;

/// @brief Constructs a new Ok value
/// @param ok the value to wrap in an Ok
/// @return a new Ok value
Expand Down Expand Up @@ -1591,7 +1591,7 @@ namespace geode {
/// @param operation the operation to perform if this Result is Ok
/// @return the result of the operation if this Result is Ok, otherwise this Result
template <class Operation>
requires(std::invocable<Operation, OkType> && impl::IsResult<std::invoke_result_t<Operation, OkType>> && std::convertible_to<ErrType, impl::ResultErrType<std::invoke_result_t<Operation, OkType>>>)
requires(std::invocable<Operation, OkType> && IsResult<std::invoke_result_t<Operation, OkType>> && std::convertible_to<ErrType, impl::ResultErrType<std::invoke_result_t<Operation, OkType>>>)
constexpr std::invoke_result_t<Operation, OkType> andThen(Operation&& operation
) && noexcept(noexcept(operation(std::declval<OkType>()))) {
if (this->isOk()) {
Expand All @@ -1606,7 +1606,7 @@ namespace geode {
/// @param operation the operation to perform if this Result is Ok
/// @return the result of the operation if this Result is Ok, otherwise this Result
template <class Operation>
requires(std::invocable<Operation, OkType> && impl::IsResult<std::invoke_result_t<Operation, OkType>> && std::convertible_to<ErrType, impl::ResultErrType<std::invoke_result_t<Operation, OkType>>>)
requires(std::invocable<Operation, OkType> && IsResult<std::invoke_result_t<Operation, OkType>> && std::convertible_to<ErrType, impl::ResultErrType<std::invoke_result_t<Operation, OkType>>>)
constexpr std::invoke_result_t<Operation, OkType> andThen(Operation&& operation
) const& noexcept(noexcept(operation(std::declval<OkType>()))) {
if (this->isOk()) {
Expand All @@ -1621,7 +1621,7 @@ namespace geode {
/// @param operation the operation to perform if this Result is Ok
/// @return the result of the operation if this Result is Ok, otherwise this Result
template <class Operation>
requires(std::invocable<Operation> && impl::IsResult<std::invoke_result_t<Operation>> && std::convertible_to<ErrType, impl::ResultErrType<std::invoke_result_t<Operation>>>)
requires(std::invocable<Operation> && IsResult<std::invoke_result_t<Operation>> && std::convertible_to<ErrType, impl::ResultErrType<std::invoke_result_t<Operation>>>)
constexpr std::invoke_result_t<Operation> andThen(Operation&& operation
) && noexcept(noexcept(operation())) {
if (this->isOk()) {
Expand All @@ -1636,7 +1636,7 @@ namespace geode {
/// @param operation the operation to perform if this Result is Ok
/// @return the result of the operation if this Result is Ok, otherwise this Result
template <class Operation>
requires(std::invocable<Operation> && impl::IsResult<std::invoke_result_t<Operation>> && std::convertible_to<ErrType, impl::ResultErrType<std::invoke_result_t<Operation>>>)
requires(std::invocable<Operation> && IsResult<std::invoke_result_t<Operation>> && std::convertible_to<ErrType, impl::ResultErrType<std::invoke_result_t<Operation>>>)
constexpr std::invoke_result_t<Operation> andThen(Operation&& operation
) const& noexcept(noexcept(operation())) {
if (this->isOk()) {
Expand Down Expand Up @@ -1677,7 +1677,7 @@ namespace geode {
/// @param operation the operation to perform if this Result is Err
/// @return the result of the operation if this Result is Err, otherwise this Result
template <class Operation>
requires(std::invocable<Operation, ErrType> && impl::IsResult<std::invoke_result_t<Operation, ErrType>> && std::convertible_to<OkType, impl::ResultOkType<std::invoke_result_t<Operation, ErrType>>>)
requires(std::invocable<Operation, ErrType> && IsResult<std::invoke_result_t<Operation, ErrType>> && std::convertible_to<OkType, impl::ResultOkType<std::invoke_result_t<Operation, ErrType>>>)
constexpr std::invoke_result_t<Operation, ErrType> orElse(Operation&& operation
) && noexcept(noexcept(operation(std::declval<ErrType>()))) {
if (this->isOk()) {
Expand All @@ -1692,7 +1692,7 @@ namespace geode {
/// @param operation the operation to perform if this Result is Err
/// @return the result of the operation if this Result is Err, otherwise this Result
template <class Operation>
requires(std::invocable<Operation, ErrType> && impl::IsResult<std::invoke_result_t<Operation, ErrType>> && std::convertible_to<OkType, impl::ResultOkType<std::invoke_result_t<Operation, ErrType>>>)
requires(std::invocable<Operation, ErrType> && IsResult<std::invoke_result_t<Operation, ErrType>> && std::convertible_to<OkType, impl::ResultOkType<std::invoke_result_t<Operation, ErrType>>>)
constexpr std::invoke_result_t<Operation, ErrType> orElse(Operation&& operation
) const& noexcept(noexcept(operation(std::declval<ErrType>()))) {
if (this->isOk()) {
Expand All @@ -1707,7 +1707,7 @@ namespace geode {
/// @param operation the operation to perform if this Result is Err
/// @return the result of the operation if this Result is Err, otherwise this Result
template <class Operation>
requires(std::invocable<Operation> && impl::IsResult<std::invoke_result_t<Operation>> && std::convertible_to<OkType, impl::ResultOkType<std::invoke_result_t<Operation>>>)
requires(std::invocable<Operation> && IsResult<std::invoke_result_t<Operation>> && std::convertible_to<OkType, impl::ResultOkType<std::invoke_result_t<Operation>>>)
constexpr std::invoke_result_t<Operation> orElse(Operation&& operation
) && noexcept(noexcept(operation())) {
if (this->isOk()) {
Expand All @@ -1722,7 +1722,7 @@ namespace geode {
/// @param operation the operation to perform if this Result is Err
/// @return the result of the operation if this Result is Err, otherwise this Result
template <class Operation>
requires(std::invocable<Operation> && impl::IsResult<std::invoke_result_t<Operation>> && std::convertible_to<OkType, impl::ResultOkType<std::invoke_result_t<Operation>>>)
requires(std::invocable<Operation> && IsResult<std::invoke_result_t<Operation>> && std::convertible_to<OkType, impl::ResultOkType<std::invoke_result_t<Operation>>>)
constexpr std::invoke_result_t<Operation> orElse(Operation&& operation
) const& noexcept(noexcept(operation())) {
if (this->isOk()) {
Expand Down Expand Up @@ -1779,7 +1779,7 @@ namespace geode {
/// @return the inner Result if the Result is Ok, otherwise the outer Result
constexpr Result<impl::ResultOkType<OkType>, ErrType> flatten(
) && noexcept(std::is_nothrow_move_constructible_v<OkType> && std::is_nothrow_move_constructible_v<ErrType>)
requires(impl::IsResult<OkType> && std::same_as<ErrType, impl::ResultErrType<OkType>>)
requires(IsResult<OkType> && std::same_as<ErrType, impl::ResultErrType<OkType>>)
{
if (this->isOk()) {
return std::move(*this).unwrap();
Expand All @@ -1793,7 +1793,7 @@ namespace geode {
/// @return the inner Result if the Result is Ok, otherwise the outer Result
constexpr Result<impl::ResultOkType<OkType>, ErrType> flatten(
) const& noexcept(std::is_nothrow_move_constructible_v<OkType> && std::is_nothrow_move_constructible_v<ErrType>)
requires(impl::IsResult<OkType> && std::same_as<ErrType, impl::ResultErrType<OkType>>)
requires(IsResult<OkType> && std::same_as<ErrType, impl::ResultErrType<OkType>>)
{
if (this->isOk()) {
return this->unwrap();
Expand Down

0 comments on commit d1251ac

Please sign in to comment.