mercredi 6 février 2019

How to create compile time check for multiple C++ types?

I have a template <class Class> generic function that includes:

std::ostringsteam objectStream;

objectStream << std::forward<Class>(object);

return objectStream.str();

For efficiency, I wish to optimize the case of Class strings.

Therefore, I'm doing tags dispatch on templates for overloading the template function per item 27 is Scott Myers' Effective Modern C++ book.

Therefore I need to generate at compile time either a std::true_type or std::false_type.

Given a template<class Class>, I need a std::true_type if any of these expressions are true:

std::is_same<typename std::decay<Class>::type, char * >()
std::is_same<typename std::decay<Class>::type, const char * >()
std::is_same<typename std::decay<Class>::type, string >()
std::is_same<typename std::decay<Class>::type, const string >()

I'm not sure how to do the OR so the compiler can dispatch on the tags at compile time correctly.

Aucun commentaire:

Enregistrer un commentaire