samedi 28 novembre 2015

Vector find function working in Visual Studio but not in GCC

I have a function that does what I want it to do in Visual Studio, and I was transferring it to GCC to make sure everything worked there.

I now have a plethora of compilation errors stemming from my use of the std::find function.

I was hoping someone could take a look and help me figure out why I am only getting these errors in GCC. Here is a sample of the code: http://cpp.sh/6pky

// Example program
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
using namespace std;

int main()
{
   vector < list < pair <string, string> > > v;
   v.resize(15);
   pair<string, string> k ("foo", "bar");
   auto & whichList = v[2];
   if(find(begin(whichList), end(whichList), k) != end(whichList))
       cout << "true";

}

The part in question is find(begin(whichList), end(whichList), k).

I am getting an error that says I cannot compare a list of pairs with a pair (an issue I have been dealing a lot with this week) which I understand. I'm mostly curious as to why VS2015 not only doesn't recognize this error, but also performs the task appropriately.

Aucun commentaire:

Enregistrer un commentaire