我在构建使用 Boost.Compute 库的程序时遇到问题。我使用zip_iterator
由两个浮点迭代器组成的元组组成的两个 s 来使用该函数对两个浮点向量进行排序boost::compute::sort()
。我的代码(compute::vector
之前两个都填充了浮点值):
typedef compute::vector<float>::iterator Float_Iterator;
typedef boost::tuple<Float_Iterator, Float_Iterator> Sort_Tuple;
typedef compute::zip_iterator<Sort_Tuple> Sort_Iterator;
Sort_Iterator first_sort = compute::make_zip_iterator
(boost::make_tuple(d_x.begin(), d_y.begin()));
Sort_Iterator last_sort = compute::make_zip_iterator
(boost::make_tuple(d_x.end(), d_y.end()));
BOOST_COMPUTE_FUNCTION(bool, compare, (const boost::tuple<float, float> p1, const boost::tuple<float, float> p2),
{
return boost_tuple_get(p1, 0) < boost_tuple_get(p2, 0);
}
);
compute::sort(first_sort, last_sort, compare, queue);
编译时,我收到:
error C2782: 'void boost::compute::detail::dispatch_merge_blocks(Iterator,Iterator,Compare,size_t,c onst size_t,const size_t,const size_t,boost::compute::command_queue &)' : **template parameter 'Iterator' is ambiguous**
c:\local\boost_1_62_0\boost\compute\algorithm\detail\merge_sort_on_cpu.hpp(129) : see declaration of 'boost::compute::detail::dispatch_merge_blocks'
could be **'Sort_Iterator'
or 'boost::compute::buffer_iterator<T>'**
with
[
T=value_type
]
正如您在我的代码中看到的,我使用Sort_Iterator
之前声明的两个 s 调用该函数。两个参数具有相同的类型,那么编译器为什么要假设任何歧义呢?我不明白这个。
但是,如果我尝试显式类型转换函数参数,例如
compute::sort((Sort_Iterator)first_sort, (Sort_Iterator)last_sort, compare, queue);
错误消息的后半部分更改为:
could be **'boost::compute::zip_iterator<Sort_Tuple>'
or 'boost::compute::buffer_iterator<T>'**
with
[
T=value_type
]