S
silverburgh.meryl
i have the following code, but it does not compile because I pass in
back_inserter(b) as the output iterator in the remove_copy_if
algorithm.
My questions are:
1. why it does not compile? Passing a back_inserter() works for copy()
algorithm, why not remove_copy_if()?
2. is there a work-around for my problem? I think one solution is to
allocate 'b' as big as 'a', but that seems to be a waste of memory for
the case of b is a lot smaller than a.
Thank you.
class EvenValue {
public:
bool operator() (float value) {
return (int)value %2 ? false : true;
}
};
float func1(vector<float>& a, float max ) {
vector<float> b;
vector<float>::iterator itr = remove_copy_if (a.begin(), a.end(),
back_inserter(b), EvenValue() );
// do something with 'b'
return 0.0;
}
back_inserter(b) as the output iterator in the remove_copy_if
algorithm.
My questions are:
1. why it does not compile? Passing a back_inserter() works for copy()
algorithm, why not remove_copy_if()?
2. is there a work-around for my problem? I think one solution is to
allocate 'b' as big as 'a', but that seems to be a waste of memory for
the case of b is a lot smaller than a.
Thank you.
class EvenValue {
public:
bool operator() (float value) {
return (int)value %2 ? false : true;
}
};
float func1(vector<float>& a, float max ) {
vector<float> b;
vector<float>::iterator itr = remove_copy_if (a.begin(), a.end(),
back_inserter(b), EvenValue() );
// do something with 'b'
return 0.0;
}