Naming convention for headers that contain forward declarations

I have a big enum class that is used from many files. The enum class is constantly changing as I add and remove things which causes a lot or recompilation.

I tried to minimize the need for recompilation by using a forward declaration instead of #include whenever I don't need the full enum class definition, just like you normally do with classes.

This works great except that the underlying type is not int so I have to repeat the underlying type each time I write a forward declaration. This feels a bit redundant and isn't optimal if I later decide the change the underlying type.

I have arrived at the conclusion that I should use two header files. One that contains the full definition of the enum class (EnumClass.h) and another one that only contains a forward declaration.

I was thinking of naming the file EnumClass_decl.h or EnumClass_fwd.h (inspired by <iosfwd>) but I'm not sure what is best. Do you use or know of any naming conventions for headers like this?
closed account (48bpfSEw)
topic "namíng" on https://google.github.io/styleguide/cppguide.html

Did you mentioned to splitt your mega enum class into separat sections? To compile every time every project when this file is changed is eh, or an other idea is to expose this values in a database refereceing them by calling names.



Thank you.

topic "namíng" on https://google.github.io/styleguide/cppguide.html

I didn't find anything about my specific situation. Quite the opposite. They recommend avoiding forward declarations but I'm not going to do that.

Did you mentioned to splitt your mega enum class into separat sections?

Splitting how? All values need to be of the same type.

To compile every time every project when this file is changed is eh

It's only used in one project, but the project consists of many files.

an other idea is to expose this values in a database refereceing them by calling names.

Yeah, I have thought of that but I prefer getting a compile time error when something is wrong.
closed account (48bpfSEw)
Thank you, for the perfect communication cycle: Question -> Answer -> Feedback.



EnumClass_decl.h or EnumClass_fwd.h

sounds good for me. ^^
A "declaration" may be forward or not. EnumClass_fwd.h conveys intent better, I think.
The standard library model may be of interest:

std::error_category http://en.cppreference.com/w/cpp/error/error_category
std::error_condition http://en.cppreference.com/w/cpp/error/error_condition

std::is_error_condition_enum http://en.cppreference.com/w/cpp/error/error_condition/is_error_condition_enum (for SFINAE etc.)
Last edited on
cire, good point. EnumClass_fwd.h it is then.
Topic archived. No new replies allowed.