fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <cctype>
  4.  
  5. class toogle_t
  6. {};
  7. constexpr toogle_t toogle;
  8. struct toogled_ostream
  9. {
  10. std::ostream& os;
  11. };
  12.  
  13. inline toogled_ostream operator << (std::ostream& os, toogle_t)
  14. {
  15. return { os };
  16. }
  17.  
  18. template <typename T>
  19. std::ostream& operator << (toogled_ostream tos, const T& v)
  20. {
  21. return tos.os << v;
  22. }
  23. std::ostream& operator << (toogled_ostream tos, char v)
  24. {
  25. char c = std::isupper(v) ? std::tolower(v)
  26. : std::islower(v) ? std::toupper(v) : v;
  27. return tos.os << c;
  28. }
  29.  
  30.  
  31.  
  32.  
  33.  
  34. int main() {
  35. std::cout << toogle << 'a' << 'A';
  36. // your code goes here
  37. return 0;
  38. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
AA