M
Matthias Kaeppler
Hello,
I need to sort a range of pointers with a predicate which applies to the
pointees. I tried to use boost::indirect_iterator, however, this will
sort the container with the pointees instead the one with the pointers:
vector<int> coll;
// ...
vector<int*> ptrcoll;
// ...
indirect_iterator< vector<int*>::iterator > begin(ptrcoll.begin()),
end(ptrcoll.end());
sort( begin, end ); // this sorts coll, not ptrcoll, what have I gained?
Instead, is there some sort of adaptor, which allows things like this:
vector<int> coll;
// ...
vector<int*> ptrcoll;
// ...
sort( ptrcoll.begin(), ptrcoll.end(), dereference( less<int>() ) );
.... where dereference is an adaptor taking the function/functor
representing the predicate on the pointees.
I need to sort a range of pointers with a predicate which applies to the
pointees. I tried to use boost::indirect_iterator, however, this will
sort the container with the pointees instead the one with the pointers:
vector<int> coll;
// ...
vector<int*> ptrcoll;
// ...
indirect_iterator< vector<int*>::iterator > begin(ptrcoll.begin()),
end(ptrcoll.end());
sort( begin, end ); // this sorts coll, not ptrcoll, what have I gained?
Instead, is there some sort of adaptor, which allows things like this:
vector<int> coll;
// ...
vector<int*> ptrcoll;
// ...
sort( ptrcoll.begin(), ptrcoll.end(), dereference( less<int>() ) );
.... where dereference is an adaptor taking the function/functor
representing the predicate on the pointees.