Conditional copying using stl functions

S

Sarath

I've two vectors vectorA and vectorB.
I've copy some elements from vectorA to B on satisfying some
conditions. I'd like to avoid for loop and comparison routines. It
would appreciate if there are any stl routines/classes can help on
this matter. I tried using for_each but still passing elements still a
problem.

e.g
stuct Test
{
char name[20];
int nCategory;
}

void Filter( const vector<Test>& vecA, vector<Test>& vecB, char*
pFilter)
{
// compare "name" attribute with "pFilter" and copy on success
}

Thanks in advance.

Regards,
Sarath
 
A

anon

Sarath said:
I've two vectors vectorA and vectorB.
I've copy some elements from vectorA to B on satisfying some
conditions. I'd like to avoid for loop and comparison routines. It
would appreciate if there are any stl routines/classes can help on
this matter. I tried using for_each but still passing elements still a
problem.

e.g
stuct Test
{
char name[20];
int nCategory;
}

void Filter( const vector<Test>& vecA, vector<Test>& vecB, char*
pFilter)
{
// compare "name" attribute with "pFilter" and copy on success
}

Would this help:
http://wwwasd.web.cern.ch/wwwasd/lhc++/RW/stdlibcr/rem_9276.htm
?
 
S

Sarath

Sarath said:
I've two vectors vectorA and vectorB.
I've copy some elements from vectorA to B on satisfying some
conditions. I'd like to avoid for loop and comparison routines. It
would appreciate if there are any stl routines/classes can help on
this matter. I tried using for_each but still passing elements still a
problem.
e.g
stuct Test
{
char name[20];
int nCategory;
}
void Filter( const vector<Test>& vecA, vector<Test>& vecB, char*
pFilter)
{
// compare "name" attribute with "pFilter" and copy on success
}

Would this help:http://wwwasd.web.cern.ch/wwwasd/lhc++/RW/stdlibcr/rem_9276.htm
?- Hide quoted text -

- Show quoted text -

Thanks for your reply.
remove_copy_if will do the work but in my case the destiation size is
not predefined. the container should initialize with some size. seems
it doesn't increase the size of destination container.
In my case the input size will be large enough so I can't say the
exact size of destination container. If I "reserve" the same size of
input vector, it will create some performance hitch I believe.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,181
Messages
2,570,970
Members
47,537
Latest member
BellCorone

Latest Threads

Top