fork download
  1. #include <iostream>
  2.  
  3. struct my_cout_t {
  4. template <typename T>
  5. my_cout_t& write(T const& t) {
  6. do_write(std::cout, t);
  7. return *this;
  8. }
  9. };
  10.  
  11. struct foo {};
  12. struct bar {};
  13.  
  14. void do_write(std::ostream& os, foo const&) {
  15. os << "yay!\n";
  16. }
  17. void do_write(std::ostream& os, bar const&) {
  18. os << "works!\n";
  19. }
  20.  
  21. my_cout_t cout;
  22.  
  23. int main() {
  24. cout.write(foo())
  25. .write(bar());
  26. }
Success #stdin #stdout 0.02s 2680KB
stdin
Standard input is empty
stdout
yay!
works!