So that's what I got :
template<class Z> struct maskChecker {
public:
maskChecker(const vector<bool> &mask) : it(mask.begin()) {}
bool operator()(Z&) const { return *it ++; }
private:
mutable vector<bool>::const_iterator it;
Instead of keeping a mutable iterator by value, I'd probably keep a
reference to an iterator. But, yes, that's the general idea.
};
template<class T> template<class Z>
void Selector<T>::compact(vector<Z> &data, const vector<bool> &mask) {
if (data.size() != mask.size()) throw UnmatchedSize(data.size(),
mask.size());
typename vector<Z>::iterator end = remove_if(data.begin(),
data.end(), maskChecker<Z>(mask));
data.erase(end, data.end());
}
That's kinda working, what's your opinion ?
I would do almost exactly the same, except for the iterator (I just
don't like 'mutable' for some reason). If it works, then you're OK, I
think.
[lib.alg.remove/5] says that the complexity is *exactly* (last-first)
applications of the corresponding predicate. If you had a reference to
the mask iterator, you could compare the iterator to mask.end() after
the call to 'remove_if' as well (and even assert on that).
Perfect, that's what I'll use.