79321061

Date: 2025-01-01 02:06:31
Score: 0.5
Natty:
Report link

An alternate solution to the posted one (though significantly less ergonomic, it reduces the nesting)

template <typename... Ts>
inline auto transform_all(auto &&fn, std::optional<Ts> &&...optionals)
    -> std::optional<std::invoke_result_t<decltype(fn), Ts...>> {
  bool is_error = (!optionals.has_value() || ...);
  if (is_error) {
    return std::nullopt;
  }
  return fn(std::forward<decltype(optionals)>(optionals).value()...);
}

Reasons:
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Thornsider3