std::forward_list<T,Allocator>::push_front
From cppreference.com
< cpp | container | forward list
| void push_front( const T& value ); |
(1) | (C++11以降) |
| void push_front( T&& value ); |
(2) | (C++11以降) |
コンテナの先頭に要素 value を追加します。
イテレータや参照は無効化されない。
目次 |
[編集] パラメータ
| value | - | 先頭に追加する要素の値 |
[編集] 計算量
定数。
[編集] 例外
何らかの理由で例外がスローされた場合、これらの関数は効果がありません(強力な例外安全性保証)。
[編集] 例
このコードを実行
#include <forward_list> #include <iomanip> #include <iostream> #include <string> int main() { std::forward_list<std::string> letters; letters.push_front("send"); std::string s{"me"}; letters.push_front(std::move(s)); 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: ""
[編集] 関連項目
| 先頭に要素を直接構築する (公開メンバ関数) | |
| 最初の要素を削除する (公開メンバ関数) | |
| 引数から推論された型の std::front_insert_iterator を作成する (関数テンプレート) |