名前空間
変種
操作

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

提供: cppreference.com
< cpp‎ | container‎ | set
 
 
 
 
ヘッダ <set> で定義
template<class InputIt,

         class Comp = std::less<typename std::iterator_traits<InputIt>::value_type>,
         class Alloc = std::allocator<typename std::iterator_traits<InputIt>::value_type>>
set(InputIt, InputIt, Comp = Comp(), Alloc = Alloc())

  -> set<typename std::iterator_traits<InputIt>::value_type, Comp, Alloc>;
(1) (C++17以上)
template<class Key, class Comp = std::less<Key>, class Alloc = std::allocator<Key>>

set(std::initializer_list<Key>, Comp = Comp(), Alloc = Alloc())

  -> set<Key, Comp, Alloc>;
(2) (C++17以上)
template<class InputIt, class Alloc>

set(InputIt, InputIt, Alloc)
  -> set<typename std::iterator_traits<InputIt>::value_type,

           std::less<typename std::iterator_traits<InputIt>::value_type>, Alloc>;
(3) (C++17以上)
template<class Key, class Alloc>

set(std::initializer_list<Key>, Alloc)

  -> set<Key, std::less<Key>, Alloc>;
(4) (C++17以上)

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

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

[編集]

#include <set>
int main() {
   std::set s = {1,2,3,4}; // guide #2 deduces std::set<int>
   std::set s2(s.begin(), s.end()); // guide #1 deduces std::set<int>
}