4 ms·
This can already be done using Linq in C++, which is range-based rather than iterator based: auto q = LINQ( from(z, boost::irange(1, std::n
by pfultz2 12y ago
This can already be done using Linq in C++, which is range-based rather than iterator based:
auto q = LINQ(
from(z, boost::irange(1, std::numerical_limits<int>::max()))
from(x, boost::irange(1, z))
from(y, boost::irange(1, x))
where(x*x + y*y == z*z)
select(boost::fusion::make_vector(x, y, z))
);
for(auto&& x:q | linq::take(10)) std::cout << x << std::endl;
Hopefully, once we get ranges in the C++ standard library, we can add list comprehension to the language, perhaps something like this:
auto q = [
for (z, std::irange(1, std::numerical_limits<int>::max()))
for (x, std::irange(1, z))
for (y, std::irange(1, x))
if (x*x + y*y == z*z)
boost::fusion::make_vector(x, y, z)
];
for(auto&& x:q | std::take(10)) std::cout << x << std::endl;
- deleted 12y ago[deleted]