Are operators always inlined?
struct foo {
void operator ()() {
// Do tons of work.
}
};
int main() {
foo f;
f();
}
Are operators always inlined?
struct foo {
void operator ()() {
// Do tons of work.
}
};
int main() {
foo f;
f();
}
No, they are not. The compiler is completely free to ignore all and any requests that a function be inlined. What it can't ignore is that it must give them internal linkage, so a header containing them can be included in multiple translation units.
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.