Non-type template parameters

I've never liked generics much, and C++ templates even less. I'm glad that Java 1.5 generics won't allow non-type parameters, despite being a C++ programmer by profession. Or perhaps because of my daily exposure to C++ templates.

It's not that I never paint myself into corners – or get painted into them by others while my back's turned – where the only ways out are duplication or a template, and I'm often glad of templates then. But I've yet to see a non-type parameter I didn't think was a mistake. I hate having my hands tied, and having to make a decision at compile-time... that's just offensive. I can feel the metal biting into my wrists.

I came across an interesting example today, where a collection class used an int template parameter as its fixed size rather than using a constructor parameter for this purpose (I wanted a fixed-size collection; those handcuffs were for security... and fun). Anyway, it turned out that being unable to make a small improvement to some code by using a size that was a run-time rather than compile-time constant was a good thing, because it's encouraged me to make a bigger improvement and go for a self-sizing container instead.

So you see, sometimes two wrongs (a magic number and an int template parameter) do make a right (a self-sizing collection).