Faster compile by generting a header file from a cpp2? #903
tomFlowee
started this conversation in
Suggestions
Replies: 1 comment 3 replies
-
Is this what you're looking for? #594 (comment). |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
It is the old problem of interoperability between existing and new.
The "old" cpp way of making classes that are reusable is to create a header file and separately a cpp file. And, to be clear, I'm NOT talking about someone making a library. Even a small app with a buch of classes is better to be split into header files and cpp files because of how the compiler works.
What is very nice about cpp2 is the creation of a class is much less messy. It avoids a lot of overhead and it is generally safer due to the specializations.
As a result if I write an enum class that should be reused in all of my project files, I prefer to write one cpp2 file to do that.
Which begs the question, how do the other cpp2 files USE that enum class? (as a simple example).
My suggestion:
a cpp2 file that has a class in it could end up generating two files in the cppfront tool; a .cpp and a .h file. This allows other parts of the project to reuse the class (because what's the point of such code otherwise?). But unlike the current '.h2' solution it would not cause the compiler to have to completey compile the entire content in every single compile-unit. The content of methods would be safely moved to a cpp file.
Ideally a class would be exported or otherwise tagged to make clear that it needs to be put into a header file. Maybe the Java method of public vs private and 'default' classes makes sense. I don't know.
But my general idea is to take a cpp2 file and if there are re-usable classes in there it should generate a header file AS WELL as a cpp file.
What do others think?
Beta Was this translation helpful? Give feedback.
All reactions