An unexpected error in a simple program

Using Visual Studio 2017 and Thrust, 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 am getting the following compiler errors:

C2027 using undefined type 'thrust :: detail :: result_of_adaptable_function'
C3646 'type': unknown override specifier
C4430 missing type specifier - int. Note: C ++ does not support default-int

the details of which are listed 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 don't know why the compiler will tell you that the Thrust type is undefined or why my code is throwing an error. This looks like standard usage thrust::make_transform_iterator

.

Why does this error occur and how can I fix it?

Also, in case it matters, I compiled with the flags

/DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_CPP /std:c++latest

      

Thanks for the help!

Update: The test program above compiles successfully with Clang. So the problem is related to VC ++ in particular.

+3


source to share


1 answer


You must include a header that defines the type result_of_adaptable_function

Line like

#include <thrust/detail/type_traits/result_of_adaptable_function.h>

      



must do the trick.

You are missing the correct inclusions to make it work.

0


source







All Articles