名稱空間
變體
操作

std::unordered_multiset 的推導指南

來自 cppreference.com
 
 
 
 
定義於標頭檔案 <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> >
unordered_multiset( InputIt, InputIt,
                    typename /* 見下文 */::size_type = /* 見下文 */,
                    Hash = Hash(), Pred = Pred(), Alloc = Alloc() )
    -> unordered_multiset<typename std::iterator_traits<InputIt>::value_type,

                          Hash, Pred, Alloc>;
(1) (C++17 起)
template< class T,

          class Hash = std::hash<T>,
          class Pred = std::equal_to<T>,
          class Alloc = std::allocator<T> >
unordered_multiset( std::initializer_list<T>,
                    typename /* 見下文 */::size_type = /* 見下文 */,
                    Hash = Hash(), Pred = Pred(), Alloc = Alloc() )

    -> unordered_multiset<T, Hash, Pred, Alloc>;
(2) (C++17 起)
template< class InputIt, class Alloc >

unordered_multiset( InputIt, InputIt, typename /* 見下文 */::size_type, Alloc )
    -> unordered_multiset<typename std::iterator_traits<InputIt>::value_type,
                          std::hash<typename std::iterator_traits<InputIt>::value_type>,
                          std::equal_to<typename std::iterator_traits<InputIt>::value_type>,

                          Alloc>;
(3) (C++17 起)
template< class InputIt, class Hash, class Alloc >

unordered_multiset( InputIt, InputIt, typename /* 見下文 */::size_type, Hash, Alloc )
    -> unordered_multiset<typename std::iterator_traits<InputIt>::value_type, Hash,
                          std::equal_to<typename std::iterator_traits<InputIt>::value_type>,

                          Alloc>;
(4) (C++17 起)
template< class T, class Alloc >

unordered_multiset( std::initializer_list<T>, typename /* 見下文 */::size_type, Alloc )

    -> unordered_multiset<T, std::hash<T>, std::equal_to<T>, Alloc>;
(5) (C++17 起)
template< class T, class Hash, class Alloc >

unordered_multiset( std::initializer_list<T>, typename /* 見下文 */::size_type,
                    Hash, Alloc )

    -> unordered_multiset<T, Hash, std::equal_to<T>, Alloc>;
(6) (C++17 起)
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_multiset( std::from_range_t, R&&,
                    typename /* 見下文 */::size_type = /* 見下文 */,
                    Hash = Hash(), Pred = Pred(), Alloc = Alloc() )

    -> unordered_multiset<ranges::range_value_t<R>, Hash, Pred, Alloc>;
(7) (C++23 起)
template< ranges::input_range R, class Alloc >

unordered_multiset( std::from_range_t, R&&,
                    typename /* 見下文 */::size_type, Alloc )
    -> unordered_multiset<ranges::range_value_t<R>, hash<ranges::range_value_t<R>>,

                          std::equal_to<ranges::range_value_t<R>>, Alloc>;
(8) (C++23 起)
template< ranges::input_range R, class Alloc >

unordered_multiset( std::from_range_t, R&&, Alloc )
    -> unordered_multiset<ranges::range_value_t<R>, hash<ranges::range_value_t<R>>,

                          std::equal_to<ranges::range_value_t<R>>, Alloc>;
(9) (C++23 起)
template< ranges::input_range R, class Hash, class Alloc >

unordered_multiset( std::from_range_t, R&&,
                    typename /* 見下文 */::size_type, Hash, Alloc )
    -> unordered_multiset<ranges::range_value_t<R>, Hash,

                          std::equal_to<ranges::range_value_t<R>>, Alloc>;
(10) (C++23 起)
1-6) 這些 推導指南unordered_multiset 提供,允許從迭代器範圍(過載 (1,3,4))和 std::initializer_list(過載 (2,5,6))進行推導。此過載僅在 InputIt 滿足 LegacyInputIteratorAlloc 滿足 AllocatorHashPred 都不滿足 Allocator,且 Hash 不是整型時才參與過載決議。
7-10) 這些推導指南為 unordered_multiset 提供,允許從 std::from_range_t 標籤和 input_range 進行推導。

注意:庫確定型別不滿足 LegacyInputIterator 的程度未指定,但至少整型不符合輸入迭代器的條件。同樣,庫確定型別不滿足 Allocator 的程度也未指定,但至少成員型別 Alloc::value_type 必須存在,並且表示式 std::declval<Alloc&>().allocate(std::size_t{}) 在被視為未求值運算元時必須是良構的。

這些指南中的 size_type 引數型別指的是由推導指南推匯出的型別的 size_type 成員型別。

[編輯] 注意

特性測試 標準 特性
__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());
}