From dc59bb6f1505cc1aacda884b4cf58ff48e607ff2 Mon Sep 17 00:00:00 2001 From: cheny-work Date: Mon, 3 Jul 2017 14:37:23 +0800 Subject: [PATCH] Add the template partial specialization for struct map_compare Add the template partial specialization: struct map_compare {...} In .\better-enums\example\5-map.cc auto not_a_literal = std::wstring(L"the blue channel"); // error. It will throw exception std::cout << descriptions.to_enum(not_a_literal.c_str()) << std::endl; --- enum.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/enum.h b/enum.h index d423eef..edd92a0 100644 --- a/enum.h +++ b/enum.h @@ -1150,6 +1150,23 @@ struct map_compare { } }; +// chenyao add +template <> +struct map_compare { + BETTER_ENUMS_CONSTEXPR_ static bool less(const wchar_t *a, const wchar_t *b) + { return less_loop(a, b); } + + private: + BETTER_ENUMS_CONSTEXPR_ static bool + less_loop(const wchar_t *a, const wchar_t *b, size_t index = 0) + { + return + a[index] != b[index] ? a[index] < b[index] : + a[index] == L'\0' ? false : + less_loop(a, b, index + 1); + } +}; + template > struct map { typedef T (*function)(Enum);