Are operators always inlined?
struct foo {
void operator ()() {
// Do tons of work.
}
};
int main() {
foo f;
f();
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The compiler is the unprecedented and (officially) unpredictable lord of inlining decisions. Good compilers will provide some guidance in the documentation about their implementations behaviour. The more complicated the code the less likely it is to be inlined, you can find some examples of what does/doesn’t tend to inline on the Wikipedia.
“Do tons of work” on it’s own suggests that your intended operator is too complicated for most compilers to inline.
Microsoft’s Visual C++ compiler can be made to generate warnings, when it decides to inline a function that wasn’t marked inline and when it doesn’t inline one that was marked inline. I like it for getting a feel for what it can inline.