I have watched a talk on cppcon here where the guy talks about modules. The talk was in 2021, so I figured such an important and long awaited language feature should be implemented by the 3 large compilers already (gcc, clang and msvc).
So I wrote a test program as such
import std;
auto main() -> int
{
using std::cout;
cout << "Hello world!\n";
return 0;
}
However, no matter what I do, I can't make it compile. I tried import iostream;
, import <iostream>;
, import std.cout;
, import std::cout;
, etc.
I use the very latest version of the compilers available on my system (Ubuntu 22.04), which are gcc version 12 and clang version 17 respectively. I compile with -std=c++23 -Wall -Wextra -Wpedantic -O0 -g modules.cpp -o modules
But g++ complains
import does not name a type
and clang gives me
module 'std' is not found
The error is of course on line 1. I tried using the example from the talk, in the hopes that somehow code written after the error would clear the error through some magic, but of course that didn't happen.
So what is going on here? How can that guy compile that code in 2021, but I can't compile that same code in 2023 with compilers released after 2021?
Why do we "have" module support, but they don't work? How can this guy tell thousands of people with a straight face that something works when it doesn't and hadn't for the next 2 years either?
Edit
I have seen this other question, which is why I included my example of import iostream;
, which also didn't work, but was the accepted answer in that other question.