Namespaces
Variants

std::forward_list<T,Allocator>:: push_front

From cppreference.net

void push_front ( const T & value ) ;
(1) (C++11부터)
(C++26부터 constexpr)
void push_front ( T && value ) ;
(2) (C++11부터)
(C++26부터 constexpr)

컨테이너의 시작 부분에 value 의 복사본을 추가합니다.

반복자나 참조가 무효화되지 않습니다.

목차

매개변수

value - 앞에 추가할 요소의 값
타입 요구사항
-
다음 조건이 충족될 경우 동작은 정의되지 않음:
1) T CopyInsertable 이 아니면서 forward_list 에 삽입되는 경우
2) T MoveInsertable 이 아니면서 forward_list 에 삽입되는 경우

복잡도

상수.

예외

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

예제

#include <forward_list>
#include <iomanip>
#include <iostream>
#include <string>
int main()
{
    std::forward_list<std::string> letters;
    letters.push_front("me"); // 오버로드 (1)
    std::string s{"send"};
    letters.push_front(std::move(s)); // 오버로드 (2)
    std::cout << "std::forward_list letters holds: ";
    for (auto&& e : letters)
        std::cout << std::quoted(e) << ' ';
    std::cout << "\nMoved-from string s holds: " << std::quoted(s) << '\n';
}

가능한 출력:

std::forward_list letters holds: "send" "me"
Moved-from string s holds: ""

참고 항목

시작 부분에 제자리에서 요소를 생성합니다
(public member function)
첫 번째 요소를 제거합니다
(public member function)
인수에서 추론된 타입의 std::front_insert_iterator 를 생성합니다
(function template)