Difference between revisions of "cpp/container"
m (+todo) |
(+basic_string) |
||
Line 170: | Line 170: | ||
===Function table=== | ===Function table=== | ||
+ | |||
+ | Note: {{lc|std::basic_string}} is not treated as a container by the standard but behaves much like one due to its similarity. It is listed as 'Pseudo container' here for convenience. | ||
{| | {| | ||
Line 188: | Line 190: | ||
| - functions present since C++23 | | - functions present since C++23 | ||
|} | |} | ||
+ | |||
====Member function table==== | ====Member function table==== | ||
− | + | ||
<div style="display: inline-block;"> | <div style="display: inline-block;"> | ||
<div style="display: inline-block;"> | <div style="display: inline-block;"> | ||
Line 196: | Line 199: | ||
|- | |- | ||
| colspan="2" | | | colspan="2" | | ||
+ | ! colspan="1" | Pseudo container | ||
! colspan="5" | Sequence containers | ! colspan="5" | Sequence containers | ||
! colspan="4" | Associative containers | ! colspan="4" | Associative containers | ||
Line 203: | Line 207: | ||
|- | |- | ||
! colspan="2" | Header | ! colspan="2" | Header | ||
+ | ! {{tt|{{header|string}}}} | ||
! {{tt|{{header|array}}}} | ! {{tt|{{header|array}}}} | ||
! {{tt|{{header|vector}}}} | ! {{tt|{{header|vector}}}} | ||
Line 219: | Line 224: | ||
|- | |- | ||
! colspan="2" | Container | ! colspan="2" | Container | ||
+ | ! {{cpp/container/table cell ho | cpp/string/basic_string }} | ||
! {{cpp/container/table cell hn | /array }} | ! {{cpp/container/table cell hn | /array }} | ||
! {{cpp/container/table cell ho | /vector }} | ! {{cpp/container/table cell ho | /vector }} | ||
Line 243: | Line 249: | ||
! rowspan="5" | | ! rowspan="5" | | ||
| {{cpp/container/table cell lo | (constructor)}} | | {{cpp/container/table cell lo | (constructor)}} | ||
+ | | {{cpp/container/table cell o | cpp/string/basic_string/basic_string }} | ||
| {{cpp/container/table cell |(implicit)}} | | {{cpp/container/table cell |(implicit)}} | ||
| {{cpp/container/table cell o | /vector/vector }} | | {{cpp/container/table cell o | /vector/vector }} | ||
Line 268: | Line 275: | ||
<!-- ---> | <!-- ---> | ||
| {{cpp/container/table cell lo | (destructor)}} | | {{cpp/container/table cell lo | (destructor)}} | ||
+ | | {{cpp/container/table cell o | cpp/string/basic_string/~basic_string }} | ||
| {{cpp/container/table cell |(implicit)}} | | {{cpp/container/table cell |(implicit)}} | ||
| {{cpp/container/table cell o | /vector/~vector }} | | {{cpp/container/table cell o | /vector/~vector }} | ||
Line 292: | Line 300: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell lo | operator{{=}}}} | | {{cpp/container/table cell lo | operator{{=}}}} | ||
+ | | {{cpp/container/table cell o | cpp/string/basic_string/operator{{=}} }} | ||
| {{cpp/container/table cell |(implicit)}} | | {{cpp/container/table cell |(implicit)}} | ||
| {{cpp/container/table cell o | /vector/operator{{=}} }} | | {{cpp/container/table cell o | /vector/operator{{=}} }} | ||
Line 316: | Line 325: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell lo | assign}} | | {{cpp/container/table cell lo | assign}} | ||
+ | | {{cpp/container/table cell o | cpp/string/basic_string/assign }} | ||
| {{n/a||}} | | {{n/a||}} | ||
| {{cpp/container/table cell o | /vector/assign }} | | {{cpp/container/table cell o | /vector/assign }} | ||
Line 340: | Line 350: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell l23 | assign_range}} | | {{cpp/container/table cell l23 | assign_range}} | ||
+ | | {{cpp/container/table cell 23 | cpp/string/basic_string/assign_range }} | ||
| {{n/a||}} | | {{n/a||}} | ||
| {{cpp/container/table cell 23 | /vector/assign_range }} | | {{cpp/container/table cell 23 | /vector/assign_range }} | ||
Line 364: | Line 375: | ||
! rowspan="4" | Iterators | ! rowspan="4" | Iterators | ||
| {{cpp/container/table cell lon | begin|cbegin}} | | {{cpp/container/table cell lon | begin|cbegin}} | ||
+ | | {{cpp/container/table cell on | cpp/string/basic_string/begin |begin|cbegin }} | ||
| {{cpp/container/table cell nn | /array/begin |begin|cbegin}} | | {{cpp/container/table cell nn | /array/begin |begin|cbegin}} | ||
| {{cpp/container/table cell on | /vector/begin |begin|cbegin}} | | {{cpp/container/table cell on | /vector/begin |begin|cbegin}} | ||
Line 389: | Line 401: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell lon | end|cend}} | | {{cpp/container/table cell lon | end|cend}} | ||
+ | | {{cpp/container/table cell on | cpp/string/basic_string/end |end|cend }} | ||
| {{cpp/container/table cell nn | /array/end |end|cend}} | | {{cpp/container/table cell nn | /array/end |end|cend}} | ||
| {{cpp/container/table cell on | /vector/end |end|cend}} | | {{cpp/container/table cell on | /vector/end |end|cend}} | ||
Line 413: | Line 426: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell lon | rbegin|crbegin}} | | {{cpp/container/table cell lon | rbegin|crbegin}} | ||
+ | | {{cpp/container/table cell on | cpp/string/basic_string/rbegin |rbegin|crbegin }} | ||
| {{cpp/container/table cell nn | /array/rbegin |rbegin|crbegin}} | | {{cpp/container/table cell nn | /array/rbegin |rbegin|crbegin}} | ||
| {{cpp/container/table cell on | /vector/rbegin |rbegin|crbegin}} | | {{cpp/container/table cell on | /vector/rbegin |rbegin|crbegin}} | ||
Line 437: | Line 451: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell lon | rend|crend}} | | {{cpp/container/table cell lon | rend|crend}} | ||
+ | | {{cpp/container/table cell on | cpp/string/basic_string/rend |rend|crend }} | ||
| {{cpp/container/table cell nn | /array/rend |rend|crend}} | | {{cpp/container/table cell nn | /array/rend |rend|crend}} | ||
| {{cpp/container/table cell on | /vector/rend |rend|crend}} | | {{cpp/container/table cell on | /vector/rend |rend|crend}} | ||
Line 461: | Line 476: | ||
! rowspan="5" | Element <br> access | ! rowspan="5" | Element <br> access | ||
| {{cpp/container/table cell lo | at}} | | {{cpp/container/table cell lo | at}} | ||
+ | | {{cpp/container/table cell o | cpp/string/basic_string/at }} | ||
| {{cpp/container/table cell n | /array/at }} | | {{cpp/container/table cell n | /array/at }} | ||
| {{cpp/container/table cell o | /vector/at }} | | {{cpp/container/table cell o | /vector/at }} | ||
Line 486: | Line 502: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell lo | operator[]}} | | {{cpp/container/table cell lo | operator[]}} | ||
+ | | {{cpp/container/table cell o | cpp/string/basic_string/operator_at |operator[] }} | ||
| {{cpp/container/table cell n | /array/operator_at |operator[]}} | | {{cpp/container/table cell n | /array/operator_at |operator[]}} | ||
| {{cpp/container/table cell o | /vector/operator_at |operator[]}} | | {{cpp/container/table cell o | /vector/operator_at |operator[]}} | ||
Line 510: | Line 527: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell ln | data}} | | {{cpp/container/table cell ln | data}} | ||
+ | | {{cpp/container/table cell o | cpp/string/basic_string/data }} | ||
| {{cpp/container/table cell n | /array/data }} | | {{cpp/container/table cell n | /array/data }} | ||
| {{cpp/container/table cell n | /vector/data }} | | {{cpp/container/table cell n | /vector/data }} | ||
Line 534: | Line 552: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell lo | front}} | | {{cpp/container/table cell lo | front}} | ||
+ | | {{cpp/container/table cell n | cpp/string/basic_string/front }} | ||
| {{cpp/container/table cell n | /array/front }} | | {{cpp/container/table cell n | /array/front }} | ||
| {{cpp/container/table cell o | /vector/front }} | | {{cpp/container/table cell o | /vector/front }} | ||
Line 558: | Line 577: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell lo | back}} | | {{cpp/container/table cell lo | back}} | ||
+ | | {{cpp/container/table cell n | cpp/string/basic_string/back }} | ||
| {{cpp/container/table cell n | /array/back }} | | {{cpp/container/table cell n | /array/back }} | ||
| {{cpp/container/table cell o | /vector/back }} | | {{cpp/container/table cell o | /vector/back }} | ||
Line 582: | Line 602: | ||
! rowspan="7" | Capacity | ! rowspan="7" | Capacity | ||
| {{cpp/container/table cell lo | empty}} | | {{cpp/container/table cell lo | empty}} | ||
+ | | {{cpp/container/table cell o | cpp/string/basic_string/empty }} | ||
| {{cpp/container/table cell n | /array/empty }} | | {{cpp/container/table cell n | /array/empty }} | ||
| {{cpp/container/table cell o | /vector/empty }} | | {{cpp/container/table cell o | /vector/empty }} | ||
Line 607: | Line 628: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell lo | size}} | | {{cpp/container/table cell lo | size}} | ||
+ | | {{cpp/container/table cell o | cpp/string/basic_string/size }} | ||
| {{cpp/container/table cell n | /array/size }} | | {{cpp/container/table cell n | /array/size }} | ||
| {{cpp/container/table cell o | /vector/size }} | | {{cpp/container/table cell o | /vector/size }} | ||
Line 631: | Line 653: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell lo | max_size}} | | {{cpp/container/table cell lo | max_size}} | ||
+ | | {{cpp/container/table cell o | cpp/string/basic_string/max_size }} | ||
| {{cpp/container/table cell n | /array/max_size }} | | {{cpp/container/table cell n | /array/max_size }} | ||
| {{cpp/container/table cell o | /vector/max_size }} | | {{cpp/container/table cell o | /vector/max_size }} | ||
Line 655: | Line 678: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell lo | resize}} | | {{cpp/container/table cell lo | resize}} | ||
+ | | {{cpp/container/table cell o | cpp/string/basic_string/resize }} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{cpp/container/table cell o | /vector/resize }} | | {{cpp/container/table cell o | /vector/resize }} | ||
Line 679: | Line 703: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell lo | capacity}} | | {{cpp/container/table cell lo | capacity}} | ||
+ | | {{cpp/container/table cell o | cpp/string/basic_string/capacity }} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{cpp/container/table cell o | /vector/capacity }} | | {{cpp/container/table cell o | /vector/capacity }} | ||
Line 703: | Line 728: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell lo | reserve}} | | {{cpp/container/table cell lo | reserve}} | ||
+ | | {{cpp/container/table cell o | cpp/string/basic_string/reserve }} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{cpp/container/table cell o | /vector/reserve}} | | {{cpp/container/table cell o | /vector/reserve}} | ||
Line 727: | Line 753: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell ln | shrink_to_fit}} | | {{cpp/container/table cell ln | shrink_to_fit}} | ||
+ | | {{cpp/container/table cell n | cpp/string/basic_string/shrink_to_fit }} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{cpp/container/table cell n | /vector/shrink_to_fit}} | | {{cpp/container/table cell n | /vector/shrink_to_fit}} | ||
Line 751: | Line 778: | ||
! rowspan="19" | Modifiers | ! rowspan="19" | Modifiers | ||
| {{cpp/container/table cell lo | clear}} | | {{cpp/container/table cell lo | clear}} | ||
+ | | {{cpp/container/table cell o | cpp/string/basic_string/clear }} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{cpp/container/table cell o | /vector/clear }} | | {{cpp/container/table cell o | /vector/clear }} | ||
Line 776: | Line 804: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell lo | insert}} | | {{cpp/container/table cell lo | insert}} | ||
+ | | {{cpp/container/table cell o | cpp/string/basic_string/insert }} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{cpp/container/table cell o | /vector/insert }} | | {{cpp/container/table cell o | /vector/insert }} | ||
Line 800: | Line 829: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell l23 | insert_range}} | | {{cpp/container/table cell l23 | insert_range}} | ||
+ | | {{cpp/container/table cell 23 | cpp/string/basic_string/insert_range }} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{cpp/container/table cell 23 | /vector/insert_range }} | | {{cpp/container/table cell 23 | /vector/insert_range }} | ||
Line 824: | Line 854: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell l17 | insert_or_assign}} | | {{cpp/container/table cell l17 | insert_or_assign}} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 848: | Line 879: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell ln | emplace}} | | {{cpp/container/table cell ln | emplace}} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{cpp/container/table cell n | /vector/emplace }} | | {{cpp/container/table cell n | /vector/emplace }} | ||
Line 872: | Line 904: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell ln | emplace_hint}} | | {{cpp/container/table cell ln | emplace_hint}} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 896: | Line 929: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell l17 | try_emplace}} | | {{cpp/container/table cell l17 | try_emplace}} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 920: | Line 954: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell lo | erase}} | | {{cpp/container/table cell lo | erase}} | ||
+ | | {{cpp/container/table cell o | cpp/string/basic_string/erase }} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{cpp/container/table cell o | /vector/erase }} | | {{cpp/container/table cell o | /vector/erase }} | ||
Line 944: | Line 979: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell lo | push_front}} | | {{cpp/container/table cell lo | push_front}} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 968: | Line 1,004: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell l23 | prepend_range}} | | {{cpp/container/table cell l23 | prepend_range}} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 992: | Line 1,029: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell ln | emplace_front}} | | {{cpp/container/table cell ln | emplace_front}} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 1,016: | Line 1,054: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell lo | pop_front}} | | {{cpp/container/table cell lo | pop_front}} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 1,040: | Line 1,079: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell lo | push_back}} | | {{cpp/container/table cell lo | push_back}} | ||
+ | | {{cpp/container/table cell o | cpp/string/basic_string/push_back }} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{cpp/container/table cell o | /vector/push_back }} | | {{cpp/container/table cell o | /vector/push_back }} | ||
Line 1,064: | Line 1,104: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell l23 | append_range}} | | {{cpp/container/table cell l23 | append_range}} | ||
+ | | {{cpp/container/table cell 23 | cpp/string/basic_string/append_range }} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{cpp/container/table cell 23 | /vector/append_range }} | | {{cpp/container/table cell 23 | /vector/append_range }} | ||
Line 1,088: | Line 1,129: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell ln | emplace_back}} | | {{cpp/container/table cell ln | emplace_back}} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{cpp/container/table cell n | /vector/emplace_back }} | | {{cpp/container/table cell n | /vector/emplace_back }} | ||
Line 1,112: | Line 1,154: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell lo | pop_back}} | | {{cpp/container/table cell lo | pop_back}} | ||
+ | | {{cpp/container/table cell n | cpp/string/basic_string/pop_back }} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{cpp/container/table cell o | /vector/pop_back }} | | {{cpp/container/table cell o | /vector/pop_back }} | ||
Line 1,136: | Line 1,179: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell lo | swap}} | | {{cpp/container/table cell lo | swap}} | ||
+ | | {{cpp/container/table cell o | cpp/string/basic_string/swap }} | ||
| {{cpp/container/table cell n | /array/swap }} | | {{cpp/container/table cell n | /array/swap }} | ||
| {{cpp/container/table cell o | /vector/swap }} | | {{cpp/container/table cell o | /vector/swap }} | ||
Line 1,160: | Line 1,204: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell lo | merge }} | | {{cpp/container/table cell lo | merge }} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 1,184: | Line 1,229: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell l17 | extract <ref>e.g., {{c|node_type extract(const_iterator)}} or {{c|node_type extract(Key&)}}</ref>}} | | {{cpp/container/table cell l17 | extract <ref>e.g., {{c|node_type extract(const_iterator)}} or {{c|node_type extract(Key&)}}</ref>}} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 1,208: | Line 1,254: | ||
! rowspan="6" | List operations | ! rowspan="6" | List operations | ||
| {{cpp/container/table cell lo | splice }} | | {{cpp/container/table cell lo | splice }} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 1,233: | Line 1,280: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell lo | remove }} | | {{cpp/container/table cell lo | remove }} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 1,257: | Line 1,305: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell lo | remove_if }} | | {{cpp/container/table cell lo | remove_if }} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 1,281: | Line 1,330: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell lo | reverse }} | | {{cpp/container/table cell lo | reverse }} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 1,305: | Line 1,355: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell lo | unique }} | | {{cpp/container/table cell lo | unique }} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 1,329: | Line 1,380: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell lo | sort }} | | {{cpp/container/table cell lo | sort }} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 1,353: | Line 1,405: | ||
! rowspan="9" | Bucket and Hash | ! rowspan="9" | Bucket and Hash | ||
| {{cpp/container/table cell lnn | begin(size_type) | cbegin(size_type) }} | | {{cpp/container/table cell lnn | begin(size_type) | cbegin(size_type) }} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 1,378: | Line 1,431: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell lnn | end(size_type) | cend(size_type) }} | | {{cpp/container/table cell lnn | end(size_type) | cend(size_type) }} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 1,402: | Line 1,456: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell ln | bucket_count}} | | {{cpp/container/table cell ln | bucket_count}} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 1,426: | Line 1,481: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell ln | max_bucket_count}} | | {{cpp/container/table cell ln | max_bucket_count}} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 1,450: | Line 1,506: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell ln | bucket_size}} | | {{cpp/container/table cell ln | bucket_size}} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 1,474: | Line 1,531: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell ln | bucket}} | | {{cpp/container/table cell ln | bucket}} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 1,498: | Line 1,556: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell ln | load_factor}} | | {{cpp/container/table cell ln | load_factor}} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 1,522: | Line 1,581: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell ln | max_load_factor}} | | {{cpp/container/table cell ln | max_load_factor}} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 1,546: | Line 1,606: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell ln | rehash}} | | {{cpp/container/table cell ln | rehash}} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 1,571: | Line 1,632: | ||
! rowspan="6" | Lookup | ! rowspan="6" | Lookup | ||
| {{cpp/container/table cell lo | count}} | | {{cpp/container/table cell lo | count}} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 1,596: | Line 1,658: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell lo | find}} | | {{cpp/container/table cell lo | find}} | ||
+ | | {{cpp/container/table cell o | cpp/string/basic_string/find }} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 1,620: | Line 1,683: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell l20 | contains}} | | {{cpp/container/table cell l20 | contains}} | ||
+ | | {{cpp/container/table cell 23 | cpp/string/basic_string/contains }} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 1,644: | Line 1,708: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell lo | lower_bound}} | | {{cpp/container/table cell lo | lower_bound}} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 1,668: | Line 1,733: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell lo | upper_bound}} | | {{cpp/container/table cell lo | upper_bound}} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 1,692: | Line 1,758: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell lo | equal_range}} | | {{cpp/container/table cell lo | equal_range}} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 1,716: | Line 1,783: | ||
! rowspan="4" | Observers | ! rowspan="4" | Observers | ||
| {{cpp/container/table cell lo | key_comp}} | | {{cpp/container/table cell lo | key_comp}} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 1,741: | Line 1,809: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell lo | value_comp}} | | {{cpp/container/table cell lo | value_comp}} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 1,765: | Line 1,834: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell ln | hash_function}} | | {{cpp/container/table cell ln | hash_function}} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 1,789: | Line 1,859: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell ln | key_eq}} | | {{cpp/container/table cell ln | key_eq}} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 1,813: | Line 1,884: | ||
! Allocator | ! Allocator | ||
| {{cpp/container/table cell lo | get_allocator}} | | {{cpp/container/table cell lo | get_allocator}} | ||
+ | | {{cpp/container/table cell o | cpp/string/basic_string/get_allocator }} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{cpp/container/table cell o | /vector/get_allocator }} | | {{cpp/container/table cell o | /vector/get_allocator }} | ||
Line 1,839: | Line 1,911: | ||
| {{cpp/container/table cell l23 | extract <ref>e.g., {{c|container_type extract() &&}} | | {{cpp/container/table cell l23 | extract <ref>e.g., {{c|container_type extract() &&}} | ||
</ref>}} | </ref>}} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 1,864: | Line 1,937: | ||
<!-- --> | <!-- --> | ||
| {{cpp/container/table cell l23 | replace}} | | {{cpp/container/table cell l23 | replace}} | ||
+ | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{n/a|}} | | {{n/a|}} | ||
Line 1,887: | Line 1,961: | ||
|- | |- | ||
! colspan="2" | Container | ! colspan="2" | Container | ||
+ | ! {{cpp/container/table cell ho | cpp/string/basic_string }} | ||
+ | ! {{cpp/container/table cell hn | /array }} | ||
! {{cpp/container/table cell hn | /array }} | ! {{cpp/container/table cell hn | /array }} | ||
! {{cpp/container/table cell ho | /vector }} | ! {{cpp/container/table cell ho | /vector }} | ||
Line 1,910: | Line 1,986: | ||
|- | |- | ||
! colspan="2" | Header | ! colspan="2" | Header | ||
+ | ! {{tt|{{header|string}}}} | ||
! {{tt|{{header|array}}}} | ! {{tt|{{header|array}}}} | ||
! {{tt|{{header|vector}}}} | ! {{tt|{{header|vector}}}} | ||
Line 1,943: | Line 2,020: | ||
|- | |- | ||
| colspan="2" | | | colspan="2" | | ||
+ | ! colspan="1" | Pseudo container | ||
! colspan="5" | Sequence containers | ! colspan="5" | Sequence containers | ||
! colspan="4" | Associative containers | ! colspan="4" | Associative containers | ||
Line 1,950: | Line 2,028: | ||
|- | |- | ||
! colspan="2" | Header | ! colspan="2" | Header | ||
+ | ! {{tt|{{header|string}}}} | ||
! {{tt|{{header|array}}}} | ! {{tt|{{header|array}}}} | ||
! {{tt|{{header|vector}}}} | ! {{tt|{{header|vector}}}} | ||
Line 1,966: | Line 2,045: | ||
|- | |- | ||
! colspan="2" | Container | ! colspan="2" | Container | ||
+ | ! {{cpp/container/table cell ho | cpp/string/basic_string }} | ||
! {{cpp/container/table cell hn | /array }} | ! {{cpp/container/table cell hn | /array }} | ||
! {{cpp/container/table cell ho | /vector }} | ! {{cpp/container/table cell ho | /vector }} | ||
Line 1,990: | Line 2,070: | ||
! rowspan="10" | Non-member function | ! rowspan="10" | Non-member function | ||
| {{cpp/container/table cell lo | operator{{==}} }} | | {{cpp/container/table cell lo | operator{{==}} }} | ||
+ | | {{cpp/container/table cell o | cpp/string/basic_string/operator_cmp | operator{{==}} }} | ||
| {{cpp/container/table cell n | /array/operator_cmp | operator{{==}} }} | | {{cpp/container/table cell n | /array/operator_cmp | operator{{==}} }} | ||
| {{cpp/container/table cell o | /vector/operator_cmp | operator{{==}} }} | | {{cpp/container/table cell o | /vector/operator_cmp | operator{{==}} }} | ||
Line 2,015: | Line 2,096: | ||
<!-- ---> | <!-- ---> | ||
| {{cpp/container/table cell lo | operator!{{=}} {{mark until c++20|removed=yes}} }} | | {{cpp/container/table cell lo | operator!{{=}} {{mark until c++20|removed=yes}} }} | ||
+ | | {{cpp/container/table cell o | cpp/string/basic_string/operator_cmp | operator!{{=}} }} | ||
| {{cpp/container/table cell n | /array/operator_cmp | operator!{{=}} }} | | {{cpp/container/table cell n | /array/operator_cmp | operator!{{=}} }} | ||
| {{cpp/container/table cell o | /vector/operator_cmp | operator!{{=}} }} | | {{cpp/container/table cell o | /vector/operator_cmp | operator!{{=}} }} | ||
Line 2,039: | Line 2,121: | ||
<!-- ---> | <!-- ---> | ||
| {{cpp/container/table cell lo | operator< {{mark until c++20|removed=yes}} }} | | {{cpp/container/table cell lo | operator< {{mark until c++20|removed=yes}} }} | ||
+ | | {{cpp/container/table cell o | cpp/string/basic_string/operator_cmp | operator< }} | ||
| {{cpp/container/table cell n | /array/operator_cmp | operator< }} | | {{cpp/container/table cell n | /array/operator_cmp | operator< }} | ||
| {{cpp/container/table cell o | /vector/operator_cmp | operator< }} | | {{cpp/container/table cell o | /vector/operator_cmp | operator< }} | ||
Line 2,063: | Line 2,146: | ||
<!-- ---> | <!-- ---> | ||
| {{cpp/container/table cell lo | operator<{{=}} {{mark until c++20|removed=yes}} }} | | {{cpp/container/table cell lo | operator<{{=}} {{mark until c++20|removed=yes}} }} | ||
+ | | {{cpp/container/table cell o | cpp/string/basic_string/operator_cmp | operator<{{=}} }} | ||
| {{cpp/container/table cell n | /array/operator_cmp | operator<{{=}} }} | | {{cpp/container/table cell n | /array/operator_cmp | operator<{{=}} }} | ||
| {{cpp/container/table cell o | /vector/operator_cmp | operator<{{=}} }} | | {{cpp/container/table cell o | /vector/operator_cmp | operator<{{=}} }} | ||
Line 2,087: | Line 2,171: | ||
<!-- ---> | <!-- ---> | ||
| {{cpp/container/table cell lo | operator> {{mark until c++20|removed=yes}} }} | | {{cpp/container/table cell lo | operator> {{mark until c++20|removed=yes}} }} | ||
+ | | {{cpp/container/table cell o | cpp/string/basic_string/operator_cmp | operator> }} | ||
| {{cpp/container/table cell n | /array/operator_cmp | operator> }} | | {{cpp/container/table cell n | /array/operator_cmp | operator> }} | ||
| {{cpp/container/table cell o | /vector/operator_cmp | operator> }} | | {{cpp/container/table cell o | /vector/operator_cmp | operator> }} | ||
Line 2,111: | Line 2,196: | ||
<!-- ---> | <!-- ---> | ||
| {{cpp/container/table cell lo | operator>{{=}} {{mark until c++20|removed=yes}} }} | | {{cpp/container/table cell lo | operator>{{=}} {{mark until c++20|removed=yes}} }} | ||
+ | | {{cpp/container/table cell o | cpp/string/basic_string/operator_cmp | operator>{{=}} }} | ||
| {{cpp/container/table cell n | /array/operator_cmp | operator>{{=}} }} | | {{cpp/container/table cell n | /array/operator_cmp | operator>{{=}} }} | ||
| {{cpp/container/table cell o | /vector/operator_cmp | operator>{{=}} }} | | {{cpp/container/table cell o | /vector/operator_cmp | operator>{{=}} }} | ||
Line 2,135: | Line 2,221: | ||
<!-- ---> | <!-- ---> | ||
| {{cpp/container/table cell l20 | operator<{{=}}> }} | | {{cpp/container/table cell l20 | operator<{{=}}> }} | ||
+ | | {{cpp/container/table cell 20 | cpp/string/basic_string/operator_cmp | operator<{{=}}> }} | ||
| {{cpp/container/table cell 20 | /array/operator_cmp | operator<{{=}}> }} | | {{cpp/container/table cell 20 | /array/operator_cmp | operator<{{=}}> }} | ||
| {{cpp/container/table cell 20 | /vector/operator_cmp | operator<{{=}}> }} | | {{cpp/container/table cell 20 | /vector/operator_cmp | operator<{{=}}> }} | ||
Line 2,159: | Line 2,246: | ||
<!-- ---> | <!-- ---> | ||
| {{cpp/container/table cell lo | swap}} | | {{cpp/container/table cell lo | swap}} | ||
+ | | {{cpp/container/table cell o | cpp/string/basic_string/swap }} | ||
| {{cpp/container/table cell n | /array/swap }} | | {{cpp/container/table cell n | /array/swap }} | ||
| {{cpp/container/table cell o | /vector/swap }} | | {{cpp/container/table cell o | /vector/swap }} | ||
Line 2,183: | Line 2,271: | ||
<!-- ---> | <!-- ---> | ||
| {{cpp/container/table cell l20 | erase}} | | {{cpp/container/table cell l20 | erase}} | ||
+ | | {{cpp/container/table cell 20 | cpp/string/basic_string/erase2 | erase }} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{cpp/container/table cell 20 | /vector/erase2 | erase }} | | {{cpp/container/table cell 20 | /vector/erase2 | erase }} | ||
Line 2,207: | Line 2,296: | ||
<!-- ---> | <!-- ---> | ||
| {{cpp/container/table cell l20 | erase_if}} | | {{cpp/container/table cell l20 | erase_if}} | ||
+ | | {{cpp/container/table cell 20 | cpp/string/basic_string/erase2 | erase_if }} | ||
| {{n/a|}} | | {{n/a|}} | ||
| {{cpp/container/table cell 20 | /vector/erase2 | erase_if }} | | {{cpp/container/table cell 20 | /vector/erase2 | erase_if }} | ||
Line 2,230: | Line 2,320: | ||
|- | |- | ||
! colspan="2" | Container | ! colspan="2" | Container | ||
+ | ! {{cpp/container/table cell ho | cpp/string/basic_string }} | ||
+ | ! {{cpp/container/table cell hn | /array }} | ||
! {{cpp/container/table cell hn | /array }} | ! {{cpp/container/table cell hn | /array }} | ||
! {{cpp/container/table cell ho | /vector }} | ! {{cpp/container/table cell ho | /vector }} | ||
Line 2,253: | Line 2,345: | ||
|- | |- | ||
! colspan="2" | Header | ! colspan="2" | Header | ||
+ | ! {{tt|{{header|string}}}} | ||
! {{tt|{{header|array}}}} | ! {{tt|{{header|array}}}} | ||
! {{tt|{{header|vector}}}} | ! {{tt|{{header|vector}}}} |
Revision as of 23:39, 22 January 2023
The Containers library is a generic collection of class templates and algorithms that allow programmers to easily implement common data structures like queues, lists and stacks. There are two(until C++11)three(since C++11) classes of containers:
- sequence containers,
- associative containers, and
|
(since C++11) |
each of which is designed to support a different set of operations.
The container manages the storage space that is allocated for its elements and provides member functions to access them, either directly or through iterators (objects with properties similar to pointers).
Most containers have at least several member functions in common, and share functionalities. Which container is the best for the particular application depends not only on the offered functionality, but also on its efficiency for different workloads.
Contents |
Sequence containers
Sequence containers implement data structures which can be accessed sequentially.
(C++11) |
fixed-sized inplace contiguous array (class template) |
dynamic contiguous array (class template) | |
double-ended queue (class template) | |
(C++11) |
singly-linked list (class template) |
doubly-linked list (class template) |
Associative containers
Associative containers implement sorted data structures that can be quickly searched (O(log n) complexity).
collection of unique keys, sorted by keys (class template) | |
collection of key-value pairs, sorted by keys, keys are unique (class template) | |
collection of keys, sorted by keys (class template) | |
collection of key-value pairs, sorted by keys (class template) |
Unordered associative containers (since C++11)
Unordered associative containers implement unsorted (hashed) data structures that can be quickly searched (O(1) amortized, O(n) worst-case complexity).
(C++11) |
collection of unique keys, hashed by keys (class template) |
(C++11) |
collection of key-value pairs, hashed by keys, keys are unique (class template) |
(C++11) |
collection of keys, hashed by keys (class template) |
(C++11) |
collection of key-value pairs, hashed by keys (class template) |
Container adaptors
Container adaptors provide a different interface for sequential containers.
adapts a container to provide stack (LIFO data structure) (class template) | |
adapts a container to provide queue (FIFO data structure) (class template) | |
adapts a container to provide priority queue (class template) | |
(C++23) |
adapts a container to provide a collection of unique keys, sorted by keys (class template) |
(C++23) |
adapts two containers to provide a collection of key-value pairs, sorted by unique keys (class template) |
(C++23) |
adapts a container to provide a collection of keys, sorted by keys (class template) |
(C++23) |
adapts two containers to provide a collection of key-value pairs, sorted by keys (class template) |
Iterator invalidation
Read-only methods never invalidate iterators or references. Methods which modify the contents of a container may invalidate iterators and/or references, as summarized in this table.
Category | Container | After insertion, are... | After erasure, are... | Conditionally | ||
---|---|---|---|---|---|---|
iterators valid? | references valid? | iterators valid? | references valid? | |||
Sequence containers | array | N/A | N/A | |||
vector | No | N/A | Insertion changed capacity | |||
Yes | Yes | Before modified element(s) (for insertion only if capacity didn't change) | ||||
No | No | At or after modified element(s) | ||||
deque | No | Yes | Yes, except erased element(s) | Modified first or last element | ||
No | No | Modified middle only | ||||
list | Yes | Yes, except erased element(s) | ||||
forward_list | Yes | Yes, except erased element(s) | ||||
Associative containers | set multiset map multimap |
Yes | Yes, except erased element(s) | |||
Unordered associative containers | unordered_set unordered_multiset unordered_map unordered_multimap |
No | Yes | N/A | Insertion caused rehash | |
Yes | Yes, except erased element(s) | No rehash |
This section is incomplete Reason: iterators from C++23 adaptors |
Here, insertion refers to any method which adds one or more elements to the container and erasure refers to any method which removes one or more elements from the container.
- Examples of insertion methods are std::set::insert, std::map::emplace, std::vector::push_back, and std::deque::push_front.
|
(since C++11) |
- Examples of erasure methods are std::set::erase, std::vector::pop_back, std::deque::pop_front, and std::map::clear.
-
clear
invalidates all iterators and references. Because it erases all elements, this technically complies with the rules above.
-
Unless otherwise specified (either explicitly or by defining a function in terms of other functions), passing a container as an argument to a library function never invalidate iterators to, or change the values of, objects within that container.
The past-the-end iterator deserves particular mention. In general this iterator is invalidated as though it were a normal iterator to a non-erased element. So std::set::end is never invalidated, std::unordered_set::end is invalidated only on rehash(since C++11), std::vector::end is always invalidated (since it is always after the modified elements), and so on.
There is one exception: an erasure which deletes the last element of a std::deque does invalidate the past-the-end iterator, even though it is not an erased element of the container (or an element at all). Combined with the general rules for std::deque iterators, the net result is that the only modifying operation which does not invalidate std::deque::end is an erasure which deletes the first element, but not the last.
Thread safety
|
(since C++11) |
Function table
Note: std::basic_string is not treated as a container by the standard but behaves much like one due to its similarity. It is listed as 'Pseudo container' here for convenience.
- functions present in C++03 | |
- functions present since C++11 | |
- functions present since C++17 | |
- functions present since C++20 | |
- functions present since C++23 |
Member function table
- Note: functions in two different extract lines have different meanings and syntax:
- ↑ e.g., node_type extract(const_iterator) or node_type extract(Key&)
- ↑ e.g., container_type extract() &&
Non-member function table
Pseudo container | Sequence containers | Associative containers | Unordered associative containers | Container adaptors | |||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Header | <string>
|
<array>
|
<vector>
|
<deque>
|
<forward_list>
|
<list>
|
<set>
|
<map>
|
<unordered_set>
|
<unordered_map>
|
<stack>
|
<queue>
|
<flat_set>
|
<flat_map>
|
Header | ||||||||||||||||||||||||||||||||
Container |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Container | |||||||||||||||||||||||||
Non-member function |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Non-member function | ||||||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||||||||||||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||||||||||||||||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||||||||||||||||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||||||||||||||||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||||||||||||||||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||||||||||||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |||||||||||||||||||||||||
|
|
|
|
|
|
| |||||||||||||||||||||||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |||||||||||||||||||||||||||||
Container |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Container | ||||||||||||||||||||||||
Header | <string>
|
<array>
|
<vector>
|
<deque>
|
<forward_list>
|
<list>
|
<set>
|
<map>
|
<unordered_set>
|
<unordered_map>
|
<stack>
|
<queue>
|
<flat_set>
|
<flat_map>
|
Header | ||||||||||||||||||||||||||||||||
Sequence containers | Associative containers | Unordered associative containers | Container adaptors |
The |
(since C++20) |
Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 51 | C++98 | container iterators might be invalidated by arbitrary library operation |
they are only invalidated when specified |
See also
C++ named requirements:
- Container
- SequenceContainer
- ContiguousContainer
- ReversibleContainer
- AssociativeContainer
- AllocatorAwareContainer
- UnorderedAssociativeContainer
numeric arrays, array masks and array slices (class template) | |
stores and manipulates sequences of characters (class template) | |
(C++17) |
read-only string view (class template) |
(C++20) |
a non-owning view over a contiguous sequence of objects (class template) |
(C++23) |
a multi-dimensional non-owning array view (class template) |