Is there any performance advantage to be had when using template parameters with static member functions instead of functor-style predicates??
For instance, a functor-style sort interface is typically something like this:
template <typename _Type, typename _Pred>
void sort (
RandomAccessIterator first,
RandomAccessIterator last ,
_Pred less_than
)
{
// actual sorting code here, calling less_than()...
}
You could do something more like this, and require that _Pred
contained a static member function _Pred::less_than
:
template <typename _Type, typename _Pred>
void sort (
RandomAccessIterator first,
RandomAccessIterator last
)
{
// actual sorting code here, calling _Pred::less_than()...
}
In theory, the first case might dynamically create a temporary functor object on the heap, whereas I believe that the second case is fully evaluated at compile time. I understand that (say) gcc and/or msvc are good at optimising, but can this be done to the same degree in the first case??
Also, I'm not trying to rewrite the STL sort routines or anything like that, just an example for a more general functor question...