@@ -363,12 +363,13 @@ operator==(const Result<LhsT, LhsErrs...>& lhs, const Result<RhsT, RhsErrs...>&
363363template <traits::IsResultError... Errs>
364364 requires (sizeof ...(Errs) > 0 )
365365class Result <void , Errs...> {
366- private:
367- // helper type
368- template <typename Self, typename F>
369- using and_then_return_t = std::invoke_result_t <F, decltype ((std::declval<Self>().m_value))>;
370-
371366 public:
367+ using value_type = void ;
368+ using error_types = traits::type_pack<Errs...>;
369+
370+ // instead of wrapping the variant in std::optional, we can use std::monostate
371+ std::variant<std::monostate, Errs...> error; // /< Variant holding an error or monostate.
372+
372373 /* *
373374 * @brief Construct a Result with an error.
374375 * @tparam E Error type (must be in Errs).
@@ -428,23 +429,19 @@ class Result<void, Errs...> {
428429 */
429430 template <typename Self, typename F>
430431 constexpr auto and_then (this Self&& self, F&& f)
431- requires std::invocable<F, decltype( std::forward<Self>(self).m_value) >
432- && traits::is_result_v<and_then_return_t<Self, F>>
433- && traits::contains_all_v<and_then_return_t<Self, F >, typename Self::error_types>
432+ requires std::invocable<F, void> && traits::is_result_v< std::invoke_result_t<F, void> >
433+ && traits::
434+ contains_all_v<std::invoke_result_t<F, void >, typename Self::error_types>
434435 {
435436 // if there is an error, return said error immediately
436437 if (self.has_error ()) {
437- return std::visit ([](auto && var) -> and_then_return_t <Self, F > {
438+ return std::visit ([](auto && var) -> std:: invoke_result_t <F, void > {
438439 return std::forward<decltype (var)>(var);
439440 }, std::forward<Self>(self));
440441 }
441442 // otherwise, invoke the callable and return the result
442443 return std::invoke (f, std::forward<Self>(self).m_value );
443444 }
444-
445- private:
446- // instead of wrapping the variant in std::optional, we can use std::monostate
447- std::variant<std::monostate, Errs...> error; // /< Variant holding an error or monostate.
448445};
449446
450447} // namespace zest
0 commit comments