From: Daniela Engert (dani_at_[hidden])
Date: 2024-07-08 06:44:13


Am 08.07.2024 um 08:32 schrieb Antony Polukhin:
>
>
> воскресенье, 7 июля 2024 г. пользователь Daniela Engert via Boost
> <boost_at_[hidden]> написал:
> <...>
>
> If you as an author want to support mixing of both traditional
> #includes and module imports, then you'd better make sure that
> entity S is attached to the global module in both cases. Like
> along these lines:
>
> // module lib
> export module lib;
> #define BOOST_MODULE_EXPORT export
> #ifdef BOOST_xxx_ATTACHED_TO_GLOBAL_MODULE
> extern "C++" {
> #endif
> #include "internal.h"
> #ifdef BOOST_xxx_ATTACHED_TO_GLOBAL_MODULE
> }
> #endif
>
> This way, name attachment is a module compile-time option.
>
> I use this f.e. in my Asio module for a long time.
>
>
> Does it make sense to go another way and make the header auto-import
> self as a module if module exists:
>
> // lib.h
> #pragma once
> #ifndef BOOST_NO_CXX20_MODULES
> import lib;
> #else
> #  ifndef BOOST_MODULE_EXPORT
> #   define BOOST_MODULE_EXPORT
> #  endif
> #  include "internal.h"
> #endif
>
I might be dense, but this automatically switches between #include and
import on the consumer side of a library. What you cite is one possible
approach to selectable name attachment on the producer side.

Dani