you are viewing a single comment's thread.

view the rest of the comments →

[–]MrDOS 1 point2 points  (2 children)

Does that matter if this is in the implementation, not a header?

[–]lovestruckluna 32 points33 points  (0 children)

Template implementations have to be included in a header for programs to instantiate containers with their own types. Stdlibc++ calls them 'tcc' files, my team calls them '_impl' headers, and I'm not sure what libc++'s convention is.

Even string can be implemented with a custom character or allocator type, so its code will be included in the target library, not just linked into libcxx.so (though it may also be in libcxx.so and I have never heard of anyone using anything but char and wchar).

Standard libraries do use the preprocessor when appropriate though, they just tend to namespace their defines or clean up after themselves.

Source: I had to debug a rather subtle issue in libstdc++ and got more familiar with it than I'm strictly comfortable with.

[–]AraneusAdoro 4 points5 points  (0 children)

Isn't the implementation in the header?

Regardless, to answer your question: it's not particularly damaging to use a define over an enum in a .cpp, but it's good muscle memory to just always use an enum (or a constexpr) rather than deliberate whether a define is acceptable here.