dimanche 28 juillet 2019

Return type agnostic template class member function

I have a class like:

tempate<class TReturn>
struct MyClass {
 template<class T>
 TReturn doSomething(const T &t) {
  // Do something
  return someValue;
 }
};

Now TReturn can be anything even void but in case it is void I want no return statement at the end and some minor different code in the function. What I want is a different function body depending on the return type. I'm using C++11 so if constexpr is not possible for me. Is there any way to to this in plain C++11?

Aucun commentaire:

Enregistrer un commentaire