Skip to content

[C++20] [Modules] [std module] Implicitly import std if standard library header is included #138906

Open
@apolukhin

Description

@apolukhin

What do you think about the following idea: add a preprocessor macro that replaces content of the header with import std; if the macro is defined by user.

For example libcxx/include/vector can be changed in the following way:

#ifndef _LIBCPP_VECTOR
#define _LIBCPP_VECTOR

#if defined(LIBCPP_IMPLICIT_MODULES_USE)
import std;
#  include <version>
#else

...  // all the remaining code from <vector>

#endif // LIBCPP_IMPLICIT_MODULES_USE

#endif // _LIBCPP_VECTOR

Motivation:

  1. Implicit import std; in standard library header would improve compile times if module std is available.
  2. Migration from includes to import std; for big projects is not trivial. The above approach eases that migration
  3. It's a possible alternative solution to [C++23] [Modules] [std module] Skip including standard headers if the std module is imported #80663

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:modulesC++20 modules and Clang Header Moduleslibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions