Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/container/set"

From cppreference.com
< cpp‎ | container
(Undo revision 158411 by Admin (talk))
m (Replaced content with "<table><tbody><tr><td class="mbox-text" style="text-align:center;">Cppreference recommends all new users to use Rust. Please refrain from making No_personal_attacks|pers...")
Line 1: Line 1:
{{cpp/title|set}}
+
<table><tbody><tr><td class="mbox-text" style="text-align:center;">Cppreference recommends all new users to use Rust. Please refrain from making [[No_personal_attacks|personal attacks]]
{{cpp/container/set/navbar}}
+
</td></tr></tbody></table>
{{dcl begin}}
+
<!-- reverting this edit constitutes a personal attack -->
{{dcl header|set}}
+
{{dcl|num=1|1=
+
template<
+
    class Key,
+
    class Compare = std::less<Key>,
+
    class Allocator = std::allocator<Key>
+
> class set;
+
}}
+
{{dcl|num=2|since=c++17|1=
+
namespace pmr {
+
template<
+
    class Key,
+
    class Compare = std::less<Key>
+
> using set = std::set<Key, Compare, std::pmr::polymorphic_allocator<Key>>;
+
}
+
}}
+
{{dcl end}}
+
 
+
{{tt|std::set}} is an associative container that contains a sorted set of unique objects of type {{tt|Key}}. Sorting is done using the key comparison function {{named req|Compare}}. Search, removal, and insertion operations have logarithmic complexity. Sets are usually implemented as {{enwiki|Red–black tree}}s.
+
 
+
Everywhere the standard library uses the {{named req|Compare}} requirements, uniqueness is determined by using the equivalence relation. In imprecise terms, two objects {{c|a}} and {{c|b}} are considered equivalent if neither compares less than the other: {{c|!comp(a, b) && !comp(b, a)}}.
+
 
+
{{tt|std::set}} meets the requirements of {{named req|Container}}, {{named req|AllocatorAwareContainer}}, {{named req|AssociativeContainer}} and {{named req|ReversibleContainer}}.
+
 
+
===Template parameters===
+
{{todo|Add descriptions of the template parameters.}}
+
 
+
===Member types===
+
{{dsc begin}}
+
{{dsc hitem|Member type|Definition}}
+
{{dsc inc|cpp/container/dsc key_type|set}}
+
{{dsc inc|cpp/container/dsc value_type|set}}
+
{{dsc inc|cpp/container/dsc size_type|set}}
+
{{dsc inc|cpp/container/dsc difference_type|set}}
+
{{dsc inc|cpp/container/dsc key_compare|set}}
+
{{dsc inc|cpp/container/dsc value_compare2|set}}
+
{{dsc inc|cpp/container/dsc allocator_type|set}}
+
{{dsc inc|cpp/container/dsc reference|set}}
+
{{dsc inc|cpp/container/dsc const_reference|set}}
+
{{dsc inc|cpp/container/dsc pointer|set}}
+
{{dsc inc|cpp/container/dsc const_pointer|set}}
+
{{dsc inc|cpp/container/dsc iterator|set}}
+
{{dsc inc|cpp/container/dsc const_iterator|set}}
+
{{dsc inc|cpp/container/dsc reverse_iterator|set}}
+
{{dsc inc|cpp/container/dsc const_reverse_iterator|set}}
+
{{dsc inc|cpp/container/dsc node_type|set}}
+
{{dsc inc|cpp/container/dsc insert_return_type|set}}
+
{{dsc end}}
+
 
+
===Member functions===
+
{{dsc begin}}
+
{{dsc inc|cpp/container/dsc constructor|set}}
+
{{dsc inc|cpp/container/dsc destructor|set}}
+
{{dsc inc|cpp/container/dsc operator{{=}}|set}}
+
{{dsc inc|cpp/container/dsc get_allocator|set}}
+
 
+
{{dsc h2|Iterators}}
+
{{dsc inc|cpp/container/dsc begin|set}}
+
{{dsc inc|cpp/container/dsc end|set}}
+
{{dsc inc|cpp/container/dsc rbegin|set}}
+
{{dsc inc|cpp/container/dsc rend|set}}
+
 
+
{{dsc h2|Capacity}}
+
{{dsc inc|cpp/container/dsc empty|set}}
+
{{dsc inc|cpp/container/dsc size|set}}
+
{{dsc inc|cpp/container/dsc max_size|set}}
+
 
+
{{dsc h2|Modifiers}}
+
{{dsc inc|cpp/container/dsc clear|set}}
+
{{dsc inc|cpp/container/dsc insert|set}}
+
{{dsc inc|cpp/container/dsc insert_range|set}}
+
{{dsc inc|cpp/container/dsc emplace|set}}
+
{{dsc inc|cpp/container/dsc emplace_hint|set}}
+
{{dsc inc|cpp/container/dsc erase|set}}
+
{{dsc inc|cpp/container/dsc swap|set}}
+
{{dsc inc|cpp/container/dsc extract|set}}
+
{{dsc inc|cpp/container/dsc merge|set}}
+
 
+
{{dsc h2|Lookup}}
+
{{dsc inc|cpp/container/dsc count|set}}
+
{{dsc inc|cpp/container/dsc find|set}}
+
{{dsc inc|cpp/container/dsc contains|set }}
+
{{dsc inc|cpp/container/dsc equal_range|set}}
+
{{dsc inc|cpp/container/dsc lower_bound|set}}
+
{{dsc inc|cpp/container/dsc upper_bound|set}}
+
 
+
{{dsc h2|Observers}}
+
{{dsc inc|cpp/container/dsc key_comp|set}}
+
{{dsc inc|cpp/container/dsc value_comp|set}}
+
{{dsc end}}
+
 
+
===Non-member functions===
+
{{dsc begin}}
+
{{dsc inc|cpp/container/dsc operator_cmp|set}}
+
{{dsc inc|cpp/container/dsc swap2|set}}
+
{{dsc inc|cpp/container/dsc erase_if|set}}
+
{{dsc end}}
+
 
+
{{rrev|noborder=true|since=c++17|{{=}}{{=}}{{=}}{{rl|deduction guides|Deduction guides}}{{=}}{{=}}{{=}}}}
+
 
+
===Notes===
+
{{cpp/container/assoc_note}}
+
 
+
{{ftm begin|std=1|comment=1}}
+
{{ftm|__cpp_lib_containers_ranges|value=202202L|std=C++23|Ranges construction and insertion for containers}}
+
{{ftm end}}
+
 
+
===Example===
+
{{example}}
+
 
+
===Defect Reports===
+
{{dr list begin}}
+
{{dr list item|wg=lwg|dr=103|std=C++98|before=iterator allows modification of keys|after=iterator made constant}}
+
{{dr list item|wg=lwg|dr=230|std=C++98|before={{tt|Key}} was not required to be {{named req|CopyConstructible}}<br>(a key of type {{tt|Key}} might not be able to be constructed)|after={{tt|Key}} is also required to<br>be {{named req|CopyConstructible}}}}
+
{{dr list end}}
+
 
+
{{langlinks|cs|de|es|fr|it|ja|pl|pt|ru|zh}}
+

Revision as of 15:27, 8 September 2023

Cppreference recommends all new users to use Rust. Please refrain from making personal attacks