Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/133.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在一起使用boost compute和boost::range时,如何避免boost::compute::zip_迭代器和boost::iterators::zip_迭代器冲突?_C++_Visual Studio 2015_Boost Range_Boost Iterators_Boost Compute - Fatal编程技术网

C++ 在一起使用boost compute和boost::range时,如何避免boost::compute::zip_迭代器和boost::iterators::zip_迭代器冲突?

C++ 在一起使用boost compute和boost::range时,如何避免boost::compute::zip_迭代器和boost::iterators::zip_迭代器冲突?,c++,visual-studio-2015,boost-range,boost-iterators,boost-compute,C++,Visual Studio 2015,Boost Range,Boost Iterators,Boost Compute,我想同时使用boost::compute和boost::range,如下所示,但是如果我取消注释\include行,我会收到一个错误,指出boost::compute::zip_迭代器和boost::迭代器::zip_迭代器是不明确的。有没有办法解决这个问题,这样我就可以在同一个cpp文件中同时使用boost::compute和boost::range?我在Windows vs2015上使用64位。升压1.67.0 更新:我发现如果我尝试包含boost/iterator/zip_iterator

我想同时使用
boost::compute和boost::range
,如下所示,但是如果我取消注释
\include
行,我会收到一个错误,指出
boost::compute::zip_迭代器
boost::迭代器::zip_迭代器
是不明确的。有没有办法解决这个问题,这样我就可以在同一个cpp文件中同时使用
boost::compute
boost::range
?我在Windows vs2015上使用64位。升压1.67.0

更新:我发现如果我尝试包含
boost/iterator/zip_iterator.hpp
而不是
boost/range/combine.hpp
,则会出现相同的错误,因此它不是特定于boost范围库的

代码:

