Optimizations are compiler specific. Why don't you build and disassemble?
However, this is not an idiomatic way to do this. You must either use specialized specialization or method overloading. They both provide a solution at compile time. So, in this case, I would prefer the latter:
#include <type_traits> template <bool flag> class foo { public: int bar() { _bar(std::integral_constant<bool, flag>()) } private: int _bar(std::true_type) { // stuff } int _bar(std::false_type) { // empty } };
EDIT: this requires C ++ 0x, but it can easily be converted to C ++ 98 by turning on boost/type_traits and changing the directives std:: to boost:: . And, of course, accelerator libraries will be required for this.
source share