Question

Why does the C++ allow specialization of a type for both true and false parameters?

template<bool> struct omg { /* can't access anything declared here */ };
template<> struct omg<true> { };
template<> struct omg<false> { };

Is there any situation in which this is meaningful/useful?

Was it helpful?

Solution

I think, there is no such situation. But standard have no any restricts to template non-type parameters, that are suitable to conditions. By the way, it such restriction were, it should be for all types. It will not be correct to do something like

enum A { first, second };

template<A> struct omg {};
template<> struct omg<first> {};
template<> struct omg<second> {};

and this is too complicated, IMHO.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top