std::inplace_vector<T,N>:: try_push_back
|
constexpr
pointer try_push_back
(
const
T
&
value
)
;
|
(1) | (C++26부터) |
|
constexpr
pointer try_push_back
(
T
&&
value
)
;
|
(2) | (C++26부터) |
주어진 요소 value 를 조건부로 컨테이너의 끝에 추가합니다.
만약
size
(
)
==
capacity
(
)
가
true
인 경우, 아무런 효과도 없습니다. 그렇지 않으면
T
타입의 객체를 추가합니다:
반복자나 참조는 무효화되지 않습니다. 단,
end()
는 삽입이 발생할 경우 무효화됩니다.
목차 |
매개변수
| value | - | 추가할 요소의 값 |
| 타입 요구사항 | ||
-
T
는
EmplaceConstructible
의 요구사항을 충족해야 합니다.
|
||
반환값
std:: addressof ( back ( ) ) 만약 size ( ) < capacity ( ) 인 경우, nullptr 그 외의 경우.
복잡도
상수.
예외
삽입된 요소의 초기화 과정에서 발생하는 모든 예외.
어떤 이유로든 예외가 발생하면, 이 함수들은 아무런 효과를 가지지 않습니다( strong exception safety guarantee ).
참고 사항
|
이 섹션은 불완전합니다
이유: 이 API의 목적을 설명해야 합니다. |
예제
#include <cassert> #include <inplace_vector> #include <string> int main() { std::inplace_vector<std::string, 2> pets; std::string dog{"dog"}; std::string* p1 = pets.try_push_back("cat"); // 오버로드 (1) assert(*p1 == "cat" and pets.size() == 1); std::string* p2 = pets.try_push_back(std::move(dog)); // 오버로드 (2) assert(*p2 == "dog" and pets.size() == 2); assert(pets[0] == "cat" and pets[1] == "dog"); assert(pets.size() == pets.capacity()); std::string* p3 = pets.try_push_back("bug"); assert(p3 == nullptr and pets.size() == 2); }
참고 항목
|
끝에 요소를 추가함
(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) |