the following code just compile with "jthread not in std". with clang 18
clang++ -std=c++26 -stdlib=libc++
and the implementation of jthread is in __thread/jthread.h, but for some reason macro out. why?
#include <thread>
using namespace std::chrono_literals;
int main() {
std::jthread t([] { std::this_thread::sleep_for(1s); });
}
The libc++ documentation has a webpage about C++20 status of libc++. Quoting the relevant footnote 8:
P0660: The paper is implemented but the features are experimental and can be enabled via
-fexperimental-library
.
Thus, just pass that flag mentioned above when compiling with Clang 18 or newer, like this:
clang++ -std=c++26 -stdlib=libc++ -fexperimental-library