#include <iostream>
#include <vector>
#include <functional>

template< class T, class U >
std::vector<U> operator>>=( std::vector<T> val, std::function<std::vector<U>(T)> f )
{
	std::vector<U> res;
	for( auto x: val )
	{
		std::vector<U> subs = f( x );
		for ( auto y: subs )
		{
			res.push_back( y );
		};
	};
	return res; 
};

std::vector<int> genarray( int n )
{
	std::vector<int> res;
	for ( int i = 1; i <= n; i++ )
		res.push_back( i );
	return res;
};

template< class T >
struct mpair
{
	T a, b;
	mpair( T na, T nb ): a(na), b(nb) {};
};
                
std::vector<mpair<int>> example( int n )
{
	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) }; } ); } );
};

int main()
{
	auto r = example( 3 );
	for ( auto x: r )
		std::cout << "(" << x.a << "," << x.b << ")";
};