fork download
  1. #include <iostream>
  2. #include <type_traits>
  3.  
  4. template <class T>
  5. struct serialize_helper {
  6. static void apply(T const&) { std::cout << "apply<T>" << std::endl; }
  7. };
  8.  
  9. template <>
  10. struct serialize_helper<std::string> {
  11. static void apply(std::string const&) { std::cout << "apply<std::string>" << std::endl; }
  12. };
  13.  
  14. template <class T, typename std::enable_if<std::is_pointer<T>::value>::type* = nullptr>
  15. inline void serializer(const T& obj) {
  16. serialize_helper<typename std::remove_pointer<T>::type>::apply(*obj);
  17. }
  18.  
  19. template <class T, typename std::enable_if<!std::is_pointer<T>::value>::type* = nullptr>
  20. inline void serializer(const T& obj) {
  21. serialize_helper<T>::apply(obj);
  22. }
  23.  
  24. int main() {
  25. std::string s = "Hello";
  26. std::string* p = new std::string("Hellp");
  27.  
  28. serializer(s);
  29. serializer(p);
  30.  
  31. delete p;
  32. return 0;
  33. }
Success #stdin #stdout 0s 3228KB
stdin
Standard input is empty
stdout
apply<std::string>
apply<std::string>