最終更新日時(UTC):
が更新

履歴 編集

function template
<deque>

std::deque::emplace(C++11)

template <class... Args>
iterator emplace(const_iterator position, Args&&... args);

概要

任意の位置に要素を直接構築で挿入する

要件

要素型 value_type は、引数 args からコンテナに対して EmplaceConstructible でなければならない。また、要素型 value_type はコンテナに対して、MoveInsertable であり、かつ、MoveAssignable でなければならない。

効果

std::forward<Args>(args)... で構築された value_type 型のオブジェクトを position の手前に挿入する。

戻り値

挿入された要素を指すイテレータ

計算量

dequeの要素数に対して線形時間、先頭もしくは末尾への挿入は定数時間

備考

例外発生時に副作用が発生しない保証はinsert()と同様。

#include <iostream>
#include <deque>
#include <utility>
#include <string>

int main()
{
  std::deque<std::pair<int, std::string>> c;

  c.emplace(c.begin(), 3, std::string("hello"));
  c.insert(c.begin(), std::make_pair(1, std::string("world")));

  for (const auto& x : c) {
    std::cout << x.first << ',' << x.second << std::endl;
  }
}

出力

1,world
3,hello

バージョン

言語

  • C++11

処理系

  • Clang: ??
  • GCC: 4.7.2
  • ICC: ??
  • Visual C++: 2012, 2013
    • 2010にもemplaceは存在するが、insert相当の機能しかない。

関連項目

名前 説明
insert 任意の位置に要素を挿入する

参照