diff options
author | John Ankarström <john@ankarstrom.se> | 2022-07-22 03:02:33 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-07-22 03:02:33 +0200 |
commit | 3eb3a554e3c88c0677bd9bd3070e2f1736f4b8cf (patch) | |
tree | 05378ad19fc13b647ef6cc3228a9cdee466779ba /c/common.h | |
parent | 595dfe169eb0ad0dbddf24cf3f94b954718b3cb5 (diff) | |
download | EpisodeBrowser-3eb3a554e3c88c0677bd9bd3070e2f1736f4b8cf.tar.gz |
Simplify AWTEXT, AWFUN.
Not quite so awful anymore.
Diffstat (limited to 'c/common.h')
-rw-r--r-- | c/common.h | 25 |
1 files changed, 13 insertions, 12 deletions
@@ -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) |