Sign in to follow this  
dmatter

inlining a member call made from a reference

Recommended Posts

dmatter    4844
Will/can a compiler inline a member function if it is called from a reference to an object, like so:
template <class T>
class container
{
    T& ref; //reference to an object implementing 'void do_something()'

public:
    container(T& r) : ref(r) { }

    void make_call() { ref.do_something(); }
};
I would like to say that a general compiler would inline away make_call() and do_something() but I'm not convinced but I need to know now as this is performance crucial code i'm trying (*ahem, sniff*) to write. [smile] Thanks Dmatter P.S. I found it hard to find much on google, if anyone can offer any good search terms or a good linky, it'd be appreciated too.

Share this post


Link to post
Share on other sites
SiCrane    11839
You could look at the disassembly you compiler generates rather than ask us. /FA family of switches for MSVC, -S for gcc. It probably is a better judge of what it will inline than humans.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this