Add convenience _FORMAT macro

This commit is contained in:
Gallo Alejandro 2022-09-12 18:42:36 +02:00
parent f1b2f37fe2
commit da704ad820

View File

@ -80,6 +80,16 @@ struct Timer {
using Timings = std::map<std::string, Timer>;
// Chrono:1 ends here
// A nice handy macro to do formatting
#define _FORMAT(_fmt, ...) \
([&] (void) -> std::string { \
int _sz = std::snprintf(nullptr, 0, _fmt, __VA_ARGS__); \
std::vector<char> _out(_sz + 1); \
std::snprintf(&_out[0], _out.size(), _fmt, __VA_ARGS__); \
return std::string(_out.data()); \
})()
// [[file:~/cuda/atrip/atrip.org::*Epilog][Epilog:1]]
}
// Epilog:1 ends here