Код: Выделить всё
#include
#include
struct A { void bar() const; };
template
decltype(std::declval().bar()) foo(T const& a);
void foo() { A a; return foo(a); }
< /code>
Скомпилируется в (GCC 5.2.0): < /p>
foo():
sub rsp, 24
lea rdi, [rsp+15]
call decltype ((((declval)()).bar)()) foo(A const&)
add rsp, 24
ret
< /code>
Вторая версия, почти эквивалентная, где тип выражения разрешается как часть дополнительного параметра шаблона: < /p>
#include
#include
struct A { void bar() const; };
template
R foo(T const& a);
void foo() { A a; return foo(a); }
< /code>
Скомпилируется в (GCC 5.2.0): < /p>
foo():
sub rsp, 24
lea rdi, [rsp+15]
call void foo(A const&)
add rsp, 24
ret
Подробнее здесь: https://stackoverflow.com/questions/346 ... ymbol-name
Мобильная версия