Я понимаю, что or_else должен возвращать значение, но есть специализация для void, поэтому почему это не должно работать?
Код: Выделить всё
std::expected fun (int);
fun (19).and_then ([]() { doSomething(); }).or_else ([] (Error e) { std::println ("Uh oh error.."); });
Код: Выделить всё
/usr/include/c++/14.2.1/expected:1586:37: error: static assertion failed
1586 | static_assert(__expected::__is_expected);
| ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14.2.1/expected:1586:37: note: ‘std::__expected::__is_expected’ evaluates to false
/usr/include/c++/14.2.1/expected:1587:25: error: ‘std::remove_cvref::type’ {aka ‘void’} is not a class, struct, or union type
1587 | static_assert(is_same_v);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14.2.1/expected:1592:20: error: expression list treated as compound expression in functional cast [-fpermissive]
1592 | return _Up(unexpect, std::move(_M_unex));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/david/tests/cpp/src/expect.cpp: In function ‘int main()’:
/home/david/tests/cpp/src/expect.cpp:49:26: error: invalid use of ‘void’
Подробнее здесь: https://stackoverflow.com/questions/792 ... void-error
Мобильная версия