constexpr auto transform()

in src/iceberg/expected.h [1636:1652]


  constexpr auto transform(F&& f) const& {
    using U = std::remove_cvref_t<std::invoke_result_t<F, decltype((this->m_val))>>;
    static_assert(expected_detail::is_value_type_valid_v<U>,
                  "U must be a valid type for expected<U, E>");
    // FIXME another constraint needed here
    if (!has_value()) {
      return expected<U, E>(unexpect, error());
    } else {
      if constexpr (std::is_void_v<U>) {
        std::invoke(std::forward<F>(f), this->m_val);
        return expected<U, E>{};
      } else {
        return expected<U, E>(expected_detail::construct_with_invoke_result_t{},
                              std::forward<F>(f), this->m_val);
      }
    }
  }