名前空間
変種
操作

std::unordered_set に対する推定ガイド

提供: 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_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>;
(1) (C++17以上)
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>,
         typename /*see below*/::size_type = /*see below*/,
         Hash = Hash(), Pred = Pred(), Alloc = Alloc())

  -> unordered_set<T, Hash, Pred, Alloc>;
(2) (C++17以上)
template<class InputIt, class Alloc>

unordered_set(InputIt, InputIt, typename /*see below*/::size_type, Alloc)
  -> unordered_set<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_set(InputIt, InputIt, typename /*see below*/::size_type, Hash, Alloc)
  -> unordered_set<typename std::iterator_traits<InputIt>::value_type, Hash,

             std::equal_to<typename std::iterator_traits<InputIt>::value_type>, Allocator>;
(4) (C++17以上)
template<class T, class Allocator>

unordered_set(std::initializer_list<T>, typename /*see below*/::size_type, Allocator)

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

unordered_set(std::initializer_list<T>, typename /*see below*/::size_type, Hash, Alloc)

  -> unordered_set<T, Hash, std::equal_to<T>, Alloc>;
(6) (C++17以上)

イテレータ範囲 (オーバーロード (1,3,4)) および std::initializer_list (オーバーロード (2,5.6)) からの推定を可能とするため unordered_set に対してこれらの推定ガイドが提供されます。 このオーバーロードは、InputItLegacyInputIterator を満たし、 AllocAllocator を満たし、 Hash および Pred のいずれも Allocator を満たさず、 Hash は整数型でない場合場合にのみ、オーバーロード解決に参加します。

ノート: ある型が LegacyInputIterator を満たさないとライブラリが判断する範囲は、少なくとも整数型が入力イテレータとして適合しないことを除いて、未規定です。 同様に、ある型が Allocator を満たさないと判断される範囲も、少なくともメンバ型 Alloc::value_type が存在しなければならず、式 std::declval<Alloc&>().allocate(std::size_t{}) が評価されない被演算子として扱われたときに well-formed でなければならないことを除いて、未規定です。

これらのガイドの size_type 引数型は推定ガイドによって推定された型の size_type メンバ型を参照します。

[編集]

#include <unordered_set>
int main() {
   std::unordered_set s = {1,2,3,4};            // ガイド #2 により std::unordered_set<int> と推定されます。
   std::unordered_set s2(s.begin(), s.end());   // ガイド #1 により std::unordered_set<int> と推定されます。
}