I'm currently ending the development of a C++ header-only template library for grid-based quantum computations and I'm considering replacing an old logging module that I've wrote nearly at the beginning.
I know that it sounds a little bit weird to have a header-only library printing stuff to stdout (and files), but I make heavy use of templates to increase flexibility and efficiency of the runtime binary, hence this choice.
The current logging module uses printf (as I disliked std::cout
syntax), macros, variadic macros (##__VA_ARGS__
), supports console colors and prints out the the location in the source using __FILE__
, __LINE__
macros, i.e. nothing modern nor type safe, but it works.
Does it make sense replace it with fmt
(or something similar) or should I rather try to modernize the existing one (i.e. replace variadic macros with templates, custom built compile-time string_view
's etc.)?
I'd like the library to work "straight-away" that is, I'd like to either:
a) eliminate as much dependencies as possible
b) try find_package(fmt)
or FetchContent them silently in CMake - (btw. is there a general CMake "template" for this behaviour? something like "find_or_fetch"? )
c) place the essential part of fmt
as a git submodule in my project and include a small header file.
Beside this, I'm also planning to use HDF5 library (with or without C++ wrappers). Here again I'm not sure how to best approach it to make the integration as seamless as possible, neither have I decided which wrapper should I use. Would a "find_or_fetch" paradigm be appropriate for header-only library?
I wouldn't if I were you.
fmt
is the opposite of that.fmt
. But you've done that matching already. And modern compilers warn about any mismatches as long as format strings are literals.