0

Suppose we create the following function:

template <int T>
void test_function()
{
    if (T == 0) {

    }
}

Now let's use test_function<1>(). Is there a standard behavior for its compilation? Will compilers interpret test_function as an empty function, or will the comparison 1 == 0 always be made at run-time?

Litty
  • 1,856
  • 1
  • 16
  • 35
  • 3
    Uh, this doesn't look like valid C++... – Brian Bi Dec 30 '14 at 21:34
  • You are absolutely correct. I've edited my question and successfully compiled it -- as I should have done the first time. – Litty Dec 30 '14 at 21:39
  • duplicate of [this](http://stackoverflow.com/questions/6174764/template-code-optimization-for-specific-values-of-non-type-parameters?rq=1) and [this](http://stackoverflow.com/questions/12030497/c-use-templates-to-avoid-compiler-from-checking-a-boolean) and many others like [this also](http://stackoverflow.com/questions/23970532/what-do-compilers-do-with-compile-time-branching) – Piotr Skotnicki Dec 30 '14 at 21:39
  • Compiler could be able to optimize that. – Jarod42 Dec 30 '14 at 21:42
  • This was a difficult question to search, these are indeed duplicates. I would be comfortable with closing this question. – Litty Dec 30 '14 at 21:43

0 Answers0