fork download
  1. #include <iostream>
  2.  
  3. template <typename stream, typename type> void serialize(stream&, type&)
  4. {
  5. std::cout << "Came to 1\n";
  6. }
  7.  
  8. struct stream
  9. {
  10. void serialize(int ) {}
  11. };
  12.  
  13. // struct foo
  14. struct foo {
  15. int bar;
  16. };
  17.  
  18. // serialize foo
  19. template <class stream> void serialize(stream& s, foo& f) {
  20. std::cout << "Came to 2\n";
  21. s.serialize(f.bar);
  22. }
  23.  
  24. struct bar {
  25. };
  26.  
  27. int main()
  28. {
  29. // ...later in source file:
  30. foo f;
  31. stream s;
  32. serialize(s, f);
  33. bar b;
  34. serialize(s, b);
  35. }
  36.  
  37.  
Success #stdin #stdout 0s 4544KB
stdin
Standard input is empty
stdout
Came to 2
Came to 1