user8434768
user8434768

Reputation:

std::mem_fn(&method_defined_with_forceinline)(*this) not inlined

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

Answers (2)

user8434768
user8434768

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

Kostas
Kostas

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

Related Questions