Вот что я попробовал далеко:
Код: Выделить всё
#include
#include
#include
using Result = std::variant;
Result computeValue(int x) {
if (x < 0) {
return "Negative input error";
}
return x * 2;
}
void handleResult(const Result& result) {
std::visit([](auto&& arg) {
using T = std::decay_t;
if constexpr (std::is_same_v) {
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/78661552/how-to-efficiently-use-stdvariant-for-error-handling-in-c[/url]