samedi 30 juillet 2016

static constexpr member storage

If I write a trait like this,

template <typename T>
struct is_int {
  static constexpr bool value = false;
};

template <>
struct is_int<int> {
  static constexpr bool value = true;
};

Is the value actually stored in memory when the program runs? For example, if I use this trait on a million different types, does the program use 1 MB of memory to store these values?

To paraphrase, is there still any advantage to using

template <typename T>
struct is_int {
  enum { value = 0; }
};

template <>
struct is_int<int> {
  enum { value = 1; }
};

Aucun commentaire:

Enregistrer un commentaire