Using Visual Studio 2017 and the Thrust library, I compiled the following program:
#include <thrust/iterator/counting_iterator.h>
#include <thrust/iterator/transform_iterator.h>
template<int c>
struct computes_mod
{
auto operator()(int i) const
{
return i % c;
}
};
int main()
{
auto ti = thrust::make_transform_iterator(thrust::make_counting_iterator(0), computes_mod<3>{});
return 0;
}
However, I get the following compiler errors:
C2027 use of undefined type 'thrust::detail::result_of_adaptable_function'
C3646 'type': unknown override specifier
C4430 missing type specifier - int assumed. Note: C++ does not support default-int
whose details are given as
1>main.cpp
1>c:\program files\nvidia gpu computing toolkit\cuda\v8.0\include\thrust\detail\type_traits.h(440): error C2027: use of undefined type 'thrust::detail::result_of_adaptable_function<UnaryFunc (int),void>'
1> with
1> [
1> UnaryFunc=computes_mod<3>
1> ]
1>c:\program files\nvidia gpu computing toolkit\cuda\v8.0\include\thrust\iterator\detail\transform_iterator.inl(40): note: see declaration of 'thrust::detail::result_of_adaptable_function<UnaryFunc (int),void>'
1> with
1> [
1> UnaryFunc=computes_mod<3>
1> ]
1>c:\program files\nvidia gpu computing toolkit\cuda\v8.0\include\thrust\iterator\detail\iterator_adaptor_base.h(53): note: see reference to class template instantiation 'thrust::detail::eval_if<true,DefaultNullaryFn,thrust::detail::identity_<System>>' being compiled
1> with
1> [
1> DefaultNullaryFn=thrust::detail::result_of_adaptable_function<computes_mod<3> (int),void>,
1> System=thrust::use_default
1> ]
1>c:\program files\nvidia gpu computing toolkit\cuda\v8.0\include\thrust\iterator\detail\transform_iterator.inl(41): note: see reference to class template instantiation 'thrust::detail::ia_dflt_help<Reference,thrust::detail::result_of_adaptable_function<UnaryFunc (int),void>>' being compiled
1> with
1> [
1> Reference=thrust::use_default,
1> UnaryFunc=computes_mod<3>
1> ]
1>c:\program files\nvidia gpu computing toolkit\cuda\v8.0\include\thrust\iterator\transform_iterator.h(191): note: see reference to class template instantiation 'thrust::detail::transform_iterator_base<AdaptableUnaryFunction,Iterator,Reference,Value>' being compiled
1> with
1> [
1> AdaptableUnaryFunction=computes_mod<3>,
1> Iterator=thrust::counting_iterator<int,thrust::use_default,thrust::use_default,thrust::use_default>,
1> Reference=thrust::use_default,
1> Value=thrust::use_default
1> ]
1>[my_project]\main.cpp(32): note: see reference to class template instantiation 'thrust::transform_iterator<computes_mod<3>,thrust::counting_iterator<int,thrust::use_default,thrust::use_default,thrust::use_default>,thrust::use_default,thrust::use_default>' being compiled
1>c:\program files\nvidia gpu computing toolkit\cuda\v8.0\include\thrust\detail\type_traits.h(440): error C3646: 'type': unknown override specifier
1>c:\program files\nvidia gpu computing toolkit\cuda\v8.0\include\thrust\detail\type_traits.h(440): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
I am not sure why the compiler would report that the Thrust type is undefined or why my code causes an error to begin with. This looks to me like a standard usage of thrust::make_transform_iterator.
Why is this error produced and how can I fix it?
Also, in case it is important, I compiled with the flags
/DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_CPP /std:c++latest
Thank you for the help!
Update: the test program above compiles successfully using Clang. The problem thus appears to be related to VC++ specifically.