Namespaces
Variants

std::inplace_vector<T,N>:: push_back

From cppreference.net
constexpr reference push_back ( const T & value ) ;
(1) (C++26부터)
constexpr reference push_back ( T && value ) ;
(2) (C++26부터)

주어진 요소 value 를 컨테이너의 끝에 추가합니다.

1) 새로운 요소는 value 의 복사본으로 초기화됩니다.
2) value 가 새로운 요소로 이동됩니다.

반복자나 참조는 무효화되지 않습니다. 단, end() 는 삽입이 발생할 경우 무효화됩니다.

목차

매개변수

value - 추가할 요소의 값
타입 요구사항
-
T 는 오버로드 (1)을 사용하기 위해 CopyInsertable 요구사항을 충족해야 합니다.
-
T 는 오버로드 (2)를 사용하기 위해 MoveInsertable 요구사항을 충족해야 합니다.

반환값

back() , 즉 삽입된 요소에 대한 참조입니다.

복잡도

상수.

예외

  • std::bad_alloc 이 발생하는 경우 size ( ) == capacity ( ) 인 경우 호출 전.
  • 삽입된 요소의 초기화 과정에서 발생하는 모든 예외.

어떤 이유로든 예외가 발생하면, 이 함수들은 아무런 효과를 가지지 않습니다( strong exception safety guarantee ).

예제

#include <inplace_vector>
#include <new>
#include <print>
#include <string>
int main()
{
    std::inplace_vector<std::string, 2> fauna;
    std::string dog{"\N{DOG}"};
    fauna.push_back("\N{CAT}"); // 오버로드 (1)
    fauna.push_back(std::move(dog)); // 오버로드 (2)
    std::println("fauna = {}", fauna);
    try
    {
        fauna.push_back("\N{BUG}"); // 예외 발생: 공간이 부족함
    }
    catch(const std::bad_alloc& ex)
    {
        std::println("{}", ex.what());
    }
    std::println("fauna = {}", fauna);
}

가능한 출력:

fauna = ["🐈", "🐕"]
std::bad_alloc
fauna = ["🐈", "🐕"]

참고 항목

끝에 제자리에서 요소를 생성합니다
(public member function)
끝에 요소들의 범위를 추가합니다
(public member function)
끝에 요소를 추가하려고 시도합니다
(public member function)
끝에 제자리에서 요소를 생성하려고 시도합니다
(public member function)
끝에 요소들의 범위를 추가하려고 시도합니다
(public member function)
무조건적으로 끝에 요소를 추가합니다
(public member function)
무조건적으로 끝에 제자리에서 요소를 생성합니다
(public member function)
마지막 요소를 제거합니다
(public member function)
인수에서 추론된 타입의 std::back_insert_iterator 를 생성합니다
(function template)