Namespaces
Variants

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

ko.cppreference.net 에서

 
 
 
 
stack() : stack(Container()) {}
(1) (C++11부터)
explicit stack( const Container& cont = Container() );
(2) (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 인 경우, 즉 기본 컨테이너가 할당자 인식 컨테이너인 경우 (와 함께 사용할 수 있는 모든 표준 라이브러리 컨테이너에 해당 stack).
7) 기본 컨테이너를 생성합니다 alloc 을(를) 할당자로 사용하여, 마치 c(alloc) 에 의한 것처럼.
8) 기본 컨테이너를 생성합니다 의 내용으로 cont 및 사용 alloc 을(를) 할당자로 사용하여, 마치 c(cont, alloc) 에 의한 것처럼.
9) 기본 컨테이너를 생성합니다 의 내용으로 cont 이동 의미론을 사용하여 활용 alloc 을(를) 할당자로 사용하여, 마치 c(std::move(cont), alloc) 에 의한 것처럼.
10) 어댑터를 생성합니다 의 내용으로 other.c 및 사용 alloc 을(를) 할당자로 사용하여, 마치 c(other.c, alloc) 에 의한 것처럼.
11) 어댑터를 생성합니다 의 내용으로 other 이동 의미론을 사용하여 활용 alloc 을(를) 할당자로 사용하여, 마치 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)