#包括
#包括
#包括
//#包括
#包括
#包括
#包括
#包括
名称空间compute=boost::compute;
使用compute::float4;
使用compute::lambda::1;
使用compute::lambda::2;
使用compute::lambda::distance;
int main()
{
//获取默认设备和设置上下文
compute::device device=compute::system::default_device();
compute::上下文(设备);
compute::命令队列(上下文、设备);
//在主机上生成随机数据
std::载体a(10000);
std::载体b(10000);
std::向量r(10000);
std::generate((float*)a.data(),(float*)(a.data()+a.size()),rand);
std::generate((float*)b.data(),(float*)(b.data()+b.size()),rand);
//在设备上创建向量
compute::vector_a(a.size(),context);
compute::vector_b(b.size(),上下文);
compute::vector(r.size(),context);
//将数据从主机传输到设备
compute::copy(a.begin(),a.end(),_a.begin(),queue);
compute::copy(b.begin(),b.end(),_b.begin(),queue);
boost::compute::transform(
_a、 begin(),_a.end(),
_b、 begin(),
_r、 begin(),
距离(_1,_2),
队列
);
//将值复制回主机
compute::copy(_r.begin(),_r.end(),r.begin(),queue);
对于(int i=0;i
C:\local\boost\u 1\u 67\u 0\boost/compute/iterator/zip\u iterator.hpp(276):
注:可能是
'boost::compute::zip_迭代器,boost::compute::buffer_迭代器,boost::tuples::null_类型,boost::tuples::null_类型,boost::tuples::null_类型,boost::tuples::null_类型,boost::tuples::null_类型,boost::tuples::null_类型,boost::tuples::null_类型>>
boost::compute::make_-zip_迭代器,boost::compute::buffer_迭代器,boost::tuples::null_类型,boost::tuples::null_类型,boost::tuples::null_类型,boost::tuples::null_类型,boost::tuples::null_类型,boost::tuples::null_类型>>(迭代器)
1> 用1>[1>
T=boost::compute::float4\u1>
IteratorTuple=boost::tuples::tuples::compute::buffer\u迭代器,boost::tuples::null\u类型,boost::tuples::null\u类型,boost::tuples::null\u类型,boost::tuples::null\u类型,boost::tuples::null\u类型,boost::tuples::null\u类型,boost::tuples::null\u类型> 1> ] 1> C:\local\boost\u 1\u 67\u 0\boost/iterator/zip\u iterator.hpp(357):注意:或
'boost::iterators::zip\u迭代器,boost::compute::buffer\u迭代器,boost::tuples::null\u类型,boost::tuples::null\u类型,boost::tuples::null\u类型,boost::tuples::null\u类型,boost::tuples::null\u类型,boost::tuples::null\u类型,boost::tuples::null\u类型>> boost::迭代器::make_-zip_迭代器,boost::compute::buffer_迭代器,boost::tuples::null_类型,boost::tuples::null_类型,boost::tuples::null_类型,boost::tuples::null_类型,boost::tuples::null_类型,boost::tuples::null_类型>>(迭代器) [使用参数相关查找找到]1>和1>[ 1> T=boost::compute::float4\u1>
IteratorTuple=boost::tuples::tuples::compute::buffer\u迭代器,boost::tuples::null\u类型,boost::tuples::null\u类型,boost::tuples::null\u类型,boost::tuples::null\u类型,boost::tuples::null\u类型,boost::tuples::null\u类型,boost::tuples::null\u类型> 1> ] 1> C:\local\boost\u 1\u 67\u 0\boost/compute/algorithm/transform.hpp(67):注意: 在尝试匹配参数列表时 “(boost::tuples::tuple,boost::compute::buffer\u迭代器,boost::tuples::null\u类型,boost::tuples::null\u类型,boost::tuples::null\u类型,boost::tuples::null\u类型,boost::tuples::null\u类型,boost::tuples::null\u类型,boost::tuples::null\u类型>)” 1> 用1>[1>
T=boost::compute::float4\u1>]1> C:\workspace\compute\u test\src\demo.cpp(45):注意:请参阅参考 函数模板实例化“输出计算器” boost::compute::transform、boost::compute::buffer\u迭代器、boost::compute::buffer\u迭代器、boost::compute::lambda::expression>(输入、输入、输出、二进制运算符、boost::compute::command\u队列 &)'正在用1>[1>
OutputIterator=boost::compute::buffer\u迭代器,1>
T=boost::compute::float4\u1>
Expr=boost::proto::exprns\uu::basic\u Expr,0>>,常量 boost::compute::lambda::expression>,0>> &,常数 boost::compute::lambda::expression>,0>> &>,3>,1>
InputIterator1=boost::compute::buffer\u迭代器, 1>
InputIterator2=boost::compute::buffer\u迭代器, 1>
BinaryOperator=boost::compute::lambda::expression,0>>,常量 boost::compute::
#include <vector>
#include <iostream>
#include <algorithm>
//#include <boost/range/combine.hpp>
#include <boost/compute/lambda.hpp>
#include <boost/compute/functional/math.hpp>
#include <boost/compute/container/vector.hpp>
#include <boost/compute/algorithm/transform.hpp>

namespace compute = boost::compute;
using compute::float4_;
using compute::lambda::_1;
using compute::lambda::_2;
using compute::lambda::distance;

int main()
{
    // get default device and setup context
    compute::device device = compute::system::default_device();
    compute::context context(device);
    compute::command_queue queue(context, device);

    // generate random data on the host
    std::vector<float4_> a(10000);
    std::vector<float4_> b(10000);
    std::vector<float> r(10000);
    std::generate((float*)a.data(), (float*)(a.data() + a.size()), rand);
    std::generate((float*)b.data(), (float*)(b.data() + b.size()), rand);

    // create a vector on the device
    compute::vector<float4_> _a(a.size(), context);
    compute::vector<float4_> _b(b.size(), context);
    compute::vector<float> _r(r.size(), context);

    // transfer data from the host to the device
    compute::copy(a.begin(), a.end(), _a.begin(), queue);
    compute::copy(b.begin(), b.end(), _b.begin(), queue);

    boost::compute::transform(
        _a.begin(), _a.end(),
        _b.begin(),
        _r.begin(),
        distance(_1, _2),
        queue
    );

    // copy values back to the host
    compute::copy(_r.begin(), _r.end(), r.begin(), queue);

    for (int i = 0; i < a.size(); ++i)
    {
        float4_ va = a[i];
        float4_ vb = b[i];
        float vr = r[i];
        float e = std::sqrt(std::pow(va[0] - vb[0], 2) +
            std::pow(va[1] - vb[1], 2) +
            std::pow(va[2] - vb[2], 2) +
            std::pow(va[3] - vb[3], 2));

        std::cout << std::setprecision(12);

        if (std::abs(e - vr) > 1e-2)
            std::cout << e << " != " << vr << "\n";
    }

    return 0;
}