#include of a HTTP URL in C++
#include of a HTTP URL in C++
我正在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
在一系列实现定义的位置中搜索标头 由<和>分隔符之间的指定序列唯一标识,并导致该指令被整个 标头的内容。如何指定地点或标题 标识是实现定义的。和>
话虽如此,这是我以前从未遇到过的事情。
相关文章:
- netcat command in c++
- Difference in displaying cv2 Mat
- C++ MFC Libraries in Travis CI
- 如何在OpenSSL中从configuration.h.in获取configuration.h
- 创建具有 new in 函数和"this is nullptr"异常的对象
- IN, OUT, INOUT Parameters
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- 有人安装"IITB Simplecpp in mac"吗?
- 从 C 样式字符串中删除子字符串 "in place" 在C++代码中
- 如何修复"error: ‘_1’ was not declared in this scope"?
- Softmax Implementation in C++
- 将 out/in out 参数与 if/switch 的 init 语句一起使用
- IF-nesting in c++
- Gurobi GRBModel and GRBmodel in C++
- Tensorflow Hub in C++
- Centos7 g++ "to_string is not in a member of std"
- InitializeCriticalSectionEx Not Located In KERNEL32.Dll
- 将 lambda 表达式传递给 std::function in C++
- @CPPFLAGS@在 Makefile.in 中意味着什么?
- std::async from std::async in windows xp