decltype(auto) f();
auto f() -> decltype(t.error());
, . [dcl.spec.auto]/12. - , , .
Wrapper , ( ) - [temp.inst]/1. decltype(auto) f(); , . , auto f() -> decltype(t.error()); .
++ 11 , . f :
template<typename U = T>
auto f() -> decltype( std::declval<U&>().error() );
:
template<typename U = T>
auto f() -> decltype( std::declval<U&>().error() )
{
return t.error();
}
Wrapper, t.error() , f , . [temp.res]/8, , , :
, , , .
, , , , . ; , . , .
, , ( ):
#include <type_traits>
template<typename T> struct type_is { using type = T; };
template <typename T>
struct Wrapper {
T t;
template<typename U=T, typename=void>
struct error_return_type_or_void : type_is<void> {};
template<typename U>
struct error_return_type_or_void
<U, decltype(std::declval<U&>().error(), void())>
: type_is<decltype(std::declval<U&>().error())> {};
auto f() -> typename error_return_type_or_void<>::type {
return t.error();
}
};