Result<T> type
#include <fp/all.hpp>
namespace views = ::ranges::views;
if (x == 0.0) {
}
return 4.0 / x;
}
if (x < 0) {
fmt::format("sqrt of value < 0.0 is undefined: {}", x)));
}
return sqrt(x);
}
}
if (!result.has_value()) {
fmt::print("{}\n", result.error());
}
}
int main() {
const auto x = views::iota(-5, 10) |
views::transform([](const int& x) { return x * 0.2; }) |
ranges::to<std::vector>();
const auto y =
x | views::transform(do_math) | views::filter([](const auto& result) {
print_errors(result);
return result.has_value();
}) |
views::transform([](const auto& result) { return result.value(); }) |
ranges::to<std::vector>();
fmt::print("y = sqrt(4.0 / x)\nx = {}\ny = {}\n", x, y);
return 0;
}