C++ Logo


Advanced search

Re: [isocpp-ext] How to provide functionality as both header file and module?

From: 许传奇(夜灯) <"许传奇>
Date: Wed, 25 May 2022 13:57:48 +0800
Hi Nicolai,

   I think the header unit might be wanted. It allows us to import headers just like modules:
import <iostream>

   If we want named modules, we could use the following tricks:
#include "headers"
export module named_module;
export the things we want to export;

   In this form, we need to write additional code but we avoid double-written.


From:Nicolai Josuttis via Ext <ext_at_[hidden]rg>
Send Time:2022 May 25 (Wed.) 13:19
To:C++ EWG Reflector <ext_at_[hidden]>; WG21 Tooling Study Group SG15 <sg15_at_[hidden]>
Cc:Nicolai Josuttis <nico_at_josuttis.de>
Subject:[isocpp-ext] How to provide functionality as both header file and module?

I need your help.
One of my customers wants to start using modules.
 So far, they use traditional header files, which should now step-by-step become modules.
However, their code is not necessarily only used within projects that use a build system.
 It is a little piece of functionality useful in all kinds of programs (a key attribute of header files today).
Initially, I told the customer that AFAIK modules can be used everywhere.
 But I learned that Microsoft decided to require using a build system when using modules.
 And I learned here that this is intentional and OK.
 Telling that my customer, they raise a very obvious question:
 How can they provide code that can be used in both software that uses a build systems and software that doesn't?
They want to avoid double-written code or scripts to transform code form one format to another (header files to module or vice versa)
And they really do not want to deliver/provide two different files of C++ code for the same functionality.
Which results in the following question:
What is the best approach / trick / hack to provide single-source code that can be used as both header file and module?
Or should customers in situations like this not replace header files by something that supports modules at all?

Nicolai M. Josuttis
+49 (0)531 / 129 88 86
+49 (0)700 / JOSUTTIS

 C++: http://cppstd20.com, http://cppstd17.com, http://cppmove.com,
      http://cppstdlib.com, http://tmplbook.com


Received on 2022-05-25 05:57:54