#include <algorithm>
#include <iostream>
#include <iterator>

struct triple_t
{
	unsigned x;
	unsigned y;
	unsigned z;
};

std::ostream & operator<<(std::ostream & out, triple_t const & triple)
{
	return out << triple.x << ", " << triple.y << ", " << triple.z;
}

class triple_iterator_t : public std::iterator<std::forward_iterator_tag, triple_t>
{
private:
	triple_t triple_;

	static triple_t next(unsigned x, unsigned y, unsigned z)
	{
		while (true)
		{
			if (y == z)
			{
				if (x == z)
				{
					++z;
					x = 1;
				}
				else ++x;
				y = x;
			}
			else ++y;

			if (x * x + y * y == z * z) return {x, y, z};
		}
	}

public:
	triple_iterator_t() : triple_{1, 1, 1}
	{
		++(*this);
	}

	triple_t operator *()
	{
		return triple_;
	}

	triple_iterator_t & operator ++()
	{
		triple_ = next(triple_.x, triple_.y, triple_.z);
		return *this;
	}
};

int main()
{
	copy_n(triple_iterator_t(), 10, std::ostream_iterator<triple_t>(std::cout, "\n"));
}