0

Is there a way to use the .find(itr, itr, value) algorithm over the keyset of a map? I know you could use an iterator over the map to transfer the key values into a set (and then use that), but I wasn't sure if there was a quicker way to do so.

4

1 回答 1

1

您可能最好使用std::map<K, V>'find()成员,因为这利用了maps 内部结构。如果你真的想找到一些东西,例如,因为你只是在键中寻找一个属性,你需要使用std::find_if()

auto it = std::find_if(m.begin(), m.end(),
    [=](decltype(*m.begin()) const& e){
        return e.first == v;
    });
于 2012-11-18T21:49:44.977 回答