#ifndef UTIL_H #define UTIL_H #include #include #include #include #include #define CAT(a, b) a##b #define APPLY(a, ...) a(__VA_ARGS__) #define UNUSED APPLY(CAT, unused_, __COUNTER__) /* Format static wide string. */ template inline int Swprintf(wchar_t (&buf)[N], const wchar_t* const fmt, T... xs) { return _snwprintf_s(buf, N, _TRUNCATE, fmt, xs...); } /* Format static narrow string. */ template inline int Sprintf(char (&buf)[N], const char* const fmt, T... xs) { return _snprintf_s(buf, N, _TRUNCATE, fmt, xs...); } /* Copy to static wide string buffer. */ template inline wchar_t* Wcscpy(wchar_t (&dst)[N], const wchar_t* const src) { const size_t len = std::min(N, wcslen(src)+1); memcpy(dst, src, len*sizeof(wchar_t)); dst[len-1] = 0; return dst; } /* Copy to static narrow string buffer. */ template inline char* Strcpy(char (&dst)[N], const char* const src) { const size_t len = std::min(N, strlen(src)+1); memcpy(dst, src, len); dst[len-1] = 0; return dst; } inline int Cmp(const int a, const int b) { if (a == b) return 0; if (a > b) return 1; return -1; } #endif