From 3eb3a554e3c88c0677bd9bd3070e2f1736f4b8cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Fri, 22 Jul 2022 03:02:33 +0200 Subject: Simplify AWTEXT, AWFUN. Not quite so awful anymore. --- c/common.h | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'c') diff --git a/c/common.h b/c/common.h index 4b42f45..2c0be13 100644 --- a/c/common.h +++ b/c/common.h @@ -74,18 +74,19 @@ inline T prefer(const T x) return x; } -/* Conditionally select between ANSI and wide string literal. */ -#define AWTEXT(t, s) cond_text(s, L"" s) -template constexpr const T* cond_text(const char*, const wchar_t*); -template <> constexpr const char* cond_text(const char* sz, const wchar_t*) { return sz; } -template <> constexpr const wchar_t* cond_text(const char*, const wchar_t* wsz) { return wsz; } - -/* Conditionally select between ANSI and wide Windows API function. */ -#define AWFUN(t, f) cond_fun() -template -constexpr std::enable_if_t, decltype(F)> cond_fun() { return F; } -template -constexpr std::enable_if_t, decltype(G)> cond_fun() { return G; } +/* Conditionally choose between two values. This template is necessary + * because the ternary conditional operator chooses only between + * values of the same type. */ +template +constexpr std::enable_if_t choose(X x, Y) { return x; } +template +constexpr std::enable_if_t choose(X, Y y) { return y; } + +/* Conditionally choose between ANSI and wide string literal. */ +#define AWTEXT(t, s) choose>(s, L"" s) + +/* Conditionally choose between ANSI and wide Windows API function. */ +#define AWFUN(t, f) choose>(f##A, f##W) /* Return integer scaled for current DPI. */ inline int Dpi(const int i) -- cgit v1.2.3