Hi!
schrieb:
> But it seems that instantiated objects outperform static member
> functions by a significant amount. My question is, is there some
> inherent reason for this, or is this likely to be different from
> compiler to compiler? Perhaps static member functions can't be
> inlined.
When passing a (static) function to i.e. std::for_each, you get an
instantiation of for_each, which takes a function pointer as an
argument. So each element is processed by calling a function through a
pointer.
When passing a class instance (a functor) to std::for_each, you get an
instantiation for just that specific class. Each element is process by
an inlined operator().
Usually the compiler does not optimize the (const) function pointer. It
might do so, however. That's why small functors outperform the static
function.
Frank