std::back_inserter
提供: cppreference.com
ヘッダ <iterator> で定義
|
||
template< class Container > std::back_insert_iterator<Container> back_inserter( Container& c ); |
(C++20未満) | |
template< class Container > constexpr std::back_insert_iterator<Container> back_inserter( Container& c ); |
(C++20以上) | |
back_inserter
はコンテナ c
のための引数型から推定した型を持つ std::back_insert_iterator を構築する便利関数テンプレートです。
目次 |
[編集] 引数
c | - | push_back 操作をサポートするコンテナ |
[編集] 戻り値
コンテナ c
の終端��要素を追加するために使用できる std::back_insert_iterator。
[編集] 実装例
template< class Container > std::back_insert_iterator<Container> back_inserter( Container& c ) { return std::back_insert_iterator<Container>(c); } |
[編集] 例
Run this code
#include <iostream> #include <vector> #include <algorithm> #include <iterator> int main() { std::vector<int> v{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; std::fill_n(std::back_inserter(v), 3, -1); for (int n : v) std::cout << n << ' '; }
出力:
1 2 3 4 5 6 7 8 9 10 -1 -1 -1
[編集] 関連項目
コンテナの末尾に挿入するためのイテレータアダプタ (クラステンプレート) | |
引数から推定した型の std::front_insert_iterator を作成します (関数テンプレート) | |
引数から推定した型の std::insert_iterator を作成します (関数テンプレート) |