尝试在 Thrust 设备比较器上使用模板时出现问题

Issue trying to use Templates on a Thrust device comparator

结构的声明非常简单。出于某种原因,当我从不尝试使用模板来定义比较器时,我无法使用与该元组关联的 .get() ,因此以下代码在 t1.get<0>() 和所有其他代码处抛出错误。我想了解为什么当您使用模板时,元组不再 rhas .get() 作为其上的函数。

template<typename FirstType, typename SecondType>
struct TupleComp{

    typedef typename thrust::device_vector<FirstType >::iterator firstIter;
    typedef typename thrust::device_vector<SecondType>::iterator secondIter;

    typedef typename thrust::tuple<firstIter,secondIter> TupleType;

     __host__ __device__
    bool operator()(const TupleType &t1, const TupleType &t2)
    {
        // thrust::tuple<thrust::device_vector<long long>::iterator > tup;
         TupleType tup;


         if(t1.get<0>() < t2.get<0>()){
             return true;
         }

         if(t1.get<0>() > t2.get<0>()){
             return false;
         }

         return (t1.get<1>() < t2.get<1>());

     }
};

下面是类似的代码

struct TupleCompUllFirstLLSecond{


    typedef typename thrust::tuple<thrust::device_vector<unsigned long long>::iterator,thrust::device_vector<long long>::iterator> TupleType;

     __host__ __device__
    bool operator()(const TupleType &t1, const TupleType &t2)
    {

         if(t1.get<0>() < t2.get<0>()){
             return true;
         }

        if(t1.get<0>() > t2.get<0>()){
             return false;
        }

         return (t1.get<1>() < t2.get<1>());

    }
};

感谢 Robert Crovella(他巧合地解决了我迄今为止所有的重点问题)解决方案修复了我在比较和使用 thrust::get 而不是元组 t1.get。工作比较函子是:

template<typename FirstType, typename SecondType>
struct TupleComp{



    typedef typename thrust::tuple<FirstType,SecondType> TupleType;

     __host__ __device__
    bool operator()(const TupleType &t1, const TupleType &t2)
    {

         FirstType leftFirst = thrust::get<0>(t1);
         FirstType rightFirst = thrust::get<0>(t2);


         if(leftFirst < rightFirst){
             return true;
         }

         if(leftFirst > rightFirst){
             return false;
         }

         SecondType leftSecond = thrust::get<1>(t1);
         SecondType rightSecond = thrust::get<1>(t2);


         return leftSecond < rightSecond;

    }
};