I was looking at a random C++ example on Github ( https://github.com/Quuxplusone/coro/blob/master/examples/pythagorean_triples_generator.cpp ), and was surprised to see that it actually compiles ( https://coro.godbolt.org/z/JXTX4Y ).
#include <https://raw.githubusercontent.com/Quuxplusone/coro/master/include/coro/shared_generator.h>
#include <stdio.h>
#include <tuple>
#include <range/v3/view/take.hpp>
namespace rv = ranges::view;
auto triples() -> shared_generator<std::tuple<int, int, int>> {
for (int z = 1; true; ++z) {
for (int x = 1; x < z; ++x) {
for (int y = x; y < z; ++y) {
if (x*x + y*y == z*z) {
co_yield std::make_tuple(x, y, z);
}
}
}
}
}
int main() {
for (auto&& triple : triples() | rv::take(10)) {
printf(
"(%d,%d,%d)\n",
std::get<0>(triple),
std::get<1>(triple),
std::get<2>(triple)
);
}
}
Is this a new C++20 feature, or an extension on Godbolt, or something entirely else?