名前空間
変種
操作

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

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

          class Alloc =std::allocator<typenamestd::iterator_traits<InputIt>::value_type>>
vector(InputIt, InputIt, Alloc = Alloc())

  -> vector<typenamestd::iterator_traits<InputIt>::value_type, Alloc>;
(C++17以上)

イテレータ範囲からの推定を可能とするため、この推定ガイドが vector に対して提供されます。 このオーバーロードは、InputItLegacyInputIterator を満たし、 AllocAllocator を満たす場合にのみ、オーバーロード解決に参加します。

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

[編集]

#include <vector>   int main(){std::vector<int> v ={1, 2, 3, 4};   // uses explicit deduction guide to deduce std::vector<int>std::vector x(v.begin(), v.end());   // deduces std::vector<std::vector<int>::iterator>// first phase of overload resolution for list-initialization selects the candidate// synthesized from the initializer-list constructor; second phase is not performed and// deduction guide has no effectstd::vector y{v.begin(), v.end()};}


close