M
Malcolm Smith
I have this functor:
struct DeleteIterObject
{
template< typename T >
void operator()(const T* ptr) const
{
delete ptr;
ptr = NULL;
}
};
Currently, the code is used like this:
FOwnerPolicy.DeleteObjects(FContainer.begin(), FContainer.end());
where FOwnerPolicy is a policy class of type 'TOwnIteratorObjectsPolicy',
shown below:
struct TOwnIteratorObjectsPolicy
{
template< class IterType >
void DeleteObjects(IterType IterB, IterType IterE)
{
std::for_each(IterB, IterE, DeleteIterObject());
}
};
Now I'm trying to work out how to specialize DeleteIterObject for the case
when 'T' is a std:air< 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 TOwnPairSecondObjectsPolicy
{
template< class IterType >
void DeleteObjects(IterType IterB, IterType IterE)
{
std::for_each(IterB, IterE, BindPairSecond(DeleteIterObject()));
}
};
[ BindPairSecond is similar in design to Bind2nd, where I pass the .second
element to DeleteIterObject for processing ]
But I cannot work out how to create a specialized case of
DeleteIterObjects(). I would ideally like to convert this:
std::for_each(IterB, IterE, BindPairFirst(DeleteIterObject()));
std::for_each(IterB, IterE, BindPairSecond(DeleteIterObject()));
into a single call such as:
std::for_each(IterB, IterE, DeleteIterObject());
I'm sure it can be done by overloading the operator() method of
'DeleteIterObject' but I cannot work out the syntax.
Is what I'm after possible ?
--
struct DeleteIterObject
{
template< typename T >
void operator()(const T* ptr) const
{
delete ptr;
ptr = NULL;
}
};
Currently, the code is used like this:
FOwnerPolicy.DeleteObjects(FContainer.begin(), FContainer.end());
where FOwnerPolicy is a policy class of type 'TOwnIteratorObjectsPolicy',
shown below:
struct TOwnIteratorObjectsPolicy
{
template< class IterType >
void DeleteObjects(IterType IterB, IterType IterE)
{
std::for_each(IterB, IterE, DeleteIterObject());
}
};
Now I'm trying to work out how to specialize DeleteIterObject for the case
when 'T' is a std:air< 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 TOwnPairSecondObjectsPolicy
{
template< class IterType >
void DeleteObjects(IterType IterB, IterType IterE)
{
std::for_each(IterB, IterE, BindPairSecond(DeleteIterObject()));
}
};
[ BindPairSecond is similar in design to Bind2nd, where I pass the .second
element to DeleteIterObject for processing ]
But I cannot work out how to create a specialized case of
DeleteIterObjects(). I would ideally like to convert this:
std::for_each(IterB, IterE, BindPairFirst(DeleteIterObject()));
std::for_each(IterB, IterE, BindPairSecond(DeleteIterObject()));
into a single call such as:
std::for_each(IterB, IterE, DeleteIterObject());
I'm sure it can be done by overloading the operator() method of
'DeleteIterObject' but I cannot work out the syntax.
Is what I'm after possible ?
--