C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Some sort of append algorithm...

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
deancoo
Guest





PostPosted: Sun Feb 27, 2005 12:52 am    Post subject: Some sort of append algorithm... Reply with quote



I'm looking for an STL algorithm similar to 'copy', but not needing the
target container to have elements available to copy into (a 'valid range').
What I need to do is something simple like, take all the elements in
container A and append them to the end of container B (sorting is not
necessary). I've looked at set_union and merge, but they don't seem to do
the trick.

d


Back to top
Jonathan Turkanis
Guest





PostPosted: Sun Feb 27, 2005 12:53 am    Post subject: Re: Some sort of append algorithm... Reply with quote



deancoo wrote:
Quote:
I'm looking for an STL algorithm similar to 'copy', but not needing
the target container to have elements available to copy into (a
'valid range'). What I need to do is something simple like, take all
the elements in container A and append them to the end of container B

If B is a sequence supporting push_back, you can write:

std::copy(A.begin(), A.end(), std::back_inserter(B));

Quote:
(sorting is not necessary). I've looked at set_union and merge, but
they don't seem to do the trick.


Quote:
d

Jonathan



Back to top
deancoo
Guest





PostPosted: Sun Feb 27, 2005 2:43 am    Post subject: Re: Some sort of append algorithm... Reply with quote



Quote:
If B is a sequence supporting push_back, you can write:

std::copy(A.begin(), A.end(), std::back_inserter(B));

Jonathan


Why yes you can. Thanks Jonathan. That's going to save me allot of time
and complication. Is "back_inserter" is a member function of the sequence?
An algorithm of its own? I can't seem to find any reference to it.

d



Back to top
Jonathan Turkanis
Guest





PostPosted: Sun Feb 27, 2005 4:39 am    Post subject: Re: Some sort of append algorithm... Reply with quote

deancoo wrote:
Quote:
If B is a sequence supporting push_back, you can write:

std::copy(A.begin(), A.end(), std::back_inserter(B));

Jonathan


Why yes you can. Thanks Jonathan. That's going to save me allot of
time and complication. Is "back_inserter" is a member function of
the sequence? An algorithm of its own? I can't seem to find any
reference to it.


I guess I should have been more explicit. Include the standard header
<iterator>. This contains the definition of the clas template
back_insert_iterator, whose instances insert elements at the end of a container,
and the helper function back_inserter, which takes a reference to a container
and returns an instance of an appropriate specialization of
back_insert_iterator.

There's also an insert_iterator and front_insert_iterator.

Quote:
d

Jonathan



Back to top
davidrubin@warpmail.net
Guest





PostPosted: Sun Feb 27, 2005 4:40 am    Post subject: Re: Some sort of append algorithm... Reply with quote

It's in the 'iterator' header file. It's a function template in the
'std' namespace. /david

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.