constexpr auto or_else()

in src/iceberg/expected.h [2154:2166]


  constexpr auto or_else(F&& f) const& {
    using G = std::remove_cvref_t<std::invoke_result_t<F, decltype(error())>>;
    static_assert(expected_detail::is_specialization_v<G, iceberg::expected>,
                  "G (return type of F) must be specialization of expected");
    static_assert(std::is_same_v<typename G::value_type, T>,
                  "The value type must be the same after calling the F");

    if (has_value()) {
      return G();
    } else {
      return std::invoke(std::forward<F>(f), error());
    }
  }