On this page
deduction guides for std::unordered_set
Defined in header <unordered_set> |
||
---|---|---|
|
(1) | (since C++17) |
|
(2) | (since C++17) |
|
(3) | (since C++17) |
|
(4) | (since C++17) |
|
(5) | (since C++17) |
|
(6) | (since C++17) |
|
(7) | (since C++23) |
|
(8) | (since C++23) |
|
(9) | (since C++23) |
|
(10) | (since C++23) |
unordered_set
to allow deduction from an iterator range (overloads (1,3,4)) and std::initializer_list
(overloads (2,5,6)). This overload participates in overload resolution only if InputIt
satisfies LegacyInputIterator, Alloc
satisfies Allocator, neither Hash
nor Pred
satisfy Allocator, Hash
is not an integral type.
unordered_set
to allow deduction from a std::from_range_t
tag and an input_range
.
Note: the extent to which the library determines that a type does not satisfy LegacyInputIterator is unspecified, except that as a minimum integral types do not qualify as input iterators. Likewise, the extent to which it determines that a type does not satisfy Allocator is unspecified, except that as a minimum the member type Alloc::value_type
must exist and the expression std::declval<Alloc&>().allocate(std::size_t{})
must be well-formed when treated as an unevaluated operand.
The size_type
parameter type in these guides refers to the size_type
member type of the type deduced by the deduction guide.
Notes
Feature-test macro | Value | Std | Feature |
---|---|---|---|
__cpp_lib_containers_ranges |
202202L | (C++23) | Ranges-aware construction and insertion; overloads (7-10) |
Example
#include <unordered_set>
int main()
{
// guide #2 deduces std::unordered_set<int>
std::unordered_set s = {1, 2, 3, 4};
// guide #1 deduces std::unordered_set<int>
std::unordered_set s2(s.begin(), s.end());
}
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/container/unordered_set/deduction_guides