Alvin wrote:[color=blue]
> Hello all,
>
> I'm curious as to your opinions on explicitly inlining function? I'm talking
> about functions as members of a class. For example, so class A defines a
> operator==() and a operator!=():
>
> class_a.h:
>
> class A
> {
> public:
> A();
> bool operator==(A &rhs);
> inline bool operator!=(A &rhs);
> ...
> };
>
> bool A::operator!=(A &rhs)
> {
> return !(*this == rhs);
> }
>
> Is it something that should be done by the programmer or should we assume
> that compiler optimisations will take care of it?
>[/color]
In my opinion, functions and methods should be inlined
when the execution cost of their content is less than
or equal to the function call & return overhead; provided
the function has already been tested as a non-inlined
function.
Exceptions:
1. Development.
Many compilers have problems providing debugging
information for inlined functions.
2. Deliverable headers.
Interfaces for the external customer, such as
libraries, should not have inlined functions;
or change the design so that the delivered headers
do not contain inlined code.
Again, this is my opinion. Yours may differ.
Remember that the keyword "inline" is only a suggestion
to the compiler. The compiler may already be inlining
the function (or eliminating it).
Don't worry about optimizations until the project
works correctly.
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq:
http://www.parashift.com/c++-faq-lite
C Faq:
http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library