views:

191

answers:

3

Since boost::shared_ptr could be called very frequently and simply returns a pointer, isn't the -> operator a good candidate for being inlined?

T * operator-> () const // never throws
{
    BOOST_ASSERT(px != 0);
    return px;
}

Would a good compiler automatically inline this anyway?

Should I lose any sleep over this? :-)

+3  A: 

Would a good compiler automatically inline this anyway?

Quite probably, yes, it would.

Should I lose any sleep over this?

Better not. If you want to be super-sure (or you are super-curious), check the assembly that's going out from your compiler.

jpalecek
+14  A: 

Functions defined (i.e. with a body) inside a class are implicitly candidates for inlining. There is no need to use the inline keyword in these cases, and it is unusual to do so.

anon
A: 

Lose sleep when you know it's costing you something :)

jkp