473,395 Members | 1,869 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Some sort of append algorithm...

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
Jul 23 '05 #1
4 1448
deancoo wrote:
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));
(sorting is not necessary). I've looked at set_union and merge, but
they don't seem to do the trick.
d


Jonathan
Jul 23 '05 #2
> 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
Jul 23 '05 #3
It's in the 'iterator' header file. It's a function template in the
'std' namespace. /david

Jul 23 '05 #4
deancoo wrote:
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.
d


Jonathan
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ken R. | last post by:
Hello all, I am relatively new to python but I am having an issue with custom sort functions.. I am trying to sort a list of lists or tuples with arbitrary ascending or descending sorts. For...
7
by: Stephan Diehl | last post by:
A while ago, I've posted a recipie about finding a common prefix to a list of strings. While the recipie itself is quite bad (I have to admit) and I didn't know at that time that this problem was...
7
by: svilen | last post by:
hello again. i'm now into using python instead of another language(s) for describing structures of data, including names, structure, type-checks, conversions, value-validations, metadata etc....
1
by: Kamilche | last post by:
I've written a generic sort routine that will sort dictionaries, lists, or tuples, either by a specified key or by value. Comments welcome! import types def sort(container, key = None,...
18
by: googleboy | last post by:
I didn't think this would be as difficult as it now seems to me. I am reading in a csv file that documents a bunch of different info on about 200 books, such as title, author, publisher, isbn,...
0
by: Jaeho Kim | last post by:
Hi,,, I am very interested about the following Python program, but I am very beginner on Python.. I do not understand this algorithm,, I would appreciated if you give me this algorithm to some...
5
by: Lieven De Keyzer | last post by:
Is the STL sort() algorithm implemented genericly over all the containers or once for each container? And in which file is it implemented?
193
by: Michael B. | last post by:
I was just thinking about this, specifically wondering if there's any features that the C specification currently lacks, and which may be included in some future standardization. Of course, I...
8
by: ianaré | last post by:
Hey all, if i use a os.walk() to append files to a list like so... files = root = self.path.GetValue() # wx.TextCtrl input filter = self.fileType.GetValue().lower() # wx.TextCtrl input...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.