#include of a HTTP URL in C++

#include of a HTTP URL in C++

本文关键字:in C++ URL HTTP of #include      更新时间:2023-10-16

我正在Github(https://github.com/Quuxplusone/coro/blob/master/examples/pythagorean_triples_generator.cpp(上查看一个随机C++示例,并惊讶地发现它实际上可以编译(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)
);
}
}

这是一个新的 C++20 功能,还是 Godbolt 的扩展,或者完全是别的什么?

这是godbolt.org 的一个功能。见 https://github.com/mattgodbolt/compiler-explorer/wiki/FAQ

:是否可以包含来自 URL 的文件?

:编译器资源管理器能够将原始文本包含在您的 来源,通过滥用#include指令。

#include <url_to_text_to_include>
...

(请参阅此链接的实时示例:https://godbolt.org/z/Pv0K0c(

请注意,URL 必须允许跨域请求,以便 工作。

据我所知,处理#include指令中"<"和">"字符对之间的标记的方式完全是(?(实现定义的。

从 [cpp.include]/2 (强调我的(...

表单的预处理指令

# include < h-char-sequence > new-line

在一系列实现定义的位置中搜索标头 由<和>分隔符之间的指定序列唯一标识,并导致该指令被整个 标头的内容。如何指定地点或标题 标识是实现定义的

话虽如此,这是我以前从未遇到过的事情。