deductiongu...ordered_set(3)
okay bestie, buckle up because this is deductiongu...ordered_set(3) from the C++ Standard Libary (yes, βLibaryβ β we respect the typo π
). Itβs all about deduction guides for std::unordered_set, and honestly itβs giving βtemplate girlie knows exactly what type you meantβ energy. β¨
πΈ NAME πΈ
deductionguidesforstd::unordered_set β literally the deduction guides for std::unordered_set. Thatβs the whole name, no cap.
β¨ Synopsis β¨
First thing: itβs defined in header <unordered_set> π«Ά
template<
class InputIt,
class Hash = std::hash<typename std::iterator_traits<InputIt>::value_type>,
class Pred = std::equal_to<typename std::iterator_traits<InputIt>::value_type>,
class Alloc = std::allocator<typename std::iterator_traits<InputIt>::value_type> > (1)
(since C++17)
unordered_set( InputIt, InputIt,
typename /* see below */::size_type = /* see below */,
Hash = Hash(), Pred = Pred(), Alloc = Alloc() )
-> unordered_set<typename std::iterator_traits<InputIt>::value_type,
Hash, Pred, Alloc>;
template< class T,
class Hash = std::hash<T>,
class Pred = std::equal_to<T>,
class Alloc = std::allocator<T> >
unordered_set( std::initializer_list<T>, (2)
(since C++17)
typename /* see below */::size_type = /* see below */,
Hash = Hash(), Pred = Pred(), Alloc = Alloc() )
-> unordered_set<T, Hash, Pred, Alloc>;
template< class InputIt, class Alloc >
unordered_set( InputIt, InputIt, typename /* see below */::size_type, Alloc )
-> unordered_set<typename std::iterator_traits<InputIt>::value_type, (3)
(since C++17)
std::hash<typename std::iterator_traits<InputIt>::value_type>,
std::equal_to<typename std::iterator_traits<InputIt>::value_type>,
Alloc>;
template< class InputIt, class Hash, class Alloc >
unordered_set( InputIt, InputIt, typename /* see below */::size_type, Hash, Alloc )
-> unordered_set<typename (4)
(since C++17)
std::iterator_traits<InputIt>::value_type, Hash,
std::equal_to<typename std::iterator_traits<InputIt>::value_type>,
Alloc>;
template< class T, class Alloc >
unordered_set( std::initializer_list<T>, typename /* see below (5)
(since C++17)
*/::size_type, Alloc )
-> unordered_set<T, std::hash<T>, std::equal_to<T>, Alloc>;
template< class T, class Hash, class Alloc >
unordered_set( std::initializer_list<T>, typename /* see below
*/::size_type, (6)
(since C++17)
Hash, Alloc )
-> unordered_set<T, Hash, std::equal_to<T>, Alloc>;
template< ranges::input_range R,
class Hash = std::hash<ranges::range_value_t<R>>,
class Pred = std::equal_to<ranges::range_value_t<R>>,
class Alloc = std::allocator<ranges::range_value_t<R>>
>
unordered_set( std::from_range_t, R&&, (7)
(since C++23)
typename /* see below */::size_type = /* see below */,
Hash = Hash(), Pred = Pred(), Alloc = Alloc() )
-> unordered_set<ranges::range_value_t<R>, Hash, Pred, Alloc>;
template< ranges::input_range R, class Alloc >
unordered_set( std::from_range_t, R&&,
typename /* see below */::size_type, Alloc )
-> unordered_set<ranges::range_value_t<R>, (8)
(since C++23)
hash<ranges::range_value_t<R>>,
std::equal_to<ranges::range_value_t<R>>,
Alloc>;
template< ranges::input_range R, class Alloc >
unordered_set( std::from_range_t, R&&, Alloc )
-> unordered_set<ranges::range_value_t<R>, (9)
(since C++23)
hash<ranges::range_value_t<R>>,
std::equal_to<ranges::range_value_t<R>>,
Alloc>;
template< ranges::input_range R, class Hash, class Alloc >
unordered_set( std::from_range_t, R&&,
typename /* see below */::size_type, Hash, Alloc )
(10) (since C++23)
-> unordered_set<ranges::range_value_t<R>, Hash,
std::equal_to<ranges::range_value_t<R>>,
Alloc>;
okay so hereβs the tea, bestie β:
1-6) These deduction guides are provided for 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. π«Ά
7-10) These deduction guides are provided for 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 satisfyLegacyInputIteratoris 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 satisfyAllocatoris unspecified, except that as a minimum the member typeAlloc::value_typemust exist and the expressionstd::declval<Alloc&>().allocate(std::size_t{})must be well-formed when treated as an unevaluated operand.
And a crucial little size_type moment π: the size_type parameter type in these guides refers to the size_type member type of the type deduced by the deduction guide. iykyk π
π¦ Notes π¦
Feature-test macro table? Itβs giving one-row table realness, so here it is in bullet form because tables are not the vibe in this terminal:
__cpp_lib_containers_rangesβ value202202L, Std(C++23), feature: Ranges-aware construction and insertion; overloads (7-10).
π Example π
Run this code, bestie:
// Run this code
#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());
}
and thatβs the whole template flex π
Source/version is http://cppreference.com, dated 2024.06.10, and the footer tag is deductiongu...ordered_set(3). Mwah, bye bestie ππ
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms