Stack Overflow Asked by Jerry Ajay on January 18, 2021
I’m trying to compile a .cpp file that uses the coroutine
library with the command.
clang-11 -std=c++20 -stdlib=libstdc++ main.cpp
I get an error like this:
/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"
So, I add the flag:
clang-11 -std=c++20 -stdlib=libstdc++ main.cpp -fcoroutines
Now, I get the error:
clang-11: error: unknown argument: '-fcoroutines'
Is this a bug?
The closest question is here. However, I wasn’t able to conclude whether a bug exists or not.
For what its worth, here’s the source:
#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";
}
}
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP