samedi 21 novembre 2020

Assert that type is unsigned integer or enum type with maximal size

I'm trying to make it possible to write the following to statically assert that a variables type is an unsigned integer with size less than or equal to four bytes.

I started with the following:

template<typename T>
using is_uint_le32_t = std::integral_constant<
  bool,
  std::is_integral<T>::value
  && std::is_unsigned<T>::value
  && sizeof(T) <= sizeof(uint32_t)>;

So that I can write static_assert(is_uint_le32_t<T>).

However, I would like this alias template to also evalue to true when T is an enum type whose underlying type satisfies is_uint_le32_t and I don't know how to do that.

Aucun commentaire:

Enregistrer un commentaire