std::forward_list<T,Allocator>:: push_front
From cppreference.net
<
cpp
|
container
|
forward list
|
void
push_front
(
const
T
&
value
)
;
|
(1) |
(C++11以降)
(constexprはC++26以降) |
|
void
push_front
(
T
&&
value
)
;
|
(2) |
(C++11以降)
(constexprはC++26以降) |
コンテナの先頭に value のコピーを追加します。
イテレータおよび参照は無効化されません。
目次 |
パラメータ
| value | - | 先頭に追加する要素の値 |
| 型要件 | ||
|
-
|
||
計算量
定数。
例外
何らかの理由で例外がスローされた場合、これらの関数は何も効果を持ちません( 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) |