문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top