Jer*_*rry 6 c++ clang c++20 c++-coroutine
我正在尝试编译一个 .cpp 文件,该文件将coroutine库与命令一起使用。
clang-11 -std=c++20 -stdlib=libstdc++ main.cpp
Run Code Online (Sandbox Code Playgroud)
我收到这样的错误:
/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/coroutine:295:2: error: "the coroutine header requires -fcoroutines"
#error "the coroutine header requires -fcoroutines"
Run Code Online (Sandbox Code Playgroud)
所以,我添加了标志:
clang-11 -std=c++20 -stdlib=libstdc++ main.cpp -fcoroutines
Run Code Online (Sandbox Code Playgroud)
现在,我收到错误:
clang-11: error: unknown argument: '-fcoroutines'
Run Code Online (Sandbox Code Playgroud)
这是一个错误吗?
最接近的问题是here。但是,我无法断定是否存在错误。
对于它的价值,这里是来源:
#include <iostream>
#include <coroutine>
template<typename T>
bool is_prime(T number) {
for(int i=2;i<number;i++) {
if (not i%number) return true;
}
return false;
}
class prime_iterator {
unsigned int number = 2;
public:
auto operator*() const {
return number;
}
prime_iterator& operator++() {
++number;
if (not is_prime(number)) {
co_yield number; // Trying to invoke co_yield just to see if library works.
}
return *this;
}
};
auto main() -> int {
for(prime_iterator p; *p < 30; ++p) {
std::cout << *p << " is prime";
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1089 次 |
| 最近记录: |