Remove duplicate entries of struct from a vector in c++

Viewed 53

I have a vector of structures, the structure is like this,

typedef struct Data
{
    char name[12];
    int  POS ;
    char Record[600];
};

The vector is sorted on POS. The situation is like that more than one record can have the same key value and different value in the char array Record, in that case, we have to consider those as different records. My problem is, that the vector is having some nonconsecutive duplicate elements. I want to remove those, is there any methods for that. I have tried std::erase and std::unique, but I feel they only remove consecutive duplicate elements. The code I have written is.

auto isEqual = [](const Data &lhs, const Data &rhs)
    {
       
    return (strcmp(lhs.Record,rhs.Record) == 0);
    };

main()
{
    stringstream s;
    string line;
    std::vector v;
    std::vector sortedV;
    std::string name = "/path/Input_File.txt";
    std::ifstream sortedFile(name.c_str());
    if(!sortedFile)
        cout<<"Fie openning error"<<endl;
    Data *d = (Data*)malloc(sizeof(Data));
    
    getline(sortedFile, line);

    stringstream s(line);
    while(s>>word)
    {
        wordCount++;
        if(wordCount == 3)
        {
            strcpy(sd->RNAME,word.c_str());
            int No = getNumberFromString(word);
            strcpy(sd->wholeRecord,line.c_str());
            s >> word;
            stringstream geek(word);
            geek>>sd->POS;
            //cout<<sd->POS<<endl;
            geek.clear();
            
            break;
        }
    }
    v.push_back(*d);
    chromNo.push_back(No);
    startPos.push_back(d->POS);
    free(d);

    sortedV = sortData(v,No,startPos);//This works Fine, Sort the vector. 
    
    sortedV.erase(std::remove_if(sortedV.begin(), sortedV.end(),isEqual), sortedV.end());// This is the problematic line.  

}

In the above code

 sortedV.erase(std::remove_if(sortedV.begin(), sortedV.end(),isEqual), sortedV.end());

by this line of code, I am trying to remove the nonconsecutive duplicate entries from the vector. But every time the error I am getting is

error: function "lambda [](const SAMData &, const SAMData &)->__nv_bool" cannot be called with the given argument list argument types are: (SAMData) object type is: lambda [](const SAMData &, const SAMData &)->__nv_bool detected during:

I am not getting how to call the function isEqual or write some thing else replacing isEqual. Thanks In advance.

0 Answers
Related