Reputation:
Is this caused by the implementation of mem_fn()
being defined without __forceinline/inline/__attribute__((always_inline))
?
Is it possible to work around this, e.g. using ones own implementation of mem_fn?
Upvotes: 1
Views: 90
Reputation:
So, std::mem_fn() does not inline for some reason or another. This cannot simply be, because of the address operator was used to determine the address, as calls to normal functions (also specified via the address operator) are inlined. I assume, that this is caused, by the address of the method being stored in some object created by std::mem_fn(). The solution here is to rewrite the function which needs function pointers as arguments to enable it to accept method pointers. The resulting assembler code does not contain any call statements anymore.
Implementing std::mem_fn() by myself did not yield any advantage -- functions were also not inlined.
Upvotes: 0
Reputation: 4166
Taking the pointer of a function doesn't allow it to be inlined.
The compiler won't be able to inline it, unless it's known in compile time which function will be called (through the pointer or std::mem_fn
), in which case why use std::mem_fn
in the first place (when you can call the function)?
Upvotes: 2