>>704
いや、ordered_が付かないmapやsetは、順序で並び替えることも定義の一部になっていて、
範囲forで巡ると、挿入した順序ではなく、比較関数で比較した結果に基いてソートされた順序になる。
https://stackoverflow.com/questions/7648756/is-the-order-of-iterating-through-stdmap-known-and-guaranteed-by-the-standard
Yes, that's guaranteed. Moreover, *begin() gives you the smallest
C++
・std::map is a sorted associative container
https://stackoverflow.com/questions/11274978/are-c-stdmapstring-string-ordered
are STL maps ordered?
Yes, a std::map<K,V> is ordered based on the key, K, using std::less<K> to compare objects, by default.
So if I iterate over it, it will iterate with the first insert string first?
No. It will iterate based on the sorted order, not the order that you inserted elements. In the case of std::string, it sorts in lexicographic order (alphabetic order).
If you want to iterate based on the insertion order, you're better off using a sequence container, such as a std::vector or a std::list.
探検
C++相談室 part162
■ このスレッドは過去ログ倉庫に格納されています
727デフォルトの名無しさん (オイコラミネオ MM7b-VZV0)
2022/12/14(水) 18:13:49.08ID:ekFaWlb/M■ このスレッドは過去ログ倉庫に格納されています
ニュース
- 今後50年間、毎年100万人ずつ人口が減る…「少子化対策」の失敗で日本が迎える「死ぬまで搾取」というヤバい未来 ★6 [ぐれ★]
- 「インバウンド政策上、中国は重要」、訪日自粛で金子国交相「早く通常の状況に戻っていただきたい」★2 [ぐれ★]
- 《「最近いつした?」が口癖》国分太一 女性への“わいせつ事案”報道…目撃されていた「下ネタ好き」と「悪辣なイジり癖」★2 [Ailuropoda melanoleuca★]
- Amazonブラックフライデー 活況の裏に過酷労働 事故やケガを「自己責任にしないで」配達員ら4年連続抗議 [蚤の市★]
- 【映画】細田守監督作『果てしなきスカーレット』はなぜ苦戦かつ低評価?「ミスマッチ」と問題作になった理由は [muffin★]
- 高市首相が代表の政党支部、企業から上限超える寄付 公表後に訂正 [どどん★]
- ワイの通り名が「キモハゲワキガなんやが」
- 頭おかしくなるのが怖い
- 【悲報】男さん「男も『助産師』にさせろ!」女性「男の助産師とか犯罪者かな?そんなにしたければ馬とか牛とか畜生の助産師やれよ」93億 [257926174]
- 【動画】上海バンダイナムコフェス、ワンピース歌ってる途中に中国政府「日本人の公演全面禁止」発令された瞬間強制終了 怖すぎ★5 [579392623]
- 中国「台湾の件でうちの味方してよ😭」🇫🇷🇬🇧「えぇ…」
- 【悲報】男のくせに女性専用車両に乗った30代の男さん、駅員に電車から無理やり降ろされてしまうwwwwwwwwwwwwwwwwww [257926174]
