kainjow / Mustache

Mustache text templates for modern C++
Boost Software License 1.0
357 stars 49 forks source link

Add library version definitions #55

Closed kainjow closed 2 years ago

kainjow commented 3 years ago

Fixes #54

mgautierfr commented 3 years ago

It would be nice to also have a #define KAINJOW_MUSTACHE_VERSION_STR "4.1.0" (which can be build from MAJOR, MINOR and PATCH). It would simplify version comparison (a lot of a build tools have a string version compare function).

But I can go without it.

kainjow commented 2 years ago

@mgautierfr without duplicating the version info, that macro would be ugly to create I think, if even possible. What about a function to return it as a string?

mgautierfr commented 2 years ago

This would work (tested) (taken from https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html) :

#define VERSION_MAJOR 4
#define VERSION_MINOR 2
#define VERSION_BUILD 1

#define xstr(s) str(s)
#define str(s) #s

#define VERSION_STR xstr(VERSION_MAJOR) "." xstr(VERSION_MINOR) "." xstr(VERSION_BUILD)

/* Cannot undef this as the "resolution" of the macro will be made when we actually use `VERSION_STR`
You could create a const instead of a define to resolve xstr/str and then undef them.
#undef str
#undef xstr
*/

int main() {
    std::cout << "Version is " << VERSION_STR << std::endl;
}

But then we would have this xstr/str macro defined. You can "hide" them by prefix them but anyway. (Or create a const) Do as you prefer. Having the version as 3 integers is enough for me. Thanks.