C++ Logo


Advanced search

How to provide functionality as both header file and module?

From: Nicolai Josuttis <nico_at_[hidden]>
Date: Wed, 25 May 2022 07:19:03 +0200
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:19:40