I have a function with a non-type template parameter of type int
, like so:
template <int N>
int foo() { /*...*/ }
I would like to unit test this function for all values of N
from 0 to 32. I have a function int expected(int n)
that takes the same N
value and returns the expected value. Effectively, I want:
if (foo<0>() != expected(0)) { /* fail... */ }
if (foo<1>() != expected(1)) { /* fail... */ }
if (foo<2>() != expected(2)) { /* fail... */ }
// 30 more lines
I don't want to write out all 33 test cases by hand, and I can't easily use a runtime loop because N
is compile time.
How can I get the compiler to generate the test cases for me in a simple way, without BOOST_PP_REPEAT
-style tricks or code generation, in C++11?