Specialize map_compare for wchar_t (#44)

Add the template partial specialization:
    struct map_compare<const wchar_t*> {...}
This commit is contained in:
cheny 2017-07-13 19:20:57 +08:00 committed by Anton Bachin
parent 6988e0509e
commit 73a1619cb7

17
enum.h
View File

@ -1150,6 +1150,23 @@ struct map_compare<const char*> {
}
};
// chenyao add
template <>
struct map_compare<const wchar_t*> {
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 <typename Enum, typename T, typename Compare = map_compare<T> >
struct map {
typedef T (*function)(Enum);