C++11 CUDA 10.1 SFINAE模板编译错误

C++11 CUDA 10.1 SFINAE模板编译错误,c++11,cuda,C++11,Cuda,CUDA 10.1 g++7.3 为了单元测试套件的目的,我需要大量可重复的数据(超过硬编码的数据)。我提出了这个“生成器”范例,其思想是可以用它来用数据填充任意容器 现在,我需要扩展生成器以填充多值容器(float2,int2,推力::复数)。我的解决方案是使用SFINAE有条件地定义一个函数,基于它是可以从单个值构造还是需要一对值 下面的代码在GCC中编译良好(-std=c++1z),但在nvcc中编译失败(-std=c++14) #包括 #包括 模板 类随机发生器 { 公众: 随机发生器(

CUDA 10.1
g++7.3

为了单元测试套件的目的,我需要大量可重复的数据(超过硬编码的数据)。我提出了这个“生成器”范例,其思想是可以用它来用数据填充任意容器

现在,我需要扩展生成器以填充多值容器(
float2
int2
推力::复数
)。我的解决方案是使用SFINAE有条件地定义一个函数,基于它是可以从单个值构造还是需要一对值

下面的代码在GCC中编译良好(
-std=c++1z
),但在nvcc中编译失败(
-std=c++14

#包括
#包括
模板
类随机发生器
{
公众:
随机发生器(最小T,最大T,无符号种子=42);
//生成序列中的下一个元素。这需要保持所有必要的状态
//推进
T算子();
//如果容器是标量的,则填充该容器
模板
typename std::启用\u如果\u t
填充(容器和c);
//如果容器包含2个值(例如复杂值),则填充容器
模板
typename std::启用\u如果\u t
填充2(集装箱和集装箱);
受保护的:
私人:
标准:均匀实分布dist;
标准:mt19937 rng;
};
//构造函数-定义此生成的域
模板
RandomGenerator::RandomGenerator(最小T、最大T、无符号种子)
:距离(最小值、最大值)
,rng()
{
种子(种子);
}
//生成一个随机数
模板
T
RandomGenerator::运算符()
{
返回距离(rng);
}
模板
模板
typename std::启用\u如果\u t
随机生成器::填充(容器和c)
{
std::generate(c.begin(),c.end(),*this);
}
模板
模板
typename std::启用\u如果\u t
RandomGenerator::fill2(容器和c)
{
std::generate(c.begin(),c.end(),[this](){return typename Container::value_type((*this)(,(*this)();});
}
编译器错误:

/usr/local/cuda/bin/nvcc  -g -Xcompiler=-fPIE -gencode=arch=compute_60,code=sm_60 --std=c++14 --use_fast_math -Xcompiler -pthread -x cu -dc unittest.cu -o unittest.cu.o
RandomGenerator.hh(30): error: namespace "std" has no member "is_constructible_v"

RandomGenerator.hh(30): error: type name is not allowed

RandomGenerator.hh(30): error: expected an identifier

RandomGenerator.hh(34): error: namespace "std" has no member "is_constructible_v"

RandomGenerator.hh(34): error: type name is not allowed

RandomGenerator.hh(34): error: too many arguments for alias template "std::enable_if_t"

RandomGenerator.hh(34): error: expected an identifier

RandomGenerator.hh(63): error: namespace "std" has no member "is_constructible_v"

RandomGenerator.hh(63): error: type name is not allowed

RandomGenerator.hh(63): error: expected an identifier

RandomGenerator.hh(71): error: namespace "std" has no member "is_constructible_v"

RandomGenerator.hh(71): error: type name is not allowed

RandomGenerator.hh(71): error: too many arguments for alias template "std::enable_if_t"

RandomGenerator.hh(71): error: expected a ";"

我错过什么了吗?有没有办法把这个传给CUDA


更新

具体问题似乎与
std::enable_if_t
std::is_XXX_v
有关。如果不使用这些typdef,而是使用更详细的形式

typename std::enable\u if::type

然后nvcc可以处理它。

编译器错误提示您它不知道关于
std::is\u constructible\u v
的任何信息。 这不是因为从gcc切换到nvcc,而是因为从c++17切换到c++14。 您已经发现您可以使用
::value
表单,这就是方法。(当然,如果您计划在nvcc支持后立即将c++17作为项目的一项要求,您也可以扩展标准名称空间。)

虽然c++14中已经引入了
std::enable_if_t
,但是您可以保留它



<> P> >一般可以发现所有的代码> STD::某些C++ <代码>快捷方式可从C++ 14上获得,但是 STD::在C++ 17中引入了一些StaveVi快捷方式。显而易见的解决方案是删除
-xcu
标志
std::is_-constructible\u v
is C++17而不是C++14<代码>标准::如果\u t是C++14,则启用。更一般地说:所有
::value
快捷键都是C++17,所有
::type
快捷键都是C++14。所以只要用长的形式表示
是可构造的,你就很好了。如果你给出答案,我会接受的。