There is a difference between a 'constant' and a 'constant expression'
A constant expression NEEDS to be known at compile time. So your code is invalid because it relies on a parameter len that is only determined at run time. Whenever you use a template, the compiler manually inserts the constant expression during compilation, therefore it needs to know what value the size of std::array is when it goes to insert it.
If it were like this:
1 2
constint len = 5;
std::array<int, len> myarr;
This would be valid, since len is now a constant expression known at compile time. Since C++11, we have the constexpr keyword that can be used exclusively for constant expressions and regular constants won't work, so this is equivalent:
1 2 3 4 5
constexprint len = 5;
std::array<int, len> myarr; //Works
constint len2; //Is constant, but not a compile-time constant
constexprint len3; //ERROR: Constexpr must have value at compile time!
As mbozzi said, function parameters are never constant expressions, but nontype template parameters ALWAYS must be constant expressions (with certain type restrictions)