Why is the boost :: shared_ptr & # 8594; not declared inline?

Since boost::shared_ptr

one would call very often and just return a pointer, isn't the operator a ->

good candidate for inlined

?

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

      

Will a good compiler be automatic inline

anyway?

Should I lose sleep over this? :-)

+2


a source to share


3 answers


Functions defined (i.e. with a body) inside a class are implicitly candidates for nesting. In these cases, it is not necessary to use a keyword inline

and it is unusual to do so.



+18


a source


Would a good compiler automatically embed this?

It is possible, yes, it would.



Should I lose sleep over this?

Better not. If you want to be sure (or are very curious), check the assembly that comes out of your compiler.

+4


a source


Note that shared_ptr

is a template class , 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 defined function with a storage specifier inline

.

In a sense, it template

also means inline

.

+1


a source







All Articles