Say I have more than one key with the same value in a map. Then in that case how do I retrieve all keys that matches a query.
Or, Is there any possibility to tell find operation to search after a specific value.
I am using an std::map, C++.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The associative containers probably won’t help you too much because for
std::map<K, V>the key happens to be unique and chances that your chosen query matches the ordering relation you used may not be too high. If the order matches, you can use thestd::map<K, V>memberslower_bound()andupper_bound(). Forstd::multimap<K, V>you can also useequal_range().In general, i.e., if you query isn’t really related to the order, you can use
std::copy_if()to get a sequence of objects matching a predicate:When copying the elements is too expensive, you should probably consider using
std:find_if()instead: