c++ - How to use custom equality via lambda to find a tuple with one matching element in a std::vector -
say have std::list looks this:
std::list< std::tuple< uint, size_t, uint > > foolist;
it's not sorted in way, , given uint, i'd search through list , find whether there's tuple matches uint using lastly element (i.e. <*, *, uint match>). example, if have did this:
foolist.emplace_back(100, 0x1000, 200); foolist.emplace_back(200, 0x2000, 400); foolist.emplace_back(400, 0x4000, 800);
if 400, should find 1 0x2000, if 100, should find nothing.
i looking solution using lambdas. please allow me know. thanks.
uint key = 400; auto p = std::find_if(foolist.begin(), foolist.end(), [key](const std::tuple<uint, size_t, uint>& t) { homecoming std::get<2>(t) == key; }); if (p != foolist.end()) { // found p } // else not found
c++ c++11 lambda std
No comments:
Post a Comment