C++23 now provides std module

https://en.cppreference.com/w/cpp/standard_library#Importing_modules

I just noticed this.

So one can now do:

module.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import  std;  //everything in std namespace is in here
//import <iostream>; // don't need these anymore
//import <vector>;
//import <string>;

//import <string_view>;

int main() {
    std::cout << "Hello Modular World!\n";

    const std::vector<std::string_view> words {"Welcome ", "Modular ", "Vector ", "With ", "auto&& "};
    for (auto&& word: words) {
        std::cout << word;
    }
    std::cout<< "\n";

}



And compile with:

clang++ -std=c++2b -Wall -Wextra -stdlib=libc++ -fmodules -fbuiltin-module-map module.cpp -o modexe

I tried to do something similar with g++, but it seems it still wants to have precompiled gcm files.

Also:
https://itnext.io/c-20-modules-complete-guide-ae741ddbae3d
Last edited on
MSVC has a similar feature that was available with VS 2019 and 2022, import std.core; that required /std:c++latest and /experimental:module.

Nice to see other compilers and the C++ ISO committee are getting around to enabling modules finally as well as logically.

Doing individual module imports didn't require experimental module support enabled and would work with /std:c++20.

To use the C++23 module import requires VS 2022 17.5 or later. Which I believe is still in preview status. I have 17.4.2 as the current public release.modules.
Topic archived. No new replies allowed.