名前空間
変種
操作

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

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

stack(Container)

  -> stack<typename Container::value_type, Container>;
(1) (C++17以上)
template<class Container, class Allocator>

stack(Container, Allocator)

  -> stack<typename Container::value_type, Container>;
(2) (C++17以上)

ベースとなるコンテナ型からの推定を可能とするため、これらの推定ガイドが stack に対して提供されます。 このオーバーロードは、AllocAllocator を満たし、 ContainerAllocator を満たさず、 (オーバーロード (2) の場合) std::uses_allocator_v<Container, Allocator>true である場合にのみ、オーバーロード解決に参加します。

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

[編集]

#include <vector>
#include <stack>
int main() {
   std::vector<int> v = {1,2,3,4};
   std::stack s{v};    // guide #1 deduces std::stack<int, vector<int>>
}