jeudi 28 mai 2015

Distinguishing structs with type traits

Is there a way to distinguish a struct which has a std::vector<T> from any other type?

I have some template functions which should be specialized if T is a struct that contains a std::vector<T> so what I'm looking for is:

template<typename T> method(const T& object)
{
  static_assert(!contains_vector<T>::value, "This method must be specialized");
  // implementation
}

so that

struct Foo {
  uint32_t foo;
  float bar;
};

struct Bar {
  uint16_t foo;
  vector<float> bar;
}

contains_vector<float>::value == false;
contains_vector<Foo>::value == false;
contains_vector<Bar>::value == true;

I was trying to figure out how could I distinguish through <type_traits> this difference.

Aucun commentaire:

Enregistrer un commentaire