05項 単一要素メンバ関数より範囲メンバ関数を使おう
範囲メンバ関数とは、指定された範囲をまとめて処理できる関数です。
すべての標準シーケンスコンテナにサポートされる範囲メンバ関数は、以下の4通りです。
1,範囲生成 : コンストラクタ
container::container(InputIterator begin, //範囲の先頭 InputIterator end) //末尾
2,範囲挿入 : insert
void container::insert(iterator position, //範囲を挿入する場所 InputIterator begin, //挿入する範囲の先頭 InputIterator end); //挿入する範囲の末尾
3,範囲消去 : erase
container::erase(InputIterator begin, //削除する範囲の先頭 InputIterator end) //末尾
4,範囲代入 : assign
container::assign(InputIterator begin, //代入する範囲の先頭 InputIterator end) //末尾
単一のメンバ関数をループで呼び出すより、範囲メンバ関数を使ったほうが読みやすく、パフォーマンスに優れます。
なので、範囲メンバ関数を使うべきです。