insert adapters C++

来源:互联网 发布:永久下架的网络剧 编辑:程序博客网 时间:2024/06/05 18:48

Inserters (also called "insert iterators") are "iterator adaptors" that permit algorithms (the copy algorithm, for example) to operate in insert mode rather than overwrite mode, which is the default. Thus they solve the problem that crops up when an algorithm tries to write elements to a destination container not already big enough to hold them, by making the destination grow as needed. There are three kinds of inserters, as shown in the table below:

  1. The back_inserter(), which can be used if the recipient container supports the push_back() member function.
  2. The front_inserter(), which can be used if the recipient container supports the push_front() member function.
  3. The inserter(), which can be used if the recipient container supports the insert() member function.
back_inserter(container_supporting_push_back) 
Used to permit an algorithm to operate in "insert mode" at the "back" of a container that supports the push_back() member function.front_inserter(container_supporting_push_front) 
Used to permit an algorithm to operate in "insert mode" at the "front" of a container that supports the push_front() member function.inserter(container_supporting_insert, insert_start_location) 
Used to permit an algorithm to operate in "insert mode" at any "interior" point of a container that supports the insert() member function.
原创粉丝点击