lundi 30 novembre 2015

C++ Std::find() fails over generics

The given Error when I am passing in a type as string from the non generic driver class using C++11 (psuedocode below, can't really provide a compilable small example):

stl_algo.h|135|error: no match for 'operator==' in '__first.std::_List_iterator<_Tp>::operator*<std::pair<std::basic_string<char>, std::basic_string<char> > >() == __val'|

I have a vector of Generic type

template <typename A, typename B>
vector<list<pair<A,B>> > myList;

I am trying to insert/remove elements from this list of pairs and am running into this type of error.

.#include <algorithm>

template <typename A, typename B>
bool addToList(const pair<A,B> &searchPair){

    auto & tempIndexList = myList[0];
    auto itr = std::find(std::begin(tempIndexList),std::end(tempIndexList), searchPair.first);  //Line where error occurs

}

I have tried changing from 'searchPair.first' to just 'searchPair' and it still fails with the same error. I'm thinking it has something to do with the fact that it is const, but I'm not really sure as it doesn't seem like it should be causing an error.

Any help is appreciated, thanks

Aucun commentaire:

Enregistrer un commentaire