std::unordered_multiset
的推导指引
定义于头文件 <unordered_set> |
||
template< class InputIt, |
(1) | (自 C++17 起) |
template< class T, class Hash = std::hash<T>, |
(2) | (自 C++17 起) |
template< class InputIt, class Alloc > unordered_multiset( InputIt, InputIt, typename /* 见下文 */::size_type, Alloc ) |
(3) | (自 C++17 起) |
template< class InputIt, class Hash, class Alloc > unordered_multiset( InputIt, InputIt, typename /* 见下文 */::size_type, Hash, Alloc ) |
(4) | (自 C++17 起) |
template< class T, class Alloc > unordered_multiset( std::initializer_list<T>, typename /* 见下文 */::size_type, Alloc ) |
(5) | (自 C++17 起) |
template< class T, class Hash, class Alloc > unordered_multiset( std::initializer_list<T>, typename /* 见下文 */::size_type, |
(6) | (自 C++17 起) |
template< ranges::input_range R, class Hash = std::hash<ranges::range_value_t<R>>, |
(7) | (自 C++23 起) |
template< ranges::input_range R, class Alloc > unordered_multiset( std::from_range_t, R&&, |
(8) | (自 C++23 起) |
template< ranges::input_range R, class Alloc > unordered_multiset( std::from_range_t, R&&, Alloc ) |
(9) | (自 C++23 起) |
template< ranges::input_range R, class Hash, class Alloc > unordered_multiset( std::from_range_t, R&&, |
(10) | (自 C++23 起) |
unordered_multiset
提供,以允许从迭代器范围(重载 (1,3,4))和 std::initializer_list (重载 (2,5,6))进行推导。此重载仅在 InputIt
满足 LegacyInputIterator,Alloc
满足 Allocator,Hash
和 Pred
都不满足 Allocator,且 Hash
不是 integral 类型时参与重载解析。注意:库确定类型不满足 LegacyInputIterator 的程度是未指定的,但至少 integral 类型不符合输入迭代器的条件。 同样,库确定类型不满足 Allocator 的程度是未指定的,但至少成员类型 Alloc::value_type
必须存在,并且表达式 std::declval<Alloc&>().allocate(std::size_t{}) 在被视为未求值操作数时必须是良构的。
这些指引中的 size_type 参数类型指的是由推导指引推导的类型的 size_type 成员类型。
[编辑] 注释
特性测试 宏 | 值 | Std | 特性 |
---|---|---|---|
__cpp_lib_containers_ranges |
202202L |
(C++23) | 范围感知 构造和插入;重载 (7-10) |
[编辑] 示例
#include <unordered_set> int main() { // guide #2 deduces std::unordered_multiset<int> std::unordered_multiset s = {1, 2, 3, 4}; // guide #1 deduces std::unordered_multiset<int> std::unordered_multiset s2(s.begin(), s.end()); }