Home > Back-end >  usage of import with plain header files
usage of import with plain header files

Time:03-18

Is it good practice to get rid of #include and only use the import keyword instead even for headers (like <span> or "Foo.h")? Are there any benefits to this? Any possible downsides? Does it add to the length of build time?

cppreference has an example in which it says this:

import <set>; // imports a synthesized header unit formed from header

What exactly does synthesized mean in this context?

CodePudding user response:

Are there any benefits to this?

Importing synthesised header units instead of including the header may satisfy a style guide that wants to use one type of directive for both modules and headers.

Any possible downsides?

It won't work in pre-C 20 code, nor compilers that haven't yet implemented importing header files. This won't matter if you also use modules, since those won't work pre-C 20 either.

  • Related