aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-07-22 03:02:33 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-07-22 03:02:33 +0200
commit3eb3a554e3c88c0677bd9bd3070e2f1736f4b8cf (patch)
tree05378ad19fc13b647ef6cc3228a9cdee466779ba
parent595dfe169eb0ad0dbddf24cf3f94b954718b3cb5 (diff)
downloadEpisodeBrowser-3eb3a554e3c88c0677bd9bd3070e2f1736f4b8cf.tar.gz
Simplify AWTEXT, AWFUN.
Not quite so awful anymore.
-rw-r--r--c/common.h25
1 files changed, 13 insertions, 12 deletions
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<t>(s, L"" s)
-template <typename T> constexpr const T* cond_text(const char*, const wchar_t*);
-template <> constexpr const char* cond_text<char>(const char* sz, const wchar_t*) { return sz; }
-template <> constexpr const wchar_t* cond_text<wchar_t>(const char*, const wchar_t* wsz) { return wsz; }
-
-/* Conditionally select between ANSI and wide Windows API function. */
-#define AWFUN(t, f) cond_fun<t, f##A, f##W>()
-template <typename T, auto F, auto G>
-constexpr std::enable_if_t<std::is_same_v<T, char>, decltype(F)> cond_fun() { return F; }
-template <typename T, auto F, auto G>
-constexpr std::enable_if_t<std::is_same_v<T, wchar_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 <bool B, typename X, typename Y>
+constexpr std::enable_if_t<B == true, X> choose(X x, Y) { return x; }
+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)
+
+/* Conditionally choose between ANSI and wide Windows API function. */
+#define AWFUN(t, f) choose<std::is_same_v<t, char>>(f##A, f##W)
/* Return integer scaled for current DPI. */
inline int Dpi(const int i)