jav*_*red 3 c++ boost boost-unordered
在C#
我喜欢的TryGetValue
方法,Dictionary
因为它允许我在一个调用中确定字典是否包含键和接收值,如果是这样:
Instrument instrument;
if (isinId2Instrument.TryGetValue(isin_id, out instrument))
{
// key exist, instrument contains value
} else {
// key doesn't exist
}
Run Code Online (Sandbox Code Playgroud)
我该怎么做同样的事情boost::unordered_map
?
用途boost::unordered_map::find()
:
boost::unordered_map<std::string, int>::iterator i = m.find("hello");
if (i != m.end())
{
std::cout << i->first << "=" << i->second << "\n";
}
else
{
std::cout << "Not found\n";
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
747 次 |
最近记录: |