I have this functor:
struct DeleteIterObjec t
{
template< typename T >
void operator()(cons t T* ptr) const
{
delete ptr;
ptr = NULL;
}
};
Currently, the code is used like this:
FOwnerPolicy.De leteObjects(FCo ntainer.begin() , FContainer.end( ));
where FOwnerPolicy is a policy class of type 'TOwnIteratorOb jectsPolicy',
shown below:
struct TOwnIteratorObj ectsPolicy
{
template< class IterType >
void DeleteObjects(I terType IterB, IterType IterE)
{
std::for_each(I terB, IterE, DeleteIterObjec t());
}
};
Now I'm trying to work out how to specialize DeleteIterObjec t for the case
when 'T' is a std::pair< U*, V* >. I've created another functor that will
bind to either the first or the second element and delete the object - like
this for example:
struct TOwnPairSecondO bjectsPolicy
{
template< class IterType >
void DeleteObjects(I terType IterB, IterType IterE)
{
std::for_each(I terB, IterE, BindPairSecond( DeleteIterObjec t()));
}
};
[ BindPairSecond is similar in design to Bind2nd, where I pass the .second
element to DeleteIterObjec t for processing ]
But I cannot work out how to create a specialized case of
DeleteIterObjec ts(). I would ideally like to convert this:
std::for_each(I terB, IterE, BindPairFirst(D eleteIterObject ()));
std::for_each(I terB, IterE, BindPairSecond( DeleteIterObjec t()));
into a single call such as:
std::for_each(I terB, IterE, DeleteIterObjec t());
I'm sure it can be done by overloading the operator() method of
'DeleteIterObje ct' but I cannot work out the syntax.
Is what I'm after possible ?
--
---
Malcolm Smith
MJ Freelancing
http://www.mjfreelancing.com
Borland Technology Partner