fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template<char... s>
  5. struct PrintChars;
  6.  
  7. template<char head, char... tail>
  8. struct PrintChars<head, tail...> { char h = head; PrintChars<tail...> t; };
  9.  
  10. template<>
  11. struct PrintChars<> { char h = '\0'; };
  12.  
  13. /*
  14. std::ostream& operator<< (std::ostream& o, const PrintChars<>&)
  15. {
  16. return o;
  17. }
  18.  
  19. template<char head, char... tail>
  20. std::ostream& operator<< (std::ostream& o, const PrintChars<head, tail...>& pc)
  21. {
  22. o << head << PrintChars<tail...>();
  23. return o;
  24. }
  25. */
  26.  
  27. template<char... s>
  28. std::ostream& operator<< (std::ostream& o, const PrintChars<s...>& pc)
  29. {
  30. const char* str = &(pc.h);
  31. o << str;
  32. return o;
  33. }
  34.  
  35. int main() {
  36. cout << PrintChars<'f','o','o'>();
  37. return 0;
  38. }
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
foo