diff options
Diffstat (limited to 'c/util.h')
-rw-r--r-- | c/util.h | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -1,13 +1,17 @@ #ifndef UTIL_H #define UTIL_H -#include <algorithm> #include <cstring> #include <memory> #include <string> #include <SWI-Prolog.h> #include <windows.h> +inline size_t Min(size_t a, size_t b) +{ + return a < b? a: b; +} + /* Buf is a span-like structure of a buffer and its size. */ template <typename T> struct Buf @@ -39,7 +43,7 @@ inline int Sprintf(Buf<char> buf, const char* const fmt, T... xs) /* Copy to static wide string buffer. */ inline wchar_t* Wcscpy(Buf<wchar_t> dst, const wchar_t* const src) { - const size_t len = std::min(dst.size, wcslen(src)+1); + const size_t len = Min(dst.size, wcslen(src)+1); memcpy(dst, src, len*sizeof(wchar_t)); dst[len-1] = 0; return dst; @@ -48,7 +52,7 @@ inline wchar_t* Wcscpy(Buf<wchar_t> dst, const wchar_t* const src) /* Copy to static narrow string buffer. */ inline char* Strcpy(Buf<char> dst, const char* const src) { - const size_t len = std::min(dst.size, strlen(src)+1); + const size_t len = Min(dst.size, strlen(src)+1); memcpy(dst, src, len); dst[len-1] = 0; return dst; |