实现推力二元谓词

时间:2011-11-02 07:09:31

标签: c++ cuda thrust

我正在尝试将min_element用于结构数组,但我根本无法为该操作定义二进制函数。

我想隐式地定义该结构,没有,但是

可以吗?我几乎尝试了一切,但似乎没有任何工作。

struct pred : public binary_function <bool , float3 , float3>
{
   bool operator () ( const float3 a, const float3 b)
   {
      return a.x > b.x;
   }
}

相反,我得到了奇怪的错误,我没有正确实现它,并且有一种类型的重载问题,我不知道究竟是哪一种。

感谢您的帮助。

我只需要一个带有二元谓词接受的工作MIN_ELEMENT函数的示例。

再次感谢!

1 个答案:

答案 0 :(得分:3)

看起来你有错误顺序的binary_function的模板参数。返回类型遵循参数类型而不是其他方式。在我的头脑中,二元谓词做你正在寻找的比较应该看起来像这样(买家要小心,从来没有在编译器附近):

struct pred: public binary_function<float3,float3,bool>
{
    __device__ bool operator()(const float3 &a, const float3 &a) const
    {
        return a.x > b.x;
    }
}
相关问题