ApprovalTests.cpp icon indicating copy to clipboard operation
ApprovalTests.cpp copied to clipboard

Use constexpr to define version numbers, not #define

Open claremacrae opened this issue 5 years ago • 4 comments

This arose out of #91.

It would be better to use constexpr instead of #define to define the version number components of this project in code - for type-safety.

Not everyone who uses this project uses it with CMake, so I would stick with our current structure - but I see that constexpr is a nicer - type-safe - way of setting the various version numbers...

I'll set up a separate issue to convert the #define approach in to constexpr instead...

Originally posted by @claremacrae in https://github.com/approvals/ApprovalTests.cpp/issues/91#issuecomment-589946545

claremacrae avatar Feb 22 '20 11:02 claremacrae

Current situation:

We use this:

https://github.com/approvals/ApprovalTests.cpp/blob/d997f56343ac70db621fd36593fa55b87b4eb975/build/prepare_release.py#L62-L81

To generate this:

https://github.com/approvals/ApprovalTests.cpp/blob/d997f56343ac70db621fd36593fa55b87b4eb975/ApprovalTests/ApprovalTestsVersion.h#L1-L13

claremacrae avatar Feb 22 '20 11:02 claremacrae

See the following template for the intention of this ticket...

https://github.com/jwillikers/cmake_configure_version_header/blob/fa644a6db6d61b7ac6dffce738bcb038fa4e6bd7/src/version.hpp.in#L1-L14

Instead of the @...@ text, our Python script would insert actual values.

We need to think about the use of a namespace, though - It would be a breaking change to add this now...

And we would use char[] instead of std::string_view

claremacrae avatar Feb 22 '20 11:02 claremacrae

We're marking this as on_hold, as no current plans to implement it...

claremacrae avatar Aug 23 '21 16:08 claremacrae

It doesn't have to be a breaking change, if we add this as a new mechanism, and keep the old one...

claremacrae avatar Aug 23 '21 16:08 claremacrae