Yes. All template parameters need to be known at compile time (anything else will result in a compiler error).
The reason for this is that technically speaking, mysequence<int, 1>
and mysequence<int, 2>
are completely separate types, generated by the compiler. If the compiler has never seen your N
before, how could it generate the types for you?
The fact that the compiler needs to generate each of those types separately is also what forces you to implement templates in the header. Determining parameters at runtime would obviously be even harder to do (you would need to dynamically recompile your code!).
Here is what the C++ standard has to say about template parameters (that are not types):
A template-argument for a non-type template-parameter shall be a converted constant expression of the type of the template-parameter
[temp.arg.nontype]/2
Now what is a converted constant expression?
A converted constant expression of type T is an expression, implicitly converted to type T, where the converted expression is a constant expression
[some restrictions on the conversions that may be applied follow]
[expr.const]/5
So really, it's just a constant expression with some conversions added. The rules for what exactly is a constant expression are somewhat complex ([expr.const]/2), but the standard has a simple summary:
Expressions that satisfy these requirements, assuming that copy elision is performed, are called constant expressions.
[ Note: Constant expressions can be evaluated during translation. — end note ]
[expr.const]/1
Evaluated during translation is a fancy term for "the compiler can do it while compiling."
Therefore, non-type template parameters must be known at compile time (and so do type template parameters, although it is harder to construct a scenario where you would want to set type template parameters at runtime)