, .
- , , . , , O (n).
, for(), std::find_if(). find_if(), . ++ 11 lambda:
typedef std::map <unsigned, Student> MyMap;
MyMap myMap;
const string targetName = "Jones";
find_if (myMap.begin(), myMap.end(), [&targetName] (const MyMap::value_type& test)
{
if (test.second.mName == targetName)
return true;
});
++ 03, :
struct MatchName
: public std::unary_function <bool, MyMap::value_type>
{
MatchName (const std::string& target) : mTarget (target) {}
bool operator() (const MyMap::value_type& test) const
{
if (test.second.mName == mTarget)
return true;
return false;
}
private:
const std::string mTarget;
};
find_if (myMap.begin(), myMap.end(), MatchName (target));
- . , , , - , , - - .
, Student, , - , . , , (, multimap), - . , Student.
. , ( ) . , , , -, , . , , , .