以下代码(最初来自Boost)无法使用启用了C ++ 11支持的nvcc 7.0进行编译:
#include <memory>
template<typename T>
struct result_of_always_void
{
typedef void type;
};
template<typename F, typename Enable = void> struct cpp0x_result_of_impl {};
template<typename F,typename T0>
struct cpp0x_result_of_impl<F(T0), typename result_of_always_void< decltype(std::declval<F>()(std::declval<T0 >()))>::type >
{
typedef decltype(std::declval<F>()(std::declval<T0 >())) type;
};
int main ()
{
return 0;
}
我得到的错误如下:
test.cu:16:93: error: invalid use of qualified-name ‘std::allocator_traits<_Alloc>::propagate_on_container_swap’
typedef decltype(std::declval<F>()(std::declval<T0 >())) type;
^
我怀疑这是由于nvcc编译器中的一个错误,但在我提交错误之前,我想问一下是否有可能进一步简化代码,同时还会产生错误?
答案 0 :(得分:4)
该问题似乎已在cuda 7.5RC中修复。请切换到较新的cuda版本。
$ cat t877.cu
#include <memory>
template<typename T>
struct result_of_always_void
{
typedef void type;
};
template<typename F, typename Enable = void> struct cpp0x_result_of_impl {};
template<typename F,typename T0>
struct cpp0x_result_of_impl<F(T0), typename result_of_always_void< decltype(std::declval<F>()(std::declval<T0 >()))>::type >
{
typedef decltype(std::declval<F>()(std::declval<T0 >())) type;
};
int main ()
{
return 0;
}
$ /usr/local/cuda-7.0/bin/nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2015 NVIDIA Corporation
Built on Mon_Feb_16_22:59:02_CST_2015
Cuda compilation tools, release 7.0, V7.0.27
$ /usr/local/cuda-7.0/bin/nvcc -std=c++11 t877.cu -o t877
t877.cu:14:93: error: invalid use of qualified-name âstd::allocator_traits<_Alloc>::propagate_on_container_swapâ
typedef decltype(std::declval<F>()(std::declval<T0 >())) type;
^
$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2015 NVIDIA Corporation
Built on Thu_May__7_00:35:41_CDT_2015
Cuda compilation tools, release 7.5, V7.5.6
$ nvcc -std=c++11 t877.cu -o t877
$
当然,欢迎您提交错误。