Question

I'm trying to use the min_element for array of structures, but I simply can't define the binary function for that operation.

I would like to define that structure implicitly, without the , but

Is it okay? I tried almost everything but nothing seems to work.

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

instead I'm getting weird errors that I'm not implementing it right and there are overloading issues with one of the types which I don't know which exactly.

Thanks for your help.

I just need an example for a working MIN_ELEMENT function with binary predicate acceptance.

Thanks again!

Was it helpful?

Solution

It looks like you have the template arguments to the binary_function in the wrong order. The return type follows the argument types and not the otherway around. Off the top of my head, binary predicate to do the comparison you are looking for should look something like this (buyer beware, never been near a compiler):

struct pred: public binary_function<float3,float3,bool>
{
    __device__ bool operator()(const float3 &a, const float3 &a) const
    {
        return a.x > b.x;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top