I would say that the direct solution to this question might be this:
template< typename T, T X, T L, T H>
using inside_t =
std::enable_if_t< (X <= H) && (X >= L),
std::integral_constant<T, X> >;
Applied to the OP:
template<typename C, unsigned K> struct X; // final {};
template<unsigned K>
struct X<char, K> final
{
using ascii_ordinal = inside_t<unsigned, K, 0, 127>;
char value = char(ascii_ordinal::value);
};
Which renders really terrible CL error messages when it does the job:
X<char, 300> a; //here 300 is out of range and I would like to be able to detect that.
While much less snazzy but most comfortable API might be:
template<unsigned K>
struct X<char, K> final
{
static_assert( K >= 0U && K <= 127U, "\n\nTeribly sorry, but value must be between 0 and 127 inclusive\n\n") ;
char value = char(K);
};