473,387 Members | 1,899 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,387 software developers and data experts.

remove elements from vector

Hello,

I am thinking an efficient way to remove all the elements (says they
are less than 10) from a container vector<int>.

Any suggestion? Thank you.

Oct 31 '06 #1
5 2624
Wing wrote:
Hello,

I am thinking an efficient way to remove all the elements (says they
are less than 10) from a container vector<int>.

Any suggestion? Thank you.
Look into std::remove_if, std::less, std::bind2nd, and the erase-remove
idiom.

Nate
Oct 31 '06 #2
Wing wrote:

I am thinking an efficient way to remove all the elements (says they
are less than 10) from a container vector<int>.

Any suggestion? Thank you.
Any reason not to use std::vector::clear()?

Best regards,

Tom

Oct 31 '06 #3

Nate Barney wrote:
Wing wrote:
Hello,

I am thinking an efficient way to remove all the elements (says they
are less than 10) from a container vector<int>.

Any suggestion? Thank you.

Look into std::remove_if, std::less, std::bind2nd, and the erase-remove
idiom.

Sounds like overkill if the OP wants to remove _all_ the elements.

Best regards,

Tom

Oct 31 '06 #4
Thomas Tutone wrote:
Nate Barney wrote:
>Wing wrote:
>>Hello,

I am thinking an efficient way to remove all the elements (says they
are less than 10) from a container vector<int>.

Any suggestion? Thank you.
Look into std::remove_if, std::less, std::bind2nd, and the erase-remove
idiom.

Sounds like overkill if the OP wants to remove _all_ the elements.
I first read the question as "How does one remove all elements that are
less than 10?". I suppose it could be read as "How does one remove all
elements of a vector that has fewer than 10 elements?". Well, now the
OP has an answer either way.

Nate
Oct 31 '06 #5
Nate Barney wrote:
Thomas Tutone wrote:
Nate Barney wrote:
Wing wrote:
Hello,

I am thinking an efficient way to remove all the elements (says they
are less than 10) from a container vector<int>.

Any suggestion? Thank you.
Look into std::remove_if, std::less, std::bind2nd, and the erase-remove
idiom.
Sounds like overkill if the OP wants to remove _all_ the elements.

I first read the question as "How does one remove all elements that are
less than 10?". I suppose it could be read as "How does one remove all
elements of a vector that has fewer than 10 elements?". Well, now the
OP has an answer either way.
Now I understand. I hadn't read the OP's question that way, but after
reading your interpretation I went back and reread the OP's question,
and now I see your point.

Best regards,

Tom

Oct 31 '06 #6

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

Similar topics

8
by: Generic Usenet Account | last post by:
To settle the dispute regarding what happens when an "erase" method is invoked on an STL container (i.e. whether the element is merely removed from the container or whether it also gets deleted in...
5
by: Yngve | last post by:
Hi! I have a (newbie) problem wich i would become glad if someone could help me with. I have a Vector of pointers to instances of another class. I would like to remove a position in the...
34
by: Adam Hartshorne | last post by:
Hi All, I have the following problem, and I would be extremely grateful if somebody would be kind enough to suggest an efficient solution to it. I create an instance of a Class A, and...
11
by: koperenkogel | last post by:
Dear cpp-ians, I am working with a vector of structures. vector <meta_segment> meta_segm (2421500); and the structure look like: struct meta_segment { float id; float num;
6
by: Arne Claus | last post by:
Hi If've just read, that remove() on a list does not actually remove the elements, but places them at the end of the list (according to TC++STL by Josuttis). It also says, that remove returns a...
6
by: happyvalley | last post by:
Hi, I want to remove some elements from a vector, the following code doesn't work, seems it doesn't allow me to remove an element when iterating the vector. (make sense), just wonder, how to do...
3
by: groups | last post by:
This small piece of code is troubling me.. is there anything wrong with it?? After calling this method the contents ot the input vector are completely screwed.. (CCountedCIG_CountZero() applies...
7
by: mohammaditraders | last post by:
Write a program which overloads a binary Minus (+) operator, The program will contain a class Matrix, This class will contain a private data member Array which store int values. The class will...
2
by: Angus | last post by:
Hello I have a vector<int(aRemovecoll) which is a list of the indexes to be removed from another vector. The other vecotr contains an object - I will call it SomeObject. So the other vecotr is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.