#C++ Modules: what can be hoisted into module implementations?

10 messages · Page 1 of 1 (latest)

verbal vine
#

In the regular .h/.cpp/#include way of exposing interfaces, we can put declarations in headers and definitions in source/.cpp files, with several notable exceptions:

  • constexpr functions, because the compiler needs to see the implementation to evaluate them
  • templates, since the compiler needs to be able to instantiate templates

How does this change with modules? Are we allowed to split template/function class decls across interface/implementation modules? If not, is there still a reasonable way of splitting stuff up (akin to including a .tpp file in a header)? I know the standard advice is to "use module interfaces as you would a header, and module implementations as you would a regular source," but how strict is that rule?

Unrelated/tangent: do i split module impl/interface in two different dir trees (akin to include/src) or do i just shove everything into src?

crystal pikeBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

real perch
#

I'm afraid the answer is pretty simple: modules don't change anything here. modules are just a way to package and consume declarations.

#

an importing translation unit will need to know the definition of your constexpr function. and the only way for it to get that is if the module exports it.

#

same story with templates

#

if you want to split the module interface into multiple files, use module partitions.

verbal vine
#

so I can just provide an impl partition? how does this affect how module consumers import?

real perch
#

it doesn't affect how consumers import. consumers import the interface unit, which would export the import of your partition and, thus, they'd also import the partition.

verbal vine
#

!solved