Код: Выделить всё
#include
#include
struct s
{
int n1 = 0;
int n2 = 0;
};
namespace std
{
// Attempt at some deduction guide to allow Func0 to compile, but it changes nothing.
// Only Func1 Func2 styles work here.
// Not, I am not trying to write more optimal codew but rather looking for a way
// to write simpler return cases when returning some value within a templated wrapper
// could be expected, optional, ...
// This partly refers to C++ weekly ep 421 ([youtube]0yJk5yfdih0[/youtube])
expected(int, int) -> expected;
// Compilation errors here.
/*
expected Func0()
{
return {1, 2};
}
*/
expected Func1()
{
return {{1, 2}};
}
expected Func2()
{
s news{1, 2};
return news;
}
expected Func3()
{
return unexpected{"error string"};
}
} // namespace std
int main()
{
}
Являются ли здесь дедуктивные направляющие жизнеспособным решением для поддержки возврата {1, 2}; или это единственное решение для создания какой-либо вспомогательной функции make_expected() (например, make_pair).
спасибо
Я пробовал разные способы ввода возврата значения моего теста Func0-1-2.
Ожидал, что такое руководство сработает
expected(int, int) -> ожидаемо;
Подробнее здесь: https://stackoverflow.com/questions/792 ... turn-types