fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <functional>
  4.  
  5. template< class T, class U >
  6. std::vector<U> operator>>=( std::vector<T> val, std::function<std::vector<U>(T)> f )
  7. {
  8. std::vector<U> res;
  9. for( auto x: val )
  10. {
  11. std::vector<U> subs = f( x );
  12. for ( auto y: subs )
  13. {
  14. res.push_back( y );
  15. };
  16. };
  17. return res;
  18. };
  19.  
  20. std::vector<int> genarray( int n )
  21. {
  22. std::vector<int> res;
  23. for ( int i = 1; i <= n; i++ )
  24. res.push_back( i );
  25. return res;
  26. };
  27.  
  28. template< class T >
  29. struct mpair
  30. {
  31. T a, b;
  32. mpair( T na, T nb ): a(na), b(nb) {};
  33. };
  34.  
  35. std::vector<mpair<int>> example( int n )
  36. {
  37. return genarray( n ) >>= std::function<std::vector<mpair<int>>(int)>( [&](int a){ return genarray(a) >>= std::function<std::vector<mpair<int>>(int)>([&](int b) { return std::vector<mpair<int>>{ mpair<int>(a,b), mpair<int>(b,a) }; } ); } );
  38. };
  39.  
  40. int main()
  41. {
  42. auto r = example( 3 );
  43. for ( auto x: r )
  44. std::cout << "(" << x.a << "," << x.b << ")";
  45. };
Success #stdin #stdout 0s 3276KB
stdin
Standard input is empty
stdout
(1,1)(1,1)(2,1)(1,2)(2,2)(2,2)(3,1)(1,3)(3,2)(2,3)(3,3)(3,3)