Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > An insert_itera...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 9446 of 10094
Post > Topic >>

An insert_iterator for forward_list

by Joe Gottman <jgottman@[EMAIL PROTECTED] > Apr 1, 2008 at 05:18 AM

Since forward_list has been accepted into the standard, it might be a
good idea to create a version of insert_iterator that works with it.
Forward_list is basically a C-style singly-linked list, and for
technical reasons it is defined so that insertions, deletions, etc. are
performed after an input iterator, instead of in front of it.  Thus,
while list has an insert() member function taking an iterator and a
value, forward_list has an insert_after function.

    One result of this is that forward_list cannot work with standard
insert_iterators, which assume the presence of an insert() member
function.  This makes it much harder to use a forward_list as the target
of an STL algorithm.  For instance, if vec is a vector<int>, list1 is an
empty list<int>, and list1 is a list<int> we can write code like
    transform(vec.begin(), vec.end(), inserter(list1, list1.end()), Foo);

  There's no equivalent way of doing the same thing to write to a
forward_list. (While we could use a front_inserter, the elements would
be added in reverse order, which could be a problem in many cases.)  I
think it would be useful to define a class insert_after_iterator() and
an associated free function inserter_after() to handle this case for
forward_lists.

Joe Gottman

-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 2 Posts in Topic:
An insert_iterator for forward_list
Joe Gottman <jgottman@  2008-04-01 05:18:12 
Re: An insert_iterator for forward_list
"Stephen Howe"   2008-04-01 15:13:04 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Oct 11 18:34:11 CDT 2008.