【发布时间】:2014-01-05 22:04:39
【问题描述】:
当我以下列方式using SFINAE with functions/function members时:
#include <type_traits>
#include <iostream>
#include <cstdlib>
struct X {};
struct A
{
template< typename T >
auto
f(T && x)
-> std::enable_if< std::is_same< T, X >::value >::type
{
return x;
}
};
int main()
{
return EXIT_SUCCESS;
}
我收到一个错误:
main.cpp:14:8: error: expected type-specifier
-> std::enable_if< std::is_same< T, X >::value >::type
^
main.cpp:14:8: error: expected initializer
因此,我应该在启动器前面加上 typename 关键字。但这里完全没有歧义:因为我现在只在-> 之后输入预期的内容。另一个提示是 Qt Creator's 在这种情况下 typename 关键字的基础。
这是 G++ 错误吗?还是在 C++11 中针对此类上下文声明 typename?
【问题讨论】:
-
@DanielFrey 我在stackoverflow.com/questions/610245 中找不到类似的上下文。
标签: c++ templates c++11 g++ c++14