// opt_throw_test.
cpp
#include <optional>
#include <stdexcept>
#include <iostream>
std::optional<int> compute(int x) {
if (x < 0) {
throw std::runtime_error("negative input"); // <-- forbidden
}
return x * 2;
}
int main() {
auto r = compute(-5);
if (r) std::cout << *r << "\n";
else std::cout << "no result\n";
return 0;
}