gpt4 book ai didi

c++ - C++ 中 HTTP URL 的 #include

转载 作者:行者123 更新时间:2023-12-02 07:14:39 25 4
gpt4 key购买 nike

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

Q: Can I include a file from an url?

A: Compiler Explorer has the ability to include raw text to your source, by abusing the #include directive.

#include <url_to_text_to_include>
...

(See this link a live example: https://godbolt.org/z/Pv0K0c)

Note that the URL has to allow for cross domain requests for this to work.

关于c++ - C++ 中 HTTP URL 的 #include,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59515261/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com