I'm working on a multi-platform codebase, and on one of the platforms, sprintf_s
isn't available, but snprintf
does exist, so in this case the solution is to have the line
#define sprintf_s snprintf
However, I'd like to either automatically revert this (or throw a compile time error so I can do it manually) should the platform implement sprintf_s
.
I've found multiple questions here to detect if a class has a member function defined (or an overload exists of a stream operator), but none for a function like sprintf_s
.
(I'd rather not use anything experimental, but if std::experimental::is_detected
is the only solution so be it).
The ideal solution looks something like
if !sprintf exists
#define sprintf_s snprintf
but something like the following would also be acceptable
static_assert(!sprintf_s_exists, "sprintf_s is now defined");
Aucun commentaire:
Enregistrer un commentaire