inlining and optimations when instantiating templates
will
Code:
if (0)
do stuff a;
else
do stuff b;
compile to
?
also, as this is in a template, will the instance have to support functions specified in "do stuff b", in case 0 is evaluated above, as a result of the template parameters, by calling an inline function on them, say:
Code:
if (GetVal())
do stuff a;
else
do stuff b;
for:
Code:
template <class x, class y>
class Stick{
public:
inline bool GetVal(){return a.GetVal() || b.GetVal();}
.
.
.
private:
x a;
y b;
}
Stick template is used recursively, upto about 8 times, but will that be a problem for inlining?
Not that kind of recursion
I was thinking more like template recursion:
Stick<a,Stick<b,Stick<c> > >
I saw an article on flipcode.com which mentioned three pragma's you could add to prevent VC++ to get fussy about inlining, but would this form of recursion prevent it?
The thing is that i can't put precompiler #ifdefs to determine what the instances should contain, but they are templates right, and they don't instantiate what isn't unneeded? The problem I have is that for a class to be a valid template parameter, it has to have the methods used on it in the template, but i have methods both in "do stuff a" and "do stuff b" that should not be together in the same instance. Will the compiler be smart enough to remove the code of either a or b and not complain about the class parameter not fitting the way it is used?