std::list<T,Allocator>:: push_back
From cppreference.net
|
void
push_back
(
const
T
&
value
)
;
|
(1) | (constexpr since C++26) |
|
void
push_back
(
T
&&
value
)
;
|
(2) |
(C++11부터)
(constexpr since C++26) |
컨테이너의 끝에 value 의 사본을 추가합니다.
반복자나 참조가 무효화되지 않습니다.
목차 |
매개변수
| value | - | 추가할 요소의 값 |
|
(C++11부터) | ||||||
복잡도
상수.
예외
예외가 발생하면(이는
Allocator::allocate()
또는 요소 복사/이동 생성자/대입 연산자로 인해 발생할 수 있음), 이 함수는 아무런 효과를 가지지 않습니다(
strong exception guarantee
).
예제
이 코드 실행
#include <iomanip> #include <iostream> #include <string> #include <list> int main() { std::list<std::string> letters; letters.push_back("abc"); std::string s{"def"}; letters.push_back(std::move(s)); std::cout << "std::list letters holds: "; for (auto&& e : letters) std::cout << std::quoted(e) << ' '; std::cout << "\nMoved-from string s holds: " << std::quoted(s) << '\n'; }
가능한 출력:
std::list letters holds: "abc" "def" Moved-from string s holds: ""
참고 항목
|
(C++11)
|
끝에 제자리에서 요소를 생성
(public member function) |
|
시작 부분에 요소를 삽입
(public member function) |
|
|
마지막 요소를 제거
(public member function) |
|
|
인수에서 추론된 타입의
std::back_insert_iterator
를 생성
(function template) |