gpt4 book ai didi

c++ - 简单程序中的意外推力错误

转载 作者:太空狗 更新时间:2023-10-29 23:12:40 27 4
gpt4 key购买 nike

使用 Visual Studio 2017 和 Thrust 库,我编译了以下程序:

#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;
}

但是,我得到以下编译器错误:

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

详细信息如下

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

我不确定为什么编译器会报告 Thrust 类型未定义或为什么我的代码会导致错误开始。在我看来,这就像是 thrust::make_transform_iterator 的标准用法。

为什么会产生这个错误,我该如何解决?

另外,如果它很重要,我用标志编译

/DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_CPP /std:c++latest

谢谢你的帮助!

更新:上面的测试程序使用 Clang 编译成功。因此,该问题似乎与 VC++ 具体相关。

最佳答案

您必须包含定义类型 result_of_adaptable_function 的 header

像这样的一行

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

应该能成功。

您缺少使其正常工作的适当包含。

关于c++ - 简单程序中的意外推力错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44359124/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com