Namespaces
Variants

std::stack<T,Container>:: stack

From cppreference.net

stack ( ) : stack ( Container ( ) ) { }
(1) (C++11부터)
(2)
explicit stack ( const Container & cont = Container ( ) ) ;
(C++11 이전)
explicit stack ( const Container & cont ) ;
(C++11 이후)
explicit stack ( Container && cont ) ;
(3) (C++11 이후)
stack ( const stack & other ) ;
(4) (암시적으로 선언됨)
stack ( stack && other ) ;
(5) (C++11 이후)
(암시적으로 선언됨)
template < class InputIt >
stack ( InputIt first, InputIt last ) ;
(6) (C++23부터)
template < class Alloc >
explicit stack ( const Alloc & alloc ) ;
(7) (C++11 이후)
template < class Alloc >
stack ( const Container & cont, const Alloc & alloc ) ;
(8) (C++11 이후)
template < class Alloc >
stack ( Container && cont, const Alloc & alloc ) ;
(9) (C++11 이후)
template < class Alloc >
stack ( const stack & other, const Alloc & alloc ) ;
(10) (C++11 이후)
template < class Alloc >
stack ( stack && other, const Alloc & alloc ) ;
(11) (C++11 이후)
template < class InputIt, class Alloc >
stack ( InputIt first, InputIt last, const Alloc & alloc ) ;
(12) (C++23부터)
template < container-compatible-range < T > R >
stack ( std:: from_range_t , R && rg ) ;
(13) (C++23 이후)
template < container-compatible-range < T > R, class Alloc >
stack ( std:: from_range_t , R && rg, const Alloc & alloc ) ;
(14) (C++23부터)

컨테이너 어댑터의 새로운 기반 컨테이너를 다양한 데이터 소스로부터 생성합니다.

1) 기본 생성자. 컨테이너를 값 초기화합니다.
2) 기본 컨테이너를 c 의 내용으로 복사 생성합니다. cont . 이는 또한 기본 생성자입니다. (C++11 이전)
3) 기본 컨테이너 c std :: move ( cont ) 로 이동 생성합니다.
4) 복사 생성자 . 어댑터는 other. c 의 내용으로 복사 생성됩니다.
5) 이동 생성자 . 어댑터는 std :: move ( other. c ) 로 생성됩니다.
6) 기본 컨테이너 c 를 범위 [ first , last ) 의 내용으로 생성합니다. 이 오버로드는 InputIt LegacyInputIterator 요구 사항을 충족할 때만 오버로드 해결에 참여합니다.
7-12) 이 생성자들은 다음 조건에서만 오버로드 해결에 참여합니다: std:: uses_allocator < Container, Alloc > :: value true 인 경우, 즉 기본 컨테이너가 allocator-aware 컨테이너인 경우입니다( stack 와 함께 사용할 수 있는 모든 표준 라이브러리 컨테이너에 대해 true입니다).
7) 기본 컨테이너를 alloc 을 할당자로 사용하여 생성합니다. 마치 c ( alloc ) 처럼 동작합니다.
8) 기본 컨테이너를 cont 의 내용과 alloc 를 할당자로 사용하여 생성합니다. 마치 c ( cont, alloc ) 와 같이 동작합니다.
9) 기본 컨테이너를 alloc 을 할당자로 사용하면서 cont 의 내용을 이동 의미론을 사용하여 구성합니다. 마치 c ( std :: move ( cont ) , alloc ) 와 같이 수행됩니다.
10) 어댑터를 other. c 의 내용과 alloc 을 할당자로 사용하여 구성합니다. 마치 c ( other. c , alloc ) 와 같이 수행됩니다.
11) alloc 를 할당자로 사용하면서 이동 의미론을 이용하여 other 의 내용으로 어댑터를 구성합니다. 마치 c ( std :: move ( other. c ) , alloc ) 와 같이 수행됩니다.
12) 범위 [ first , last ) 의 내용으로 기본 컨테이너를 alloc 을 할당자로 사용하여 생성합니다. 마치 c ( first, last, alloc ) 와 같이 수행됩니다. 이 오버로드는 InputIt LegacyInputIterator 요구 사항을 충족할 때만 오버로드 해결에 참여합니다.
13) 기본 컨테이너를 ranges:: to < Container > ( std:: forward < R > ( rg ) ) 로 구성합니다.
14) 기본 컨테이너를 ranges:: to < Container > ( std:: forward < R > ( rg ) , alloc ) 로 구성합니다.

목차

매개변수

alloc - 기본 컨테이너의 모든 메모리 할당에 사용할 할당자
other - 기본 컨테이너를 초기화하는 데 소스로 사용할 다른 컨테이너 어댑터
cont - 기본 컨테이너를 초기화하는 데 소스로 사용할 컨테이너
first, last - 초기화에 사용할 요소들의 소스 범위 를 정의하는 반복자 쌍
rg - 컨테이너 호환 범위 , 즉 요소들이 T 로 변환 가능한 input_range
타입 요구사항
-
Alloc Allocator 요구사항을 충족해야 함
-
Container Container 요구사항을 충족해야 함. 할당자 매개변수를 취하는 생성자들은 Container AllocatorAwareContainer 요구사항을 충족할 때만 오버로드 해결에 참여함
-
InputIt LegacyInputIterator 요구사항을 충족해야 함

복잡도

래핑된 컨테이너의 해당 연산과 동일합니다.

참고 사항

기능 테스트 매크로 표준 기능
__cpp_lib_adaptor_iterator_pair_constructor 202106L (C++23) std::queue std::stack 를 위한 반복자 쌍 생성자; 오버로드 ( 6 ) ( 12 )
__cpp_lib_containers_ranges 202202L (C++23) 범위 인식 생성 및 삽입; 오버로드 ( 13 ) ( 14 )

예제

#include <cassert>
#include <deque>
#include <iostream>
#include <memory>
#include <ranges>
#include <stack>
int main()
{
    std::stack<int> c1;
    c1.push(5);
    assert(c1.size() == 1);
    std::stack<int> c2(c1);
    assert(c2.size() == 1);
    std::deque<int> deq{3, 1, 4, 1, 5};
    std::stack<int> c3(deq); // 오버로드 (2)
    assert(c3.size() == 5);
# ifdef __cpp_lib_adaptor_iterator_pair_constructor
    const auto il = {2, 7, 1, 8, 2};
    std::stack<int> c4{il.begin(), il.end()}; // C++23, (6)
    assert(c4.size() == 5);
# endif
# if __cpp_lib_containers_ranges >= 202202L
    // C++23, 오버로드 (13)
    auto c5 = std::stack(std::from_range_t, std::ranges::iota(0, 42));
    assert(c5.size() == 42);
    // 파이프 구문으로 동일한 효과, 내부적으로 오버로드 (13) 사용
    auto c6 = std::ranges::iota(0, 42) | std::ranges::to<std::stack>();
    assert(c6.size() == 42);
    std::allocator<int> alloc;
    // C++23, 오버로드 (14)
    auto c7 = std::stack(std::from_range_t, std::ranges::iota(0, 42), alloc);
    assert(c7.size() == 42);
    // 파이프 구문으로 동일한 효과, 내부적으로 오버로드 (14) 사용
    auto c8 = std::ranges::iota(0, 42) | std::ranges::to<std::stack>(alloc);
    assert(c8.size() == 42);
# endif
}

결함 보고서

다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.

DR 적용 대상 게시된 동작 올바른 동작
P0935R0 C++11 default constructor was explicit made implicit

참고 항목

컨테이너 어댑터에 값을 할당합니다
(public member function)