简体   繁体   中英

Why isn't the boost::shared_ptr -> operator declared inline?

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? :-)

Functions defined (ie 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.

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.

Please note that shared_ptr is a class template , so its member functions are actually function templates .

Since they are not export ed, they must not only be declared , but also defined in all translation units where they are used, just like a function defined with the inline storage specifier.

In a way, template also means inline .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM