<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/138906>138906</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[C++20] [Modules] [std module] Implicitly import std if standard library header is included
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
apolukhin
</td>
</tr>
</table>
<pre>
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 https://github.com/llvm/llvm-project/issues/80663
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVM2OqzYUfhqzOSpyDCFhwSKZmUiRJrqj3rntcmTwIZxeYyPbMJO3rwyktz_TLipFiuDgz9-fLb2nq0Gs2PbIto-JHENnXSUHq8fvHZmktupW_drJAMrCzY4QOjLfQdZ2DBA6hNZqbd_JXIEUSpYdQCoFEgaHg7MNem8d9LJxFkKEcTho2aCHxpqAJoBtZ5wOpUIH7xQ6YAWnfrAugA-KZUdWcKDlswWJPChsyaCC-gajR5cyfmD8cLIO8EP2g0bQVDcfH0ycyDR6VMjEacImWAeNNFAjNJ00V1RA5m9K3uWNZRGOFXz98QMTGbVGYQtvz-fjw8vL2y9PD69ffl5GC51PRuvCO18m9usn58vL8_nh_Pp2-fL47fnp69u3r09MlIwf_qp9BoBVA7DsYULnyRqWPS0z1B6XndI0BWDixMQJpNazKoe9JBNVNVYhtM72C0h0YsVYYIyi9r76vzh-uuCfwv9sHT9cbKBJhpl3fN6kcO4HTQ2Fz-M24IM0SjoVg3TS3f6oiB21AuoHZyeExvYDaYRAPfrYkt6qUWOEijWRkyQta42xICKFC13dTGNxYrXVQ7Cf0mitg5quMDj7GzbBR0hjAwRHE0mdwmuH8TBMCHIYnJVNByh9BIxl7--7MX7IUjgHJnY-Hg7rPdUaQeqAzshAE4K3epyZBQtdCIOPTs3uXil0Y502tmfipPV0__tppRU77v2InonTnhdFlqgqU2VWygSrzS4vimwrijLpqlw1rVSbXJS7rFTlvt5gnuUoeb7b7POdSqgSXGz5lu82hdjlZcr3bSOLXZarbZnnvGA5j43SaSSQWndN5q2rTbYveZFoWaP283UihMF3mKdMiHi7uGpmXY9Xz3KuyQf_AyZQ0PM99MDEkYmj4Gz7CGx7vMyB-vUp5rpEHF_cO6Rv8CO72IJ_Kw_5e-YqGZ2u_r_Rq-CpEr8HAAD__1KKtEw">