- 252 名前:デフォルトの名無しさん (ワッチョイ 0b59-C4NQ) mailto:sage [2017/04/23(日) 11:36:55.65 ID:onWybp6E0.net]
- 質問
std::map<key_t, int>にkey_t型のブツの個数を格納したいのですが、どう書くのがSTL的に推奨? 仮に typedef std::map<key_t, value_t> dic_t; dic_t dic; key_t key; であるとして、 (1) std::pair<dic_t::iterator, bool> result = dic.insert(dic_t::value_type(key, 1)); if (!result.second) { result.first->second++; } (2) dic_t::iterator it = dic.find(key); if (it == dic.end()) { dic[key] = 1; } else { it->second++; } (3) その他 みたいな?
|

|