fork download
  1. #include <iostream>
  2. #include <stdexcept>
  3.  
  4. namespace documentation {
  5. struct Page {
  6. char const * text;
  7. };
  8.  
  9. // Print at printer, costs hundreds of dollars because it's an awesome printer
  10. void print(Page const &) {
  11. throw std::logic_error{"WTF! Who turned on the printer!?!"};
  12. }
  13.  
  14. // Write on screen
  15. std::ostream & operator<<(std::ostream & s, Page const & p) {
  16. return (s << p.text);
  17. }
  18. }
  19.  
  20. namespace IO {
  21.  
  22. template <typename T>
  23. void print(const T& input)
  24. {
  25. std::cout << input << ' ';
  26. }
  27.  
  28.  
  29. template <typename T, typename... Types>
  30. void print(const T& firstArg, const Types&... arguments)
  31. {
  32. std::cout << firstArg << ' ';
  33. print(arguments...);
  34. }
  35. }
  36.  
  37.  
  38. int main() {
  39. try {
  40. documentation::Page p {"Some nice text"};
  41. IO::print("Introduction: ", p);
  42. } catch (std::exception const & e) {
  43. std::cout << "ERROR: " << e.what() << std::endl;
  44. }
  45. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Introduction:  ERROR: WTF! Who turned on the printer!?!