[meta] Replace most hb_enable_if with hb_requires

They do absolutely same thing.  hb_requires is to encode constraints,
whereas hb_enable_if is for more conditional enabling.
This commit is contained in:
Behdad Esfahbod 2019-05-07 21:39:20 -07:00
parent 6fa1f38070
commit af571dbffc
4 changed files with 37 additions and 44 deletions

View File

@ -281,11 +281,11 @@ struct hb_is_iterator_of { enum {
/* Range-based 'for' for iterables. */ /* Range-based 'for' for iterables. */
template <typename Iterable, template <typename Iterable,
hb_enable_if (hb_is_iterable (Iterable))> hb_requires (hb_is_iterable (Iterable))>
static inline auto begin (Iterable&& iterable) HB_AUTO_RETURN (hb_iter (iterable).begin ()) static inline auto begin (Iterable&& iterable) HB_AUTO_RETURN (hb_iter (iterable).begin ())
template <typename Iterable, template <typename Iterable,
hb_enable_if (hb_is_iterable (Iterable))> hb_requires (hb_is_iterable (Iterable))>
static inline auto end (Iterable&& iterable) HB_AUTO_RETURN (hb_iter (iterable).end ()) static inline auto end (Iterable&& iterable) HB_AUTO_RETURN (hb_iter (iterable).end ())
/* begin()/end() are NOT looked up non-ADL. So each namespace must declare them. /* begin()/end() are NOT looked up non-ADL. So each namespace must declare them.
@ -293,11 +293,11 @@ static inline auto end (Iterable&& iterable) HB_AUTO_RETURN (hb_iter (iterable).
namespace OT { namespace OT {
template <typename Iterable, template <typename Iterable,
hb_enable_if (hb_is_iterable (Iterable))> hb_requires (hb_is_iterable (Iterable))>
static inline auto begin (Iterable&& iterable) HB_AUTO_RETURN (hb_iter (iterable).begin ()) static inline auto begin (Iterable&& iterable) HB_AUTO_RETURN (hb_iter (iterable).begin ())
template <typename Iterable, template <typename Iterable,
hb_enable_if (hb_is_iterable (Iterable))> hb_requires (hb_is_iterable (Iterable))>
static inline auto end (Iterable&& iterable) HB_AUTO_RETURN (hb_iter (iterable).end ()) static inline auto end (Iterable&& iterable) HB_AUTO_RETURN (hb_iter (iterable).end ())
} }
@ -308,14 +308,14 @@ static inline auto end (Iterable&& iterable) HB_AUTO_RETURN (hb_iter (iterable).
*/ */
template <typename Lhs, typename Rhs, template <typename Lhs, typename Rhs,
hb_enable_if (hb_is_iterator (Lhs))> hb_requires (hb_is_iterator (Lhs))>
static inline auto static inline auto
operator | (Lhs lhs, const Rhs &rhs) HB_AUTO_RETURN (rhs (lhs)) operator | (Lhs lhs, const Rhs &rhs) HB_AUTO_RETURN (rhs (lhs))
/* hb_map(), hb_filter(), hb_reduce() */ /* hb_map(), hb_filter(), hb_reduce() */
template <typename Iter, typename Proj, template <typename Iter, typename Proj,
hb_enable_if (hb_is_iterator (Iter))> hb_requires (hb_is_iterator (Iter))>
struct hb_map_iter_t : struct hb_map_iter_t :
hb_iter_t<hb_map_iter_t<Iter, Proj>, hb_iter_t<hb_map_iter_t<Iter, Proj>,
decltype (hb_declval (Proj) (hb_declval (typename Iter::item_t)))> decltype (hb_declval (Proj) (hb_declval (typename Iter::item_t)))>
@ -347,7 +347,7 @@ struct hb_map_iter_factory_t
hb_map_iter_factory_t (Proj f) : f (f) {} hb_map_iter_factory_t (Proj f) : f (f) {}
template <typename Iter, template <typename Iter,
hb_enable_if (hb_is_iterator (Iter))> hb_requires (hb_is_iterator (Iter))>
hb_map_iter_t<Iter, Proj> hb_map_iter_t<Iter, Proj>
operator () (Iter it) const operator () (Iter it) const
{ return hb_map_iter_t<Iter, Proj> (it, f); } { return hb_map_iter_t<Iter, Proj> (it, f); }
@ -365,7 +365,7 @@ struct
HB_FUNCOBJ (hb_map); HB_FUNCOBJ (hb_map);
template <typename Iter, typename Pred, typename Proj, template <typename Iter, typename Pred, typename Proj,
hb_enable_if (hb_is_iterator (Iter))> hb_requires (hb_is_iterator (Iter))>
struct hb_filter_iter_t : struct hb_filter_iter_t :
hb_iter_with_fallback_t<hb_filter_iter_t<Iter, Pred, Proj>, hb_iter_with_fallback_t<hb_filter_iter_t<Iter, Pred, Proj>,
typename Iter::item_t> typename Iter::item_t>
@ -394,7 +394,7 @@ struct hb_filter_iter_factory_t
hb_filter_iter_factory_t (Pred p, Proj f) : p (p), f (f) {} hb_filter_iter_factory_t (Pred p, Proj f) : p (p), f (f) {}
template <typename Iter, template <typename Iter,
hb_enable_if (hb_is_iterator (Iter))> hb_requires (hb_is_iterator (Iter))>
hb_filter_iter_t<Iter, Pred, Proj> hb_filter_iter_t<Iter, Pred, Proj>
operator () (Iter it) const operator () (Iter it) const
{ return hb_filter_iter_t<Iter, Pred, Proj> (it, p, f); } { return hb_filter_iter_t<Iter, Pred, Proj> (it, p, f); }
@ -419,7 +419,7 @@ struct hb_reduce_t
hb_reduce_t (Redu r, InitT init_value) : r (r), init_value (init_value) {} hb_reduce_t (Redu r, InitT init_value) : r (r), init_value (init_value) {}
template <typename Iter, template <typename Iter,
hb_enable_if (hb_is_iterator (Iter)), hb_requires (hb_is_iterator (Iter)),
typename AccuT = decltype (hb_declval (Redu) (hb_declval (InitT), hb_declval (typename Iter::item_t)))> typename AccuT = decltype (hb_declval (Redu) (hb_declval (InitT), hb_declval (typename Iter::item_t)))>
AccuT AccuT
operator () (Iter it) const operator () (Iter it) const
@ -480,7 +480,7 @@ struct hb_zip_iter_t :
struct struct
{ {
template <typename A, typename B, template <typename A, typename B,
hb_enable_if (hb_is_iterable (A) && hb_is_iterable (B))> hb_requires (hb_is_iterable (A) && hb_is_iterable (B))>
hb_zip_iter_t<hb_iter_t (A), hb_iter_t (B)> hb_zip_iter_t<hb_iter_t (A), hb_iter_t (B)>
operator () (A& a, B &b) const operator () (A& a, B &b) const
{ return hb_zip_iter_t<hb_iter_t (A), hb_iter_t (B)> (hb_iter (a), hb_iter (b)); } { return hb_zip_iter_t<hb_iter_t (A), hb_iter_t (B)> (hb_iter (a), hb_iter (b)); }
@ -490,7 +490,7 @@ HB_FUNCOBJ (hb_zip);
/* hb_enumerate */ /* hb_enumerate */
template <typename Iter, template <typename Iter,
hb_enable_if (hb_is_iterator (Iter))> hb_requires (hb_is_iterator (Iter))>
struct hb_enumerate_iter_t : struct hb_enumerate_iter_t :
hb_iter_t<hb_enumerate_iter_t<Iter>, hb_iter_t<hb_enumerate_iter_t<Iter>,
hb_pair_t<unsigned, typename Iter::item_t>> hb_pair_t<unsigned, typename Iter::item_t>>
@ -527,7 +527,7 @@ struct hb_enumerate_iter_t :
struct struct
{ {
template <typename Iterable, template <typename Iterable,
hb_enable_if (hb_is_iterable (Iterable))> hb_requires (hb_is_iterable (Iterable))>
hb_enumerate_iter_t<hb_iter_t (Iterable)> hb_enumerate_iter_t<hb_iter_t (Iterable)>
operator () (Iterable& it) const operator () (Iterable& it) const
{ return hb_enumerate_iter_t<hb_iter_t (Iterable)> (hb_iter (it)); } { return hb_enumerate_iter_t<hb_iter_t (Iterable)> (hb_iter (it)); }
@ -542,9 +542,8 @@ struct hb_apply_t
hb_apply_t (Appl a) : a (a) {} hb_apply_t (Appl a) : a (a) {}
template <typename Iter, template <typename Iter,
hb_enable_if (hb_is_iterator (Iter))> hb_requires (hb_is_iterator (Iter))>
void void operator () (Iter it) const
operator () (Iter it) const
{ {
for (; it; ++it) for (; it; ++it)
(void) hb_invoke (a, *it); (void) hb_invoke (a, *it);
@ -573,9 +572,8 @@ struct hb_sink_t
hb_sink_t (Sink&& s) : s (s) {} hb_sink_t (Sink&& s) : s (s) {}
template <typename Iter, template <typename Iter,
hb_enable_if (hb_is_iterator (Iter))> hb_requires (hb_is_iterator (Iter))>
void void operator () (Iter it) const
operator () (Iter it) const
{ {
for (; it; ++it) for (; it; ++it)
s << *it; s << *it;
@ -601,9 +599,8 @@ HB_FUNCOBJ (hb_sink);
struct struct
{ {
template <typename Iter, template <typename Iter,
hb_enable_if (hb_is_iterator (Iter))> hb_requires (hb_is_iterator (Iter))>
void void operator () (Iter it) const
operator () (Iter it) const
{ {
for (; it; ++it) for (; it; ++it)
(void) *it; (void) *it;
@ -619,9 +616,8 @@ struct hb_unzip_t
hb_unzip_t (Sink1&& s1, Sink2&& s2) : s1 (s1), s2 (s2) {} hb_unzip_t (Sink1&& s1, Sink2&& s2) : s1 (s1), s2 (s2) {}
template <typename Iter, template <typename Iter,
hb_enable_if (hb_is_iterator (Iter))> hb_requires (hb_is_iterator (Iter))>
void void operator () (Iter it) const
operator () (Iter it) const
{ {
for (; it; ++it) for (; it; ++it)
{ {
@ -653,9 +649,8 @@ HB_FUNCOBJ (hb_unzip);
struct struct
{ {
template <typename Iterable, template <typename Iterable,
hb_enable_if (hb_is_iterable (Iterable))> hb_requires (hb_is_iterable (Iterable))>
bool bool operator () (Iterable&& c) const
operator () (Iterable&& c) const
{ {
for (auto it = hb_iter (c); it; ++it) for (auto it = hb_iter (c); it; ++it)
if (!*it) if (!*it)
@ -667,9 +662,8 @@ HB_FUNCOBJ (hb_all);
struct struct
{ {
template <typename Iterable, template <typename Iterable,
hb_enable_if (hb_is_iterable (Iterable))> hb_requires (hb_is_iterable (Iterable))>
bool bool operator () (Iterable&& c) const
operator () (Iterable&& c) const
{ {
for (auto it = hb_iter (c); it; ++it) for (auto it = hb_iter (c); it; ++it)
if (*it) if (*it)
@ -681,9 +675,8 @@ HB_FUNCOBJ (hb_any);
struct struct
{ {
template <typename Iterable, template <typename Iterable,
hb_enable_if (hb_is_iterable (Iterable))> hb_requires (hb_is_iterable (Iterable))>
bool bool operator () (Iterable&& c) const
operator () (Iterable&& c) const
{ {
for (auto it = hb_iter (c); it; ++it) for (auto it = hb_iter (c); it; ++it)
if (*it) if (*it)
@ -698,7 +691,7 @@ HB_FUNCOBJ (hb_none);
*/ */
template <typename C, typename V, template <typename C, typename V,
hb_enable_if (hb_is_iterable (C))> hb_requires (hb_is_iterable (C))>
inline void inline void
hb_fill (C& c, const V &v) hb_fill (C& c, const V &v)
{ {

View File

@ -419,7 +419,7 @@ struct UnsizedArrayOf
return_trace (true); return_trace (true);
} }
template <typename Iterator, template <typename Iterator,
hb_enable_if (hb_is_iterator_of (Iterator, const Type))> hb_requires (hb_is_iterator_of (Iterator, const Type))>
bool serialize (hb_serialize_context_t *c, Iterator items) bool serialize (hb_serialize_context_t *c, Iterator items)
{ {
TRACE_SERIALIZE (this); TRACE_SERIALIZE (this);
@ -600,7 +600,7 @@ struct ArrayOf
return_trace (true); return_trace (true);
} }
template <typename Iterator, template <typename Iterator,
hb_enable_if (hb_is_iterator_of (Iterator, const Type))> hb_requires (hb_is_iterator_of (Iterator, const Type))>
bool serialize (hb_serialize_context_t *c, Iterator items) bool serialize (hb_serialize_context_t *c, Iterator items)
{ {
TRACE_SERIALIZE (this); TRACE_SERIALIZE (this);
@ -880,7 +880,7 @@ struct SortedArrayOf : ArrayOf<Type, LenType>
return_trace (ret); return_trace (ret);
} }
template <typename Iterator, template <typename Iterator,
hb_enable_if (hb_is_sorted_iterator_of (Iterator, const Type))> hb_requires (hb_is_sorted_iterator_of (Iterator, const Type))>
bool serialize (hb_serialize_context_t *c, Iterator items) bool serialize (hb_serialize_context_t *c, Iterator items)
{ {
TRACE_SERIALIZE (this); TRACE_SERIALIZE (this);

View File

@ -797,7 +797,7 @@ struct CoverageFormat1
} }
template <typename Iterator, template <typename Iterator,
hb_enable_if (hb_is_sorted_iterator_of (Iterator, const GlyphID))> hb_requires (hb_is_sorted_iterator_of (Iterator, const GlyphID))>
bool serialize (hb_serialize_context_t *c, Iterator glyphs) bool serialize (hb_serialize_context_t *c, Iterator glyphs)
{ {
TRACE_SERIALIZE (this); TRACE_SERIALIZE (this);
@ -866,7 +866,7 @@ struct CoverageFormat2
} }
template <typename Iterator, template <typename Iterator,
hb_enable_if (hb_is_sorted_iterator_of (Iterator, const GlyphID))> hb_requires (hb_is_sorted_iterator_of (Iterator, const GlyphID))>
bool serialize (hb_serialize_context_t *c, Iterator glyphs) bool serialize (hb_serialize_context_t *c, Iterator glyphs)
{ {
TRACE_SERIALIZE (this); TRACE_SERIALIZE (this);
@ -1030,7 +1030,7 @@ struct Coverage
} }
template <typename Iterator, template <typename Iterator,
hb_enable_if (hb_is_sorted_iterator_of (Iterator, const GlyphID))> hb_requires (hb_is_sorted_iterator_of (Iterator, const GlyphID))>
bool serialize (hb_serialize_context_t *c, Iterator glyphs) bool serialize (hb_serialize_context_t *c, Iterator glyphs)
{ {
TRACE_SERIALIZE (this); TRACE_SERIALIZE (this);

View File

@ -65,7 +65,7 @@ struct some_array_t
template <typename Iter, template <typename Iter,
hb_enable_if (hb_is_iterator (Iter))> hb_requires (hb_is_iterator (Iter))>
static void static void
test_iterator_non_default_constructable (Iter it) test_iterator_non_default_constructable (Iter it)
{ {
@ -92,7 +92,7 @@ test_iterator_non_default_constructable (Iter it)
} }
template <typename Iter, template <typename Iter,
hb_enable_if (hb_is_iterator (Iter))> hb_requires (hb_is_iterator (Iter))>
static void static void
test_iterator (Iter it) test_iterator (Iter it)
{ {
@ -103,7 +103,7 @@ test_iterator (Iter it)
} }
template <typename Iterable, template <typename Iterable,
hb_enable_if (hb_is_iterable (Iterable))> hb_requires (hb_is_iterable (Iterable))>
static void static void
test_iterable (const Iterable &lst = Null(Iterable)) test_iterable (const Iterable &lst = Null(Iterable))
{ {