Heya Everyone,
I am trying to create a generic way to extract a list of objects from
another list of objects. Let me explain!
Say I have a vector (or any container with fwd iterators and value_type)
that contains objects that have a function which returns a long (could
actually be any type). I want to iterate over that vector and extract
each of the longs into a list (or any container that supports push_back
and defines value_type). Something like the following:
class HandleClass
{
public:
long handle() const { return val_++; }
private:
static long val_;
};
// ...
std::vector<HandleClass> listOfHcs;
// ... fill listOfHcs here
std::list<long> needToFill;
OK so far. I then wrote this extraction function (yes, there are many
ways I could have done this - with a functor and using foreach is
another possibility worth exploring, but not now :) ).
template
<
class ReturnContainer,
class FwdIterator
>
void Extract(const FwdIterator & itBegin,
const FwdIterator & itEnd,
ReturnContainer & container,
boost::function1