Exporting Concept From Module

409 Views Asked by At

I can't find nothing about C++ modules and concepts interaction. Is the syntax of exporting concept from module correct?

export module Module;

template <typename S>
export concept sequence = true;
1

There are 1 best solutions below

3
On

export exports declarations. A concept definition is a declaration and can therefore be exported. It works just like exporting any other declaration, as far as the results of such an export work.

As for the specific grammar, export is applied to the "declaration" grammar rule. And "template-declaration" is a kind of "declaration". A "template-declaration" includes the template header, but the grammatical definition for "template-declaration" says that it's a "template-head" followed by a "declaration" or a "template-head" followed by a "concept-definition".

So just from the grammar, if you want to export a concept definition, you have to do it before the template header, since concept-definition doesn't include export as valid grammar.

However, if you're wondering about exporting regular templates, one might think that, from this grammar, export could come before the "template-head" or after. However, the standard specifically says this:

[A template-declaration's] declaration shall not be an export-declaration.

From this, we conclude that all templates put export before the template-head.