Joh*_*itb 9 c++ c++11 c++17 c++20 compiler-explorer
我在 Github 上查看了一个随机 C++ 示例(https://github.com/Quuxplusone/coro/blob/master/examples/pythagorean_triples_generator.cpp),并惊讶地发现它实际上可以编译(https://coro.cpp)。 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)
);
}
}
Run Code Online (Sandbox Code Playgroud)
这是 C++20 的新功能,还是 Godbolt 的扩展,或者完全是其他东西?
这是 godbolt.org 的一个功能。请参阅https://github.com/mattgodbolt/compiler-explorer/wiki/FAQ
问:我可以包含来自 url 的文件吗?
答:编译器资源管理器能够通过滥用
#include指令将原始文本包含到您的源代码中。Run Code Online (Sandbox Code Playgroud)#include <url_to_text_to_include> ...(请参阅此链接的实例:https ://godbolt.org/z/Pv0K0c )
请注意,URL 必须允许跨域请求才能正常工作。
| 归档时间: |
|
| 查看次数: |
1794 次 |
| 最近记录: |