>>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■ このスレッドは過去ログ倉庫に格納されています
ニュース
- 【東京】逮捕された男2人が「児童の母親の友人」と判明 小学校側と話がまとまらずに母親が2人呼んだか 1人は容疑否認 立川市立三小 [ぐれ★]
- 三崎優太「永野芽郁を叩きすぎじゃない?人の不倫なんてどうでも良くない?」 [少考さん★]
- 【文春】永野芽郁(25)&田中圭(40)燃え上がる不倫LINE ★26 [Ailuropoda melanoleuca★]
- 【続報】東京・立川市の小学校 暴行容疑で男2人を逮捕 教師4人と用務員1人けが [夜のけいちゃん★]
- 【速報】トヨタ発表 2026年3月期の純利益予想34.9%減3兆1000億円 [蚤の市★]
- 【米】スーパーのコメ価格、4233円 17週連続値上がり 前年同期比で2145円高く ★4 [ぐれ★]
- 【悲報】斎藤元彦陣営のネット広報担当会社が投稿したnoteで騒然★679 [931948549]
- 永野芽郁、消され始める [606757419]
- 【緊急】日本の議員がまた中国と戦争しようとしてる理由 [943688309]
- 【悲報】北海道の社長、従業員を殴りまくってスポンサー契約解除されてしまう [705549419]
- 【画像】ケンモメン、ツーブロックにしてしまうwwwwwwwwwww [834922174]
- 石破政権、氷河期支援に続き「ひきこもり支援」も新指針… 日本社会、なんか彼らを救わないとヤバいみたいな空気になる [452836546]