Let's say this the bare bone for a non zero-able type.
template<typename T>
struct NonZero {
T val;
};
My question is if it's possible to make a constructor for NonZero
which to take a literal of type T
and statically check if it's non-zero and then assigns it to val
.
NonZero<int> n( 0 ); // compilation error
NonZero<int> n( 1 ); // ok
Or is there a better way to archieve a non zero type?