fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. #define TEST1 (0)
  5. #define TEST2 (0)
  6.  
  7. #if TEST1
  8. #include <iomanip>
  9. #endif
  10.  
  11. template<class T>
  12. class Unko
  13. {
  14. public:
  15. Unko(ostream& (*f)(ostream&, T), T i) : func(f), value(i) { }
  16. #if TEST2
  17. template<class T2>
  18. friend ostream& operator<< (ostream&, const Unko<T2>&);
  19. private:
  20. #endif
  21. T value;
  22. ostream& (*func)(ostream&, T);
  23. };
  24.  
  25. template <class T>
  26. ostream& operator<< (ostream& o, const Unko<T>& u) {
  27. return (*u.func)(o, u.value);
  28. }
  29.  
  30. ostream& unkounko(ostream& o, int i) {
  31. #if TEST1
  32. return o << setfill('0') << setw(10) << hex << (i * 2)
  33. << dec << setfill(' ');
  34. #else
  35. o.width(10);
  36. o.fill('0');
  37. o.setf(o.hex, o.basefield);
  38. o << (i * 2);
  39. o.fill(' ');
  40. o.unsetf(o.basefield);
  41. return o;
  42. #endif
  43. }
  44.  
  45. ostream& gerigeri(ostream& o, int i) {
  46. return o << '(' << i << ')';
  47. }
  48.  
  49. inline Unko<int> unko(int i) {
  50. return Unko<int>(unkounko, i);
  51. }
  52.  
  53. inline Unko<int> geri(int i) {
  54. return Unko<int>(gerigeri, i);
  55. }
  56.  
  57. ostream& abc(ostream& o) {
  58. return o << "abc";
  59. }
  60.  
  61. int main() {
  62.  
  63. cout << abc << unko(123) << geri(345) << abc;
  64.  
  65. return 0;
  66. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
abc00000000f6(345)abc