diff options
author | John Ankarström <john@ankarstrom.se> | 2022-07-29 15:31:26 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-07-29 15:31:26 +0200 |
commit | c883d9cf5673fe0af8d69120b048d642e122bdbb (patch) | |
tree | e657e8375be9e881492bc05b15b036ed633a7765 /c/common.h | |
parent | a67d7ca9e69799728801e30eff6af1adc7d2e53b (diff) | |
download | EpisodeBrowser-c883d9cf5673fe0af8d69120b048d642e122bdbb.tar.gz |
Use swprintf_s instead of string streams.
I find it much simpler. It is very safe, as wszf only accepts
fixed-size arrays. There is, of course, the chance that swprintf_s
fails and writes nothing into the array. This can be handled by the
caller, if desired.
Diffstat (limited to 'c/common.h')
-rw-r--r-- | c/common.h | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -42,6 +42,12 @@ T* Library::GetProcAddress(const char* const szProc) return (T*)(void*)::GetProcAddress(m_hModule, szProc); } +template<size_t N, typename... T> +inline auto wszf(wchar_t (&wsz)[N], const wchar_t* wszFmt, T... xs) +{ + return swprintf_s(wsz, N, wszFmt, xs...); +} + /* Create and return an object of type C. If construction fails, * return nothing. The returned value must be checked before being * used, as dereferencing is undefined if the value is empty. */ @@ -57,7 +63,7 @@ std::optional<T> maybe_make(U... xs) /* Variable template for caching values from GetSystemMetrics. */ template <int I> -const auto Metric = GetSystemMetrics(I); +auto Metric = GetSystemMetrics(I); /* Check result of Windows API call, throwing error on NULL. */ template <typename T> |