diff options
Diffstat (limited to 'c/common.h')
-rw-r--r-- | c/common.h | 14 |
1 files changed, 9 insertions, 5 deletions
@@ -54,7 +54,11 @@ std::optional<T> maybe_make(U... xs) } } -/* Call Windows API function, throwing error on NULL. */ +/* Variable template for caching values from GetSystemMetrics. */ +template <int I> +const auto Metric = GetSystemMetrics(I); + +/* Check result of Windows API call, throwing error on NULL. */ template <typename T> inline T require(const T x) { @@ -62,7 +66,7 @@ inline T require(const T x) return x; } -/* Call Windows API function, showing a warning on NULL. */ +/* Check result of Windows API call, showing a warning on NULL. */ template <typename T> inline T prefer(const T x) { @@ -75,7 +79,7 @@ inline T prefer(const T x) } /* Conditionally choose between two values. This template is necessary - * because the ternary conditional operator chooses only between + * because the ternary conditional operator can choose only between * values of the same type. */ template <bool B, typename X, typename Y> constexpr std::enable_if_t<B == true, X> choose(X x, Y) { return x; } @@ -83,10 +87,10 @@ template <bool B, typename X, typename Y> constexpr std::enable_if_t<B == false, Y> choose(X, Y y) { return y; } /* Conditionally choose between ANSI and wide string literal. */ -#define AWTEXT(t, s) choose<std::is_same_v<t, char>>(s, L"" s) +#define AWTEXT(t, s) choose<std::is_same_v<t, wchar_t>>(L"" s, s) /* Conditionally choose between ANSI and wide Windows API function. */ -#define AWFUN(t, f) choose<std::is_same_v<t, char>>(f##A, f##W) +#define AWFUN(t, f) choose<std::is_same_v<t, wchar_t>>(f##W, f##A) /* Return integer scaled for current DPI. */ inline int Dpi(const int i) |