C++ Logo

sg15

Advanced search

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

From: Nico Josuttis <nico_at_[hidden]>
Date: Wed, 25 May 2022 08:38:23 +0200
So you propose not to switch to a module at all to provide the code.
Thanks


Am 25. Mai 2022 07:57:48 OEZ schrieb "许传奇(夜灯)" <chuanqi.xcq_at_[hidden]>:
>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:
>```
>module;
>#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.
>
>Thanks,
>Chuanqi
>
>
>------------------------------------------------------------------
>From:Nicolai Josuttis via Ext <ext_at_[hidden]>
>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_[hidden]>
>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
>www.josuttis.de
>+49 (0)531 / 129 88 86
>+49 (0)700 / JOSUTTIS
>
>Books:
> C++: http://cppstd20.com, http://cppstd17.com, http://cppmove.com,
> http://cppstdlib.com, http://tmplbook.com
>
>
-- 
Nico Josuttis
(sent from my mobile phone) 

Received on 2022-05-25 06:38:29