Conditionalize IntType::cmp() so it never fails to compile

Useful with lfind() since that calls hb_equal() which SFINAEs which
cmp() to use.
This commit is contained in:
Behdad Esfahbod 2021-02-05 13:40:10 -05:00
parent ed04174a64
commit 98374cebe1
1 changed files with 12 additions and 5 deletions

View File

@ -80,14 +80,21 @@ struct IntType
return pb->cmp (*pa);
}
template <typename Type2>
template <typename Type2,
hb_enable_if (hb_is_integral (Type2) &&
sizeof (Type2) < sizeof (int) &&
sizeof (Type) < sizeof (int))>
int cmp (Type2 a) const
{
Type b = v;
if (sizeof (Type) < sizeof (int) && sizeof (Type2) < sizeof (int))
return (int) a - (int) b;
else
return a < b ? -1 : a == b ? 0 : +1;
return (int) a - (int) b;
}
template <typename Type2,
hb_enable_if (hb_is_convertible (Type2, Type))>
int cmp (Type2 a) const
{
Type b = v;
return a < b ? -1 : a == b ? 0 : +1;
}
bool sanitize (hb_sanitize_context_t *c) const
{