vendredi 3 juin 2016

How to use std::find on a vector of array?

I am on Ubuntu 14.04, g++ 4.9.3. The code below

std::vector<std::array<int, 3>> a;
a.push_back({2, 3, 1});
a.push_back({1, 3, 4});
a.push_back({3, 1, 2});

auto it = std::find(a.begin(), a.end(), {2, 3, 1});

returns an error

couldn't deduce template parameter ‘_Tp’
      std::find(a.begin(), a.end(), {2, 3, 1});
                                             ^

After a few googling sessions I figured out a more elaborate way to use std::find_if with a lambda function to solve this problem, but why doesn't this code work?

Aucun commentaire:

Enregistrer un commentaire