Conditional copying using stl functions



 DEVELOP > c-Plus-Plus > Conditional copying using stl functions

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Sarath"
Date: 18 Dec 2007 02:17:42 AM
Object: Conditional copying using stl functions
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
.

User: "anon"

Title: Re: Conditional copying using stl functions 18 Dec 2007 02:44:57 AM
Sarath wrote:

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
?
.
User: "Sarath"

Title: Re: Conditional copying using stl functions 19 Dec 2007 03:25:46 AM
On Dec 18, 5:44 pm, anon <a...@no.no> wrote:

Sarath wrote:

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.
.



  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER