[iter] Rewrite test functions
Notably, add hb_is_source_of(,) and hb_is_sink_of(,) to replace most uses of hb_is_iterator_of(,).
This commit is contained in:
parent
42901d7af9
commit
ed972d5d73
|
@ -237,6 +237,21 @@ struct hb_iter_with_fallback_t :
|
||||||
* Meta-programming predicates.
|
* Meta-programming predicates.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* hb_is_iterator() / hb_is_iterator_of() */
|
||||||
|
|
||||||
|
template<typename Iter, typename Item>
|
||||||
|
struct hb_is_iterator_of
|
||||||
|
{
|
||||||
|
template <typename Item2 = Item>
|
||||||
|
static hb_true_t impl (hb_priority<2>, hb_iter_t<Iter, hb_type_identity<Item2>> *);
|
||||||
|
static hb_false_t impl (hb_priority<0>, const void *);
|
||||||
|
|
||||||
|
public:
|
||||||
|
static constexpr bool value = decltype (impl (hb_prioritize, hb_declval (Iter*)))::value;
|
||||||
|
};
|
||||||
|
#define hb_is_iterator_of(Iter, Item) hb_is_iterator_of<Iter, Item>::value
|
||||||
|
#define hb_is_iterator(Iter) hb_is_iterator_of (Iter, typename Iter::item_t)
|
||||||
|
|
||||||
/* hb_is_iterable() */
|
/* hb_is_iterable() */
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -251,39 +266,41 @@ struct hb_is_iterable
|
||||||
static hb_false_t impl (hb_priority<0>);
|
static hb_false_t impl (hb_priority<0>);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static constexpr bool value = decltype (impl<T> (hb_prioritize))::value;
|
||||||
enum { value = decltype (impl<T> (hb_prioritize))::value };
|
|
||||||
};
|
};
|
||||||
#define hb_is_iterable(Iterable) hb_is_iterable<Iterable>::value
|
#define hb_is_iterable(Iterable) hb_is_iterable<Iterable>::value
|
||||||
|
|
||||||
/* TODO Add hb_is_iterable_of().
|
/* hb_is_source_of() / hb_is_sink_of() */
|
||||||
* TODO Add random_access / sorted variants. */
|
|
||||||
|
|
||||||
/* hb_is_iterator() / hb_is_random_access_iterator() / hb_is_sorted_iterator() */
|
|
||||||
|
|
||||||
template <typename Iter, typename Item>
|
|
||||||
static inline char _hb_is_iterator_of (hb_priority<0>, const void *) { return 0; }
|
|
||||||
template <typename Iter,
|
|
||||||
typename Item,
|
|
||||||
typename Item2 = typename Iter::item_t,
|
|
||||||
hb_enable_if (hb_is_convertible (Item2, Item))>
|
|
||||||
static inline int _hb_is_iterator_of (hb_priority<2>, hb_iter_t<Iter, Item2> *) { return 0; }
|
|
||||||
|
|
||||||
template<typename Iter, typename Item>
|
template<typename Iter, typename Item>
|
||||||
struct hb_is_iterator_of { enum {
|
struct hb_is_source_of
|
||||||
value = sizeof (int) == sizeof (_hb_is_iterator_of<Iter, Item> (hb_prioritize, hb_declval (Iter*))) }; };
|
{
|
||||||
#define hb_is_iterator_of(Iter, Item) hb_is_iterator_of<Iter, Item>::value
|
private:
|
||||||
#define hb_is_iterator(Iter) hb_is_iterator_of (Iter, typename Iter::item_t)
|
template <typename Iter2 = Iter,
|
||||||
|
hb_enable_if (hb_is_convertible (typename Iter2::item_t, const Item &))>
|
||||||
|
static hb_true_t impl (hb_priority<2>);
|
||||||
|
static hb_false_t impl (hb_priority<0>);
|
||||||
|
|
||||||
#define hb_is_random_access_iterator_of(Iter, Item) \
|
public:
|
||||||
hb_is_iterator_of (Iter, Item) && Iter::is_random_access_iterator
|
static constexpr bool value = decltype (impl (hb_prioritize))::value;
|
||||||
#define hb_is_random_access_iterator(Iter) \
|
};
|
||||||
hb_is_random_access_iterator_of (Iter, typename Iter::item_t)
|
#define hb_is_source_of(Iter, Item) hb_is_source_of<Iter, Item>::value
|
||||||
|
|
||||||
#define hb_is_sorted_iterator_of(Iter, Item) \
|
template<typename Iter, typename Item>
|
||||||
hb_is_iterator_of (Iter, Item) && Iter::is_sorted_iterator
|
struct hb_is_sink_of
|
||||||
#define hb_is_sorted_iterator(Iter) \
|
{
|
||||||
hb_is_sorted_iterator_of (Iter, typename Iter::item_t)
|
private:
|
||||||
|
static auto impl (hb_priority<2>) -> decltype (hb_declval (Iter) << hb_declval (Item), hb_true_t ());
|
||||||
|
static hb_false_t impl (hb_priority<0>);
|
||||||
|
|
||||||
|
public:
|
||||||
|
static constexpr bool value = decltype (impl (hb_prioritize))::value;
|
||||||
|
};
|
||||||
|
#define hb_is_sink_of(Iter, Item) hb_is_sink_of<Iter, Item>::value
|
||||||
|
|
||||||
|
/* This is commonly used, so define: */
|
||||||
|
#define hb_is_sorted_source_of(Iter, Item) \
|
||||||
|
(hb_is_source_of(Iter, Item) && Iter::is_sorted_iterator)
|
||||||
|
|
||||||
|
|
||||||
/* Range-based 'for' for iterables. */
|
/* Range-based 'for' for iterables. */
|
||||||
|
|
|
@ -419,7 +419,7 @@ struct UnsizedArrayOf
|
||||||
return_trace (true);
|
return_trace (true);
|
||||||
}
|
}
|
||||||
template <typename Iterator,
|
template <typename Iterator,
|
||||||
hb_requires (hb_is_iterator_of (Iterator, const Type))>
|
hb_requires (hb_is_source_of (Iterator, 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);
|
||||||
|
@ -598,7 +598,7 @@ struct ArrayOf
|
||||||
return_trace (true);
|
return_trace (true);
|
||||||
}
|
}
|
||||||
template <typename Iterator,
|
template <typename Iterator,
|
||||||
hb_requires (hb_is_iterator_of (Iterator, const Type))>
|
hb_requires (hb_is_source_of (Iterator, 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);
|
||||||
|
@ -877,7 +877,7 @@ struct SortedArrayOf : ArrayOf<Type, LenType>
|
||||||
return_trace (ret);
|
return_trace (ret);
|
||||||
}
|
}
|
||||||
template <typename Iterator,
|
template <typename Iterator,
|
||||||
hb_requires (hb_is_sorted_iterator_of (Iterator, const Type))>
|
hb_requires (hb_is_sorted_source_of (Iterator, 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);
|
||||||
|
@ -885,7 +885,6 @@ struct SortedArrayOf : ArrayOf<Type, LenType>
|
||||||
return_trace (ret);
|
return_trace (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
Type &bsearch (const T &x, Type ¬_found = Crap (Type))
|
Type &bsearch (const T &x, Type ¬_found = Crap (Type))
|
||||||
{ return *as_array ().bsearch (x, ¬_found); }
|
{ return *as_array ().bsearch (x, ¬_found); }
|
||||||
|
|
|
@ -797,7 +797,7 @@ struct CoverageFormat1
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Iterator,
|
template <typename Iterator,
|
||||||
hb_requires (hb_is_sorted_iterator_of (Iterator, const GlyphID))>
|
hb_requires (hb_is_sorted_source_of (Iterator, hb_codepoint_t))>
|
||||||
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_requires (hb_is_sorted_iterator_of (Iterator, const GlyphID))>
|
hb_requires (hb_is_sorted_source_of (Iterator, hb_codepoint_t))>
|
||||||
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_requires (hb_is_sorted_iterator_of (Iterator, const GlyphID))>
|
hb_requires (hb_is_sorted_source_of (Iterator, hb_codepoint_t))>
|
||||||
bool serialize (hb_serialize_context_t *c, Iterator glyphs)
|
bool serialize (hb_serialize_context_t *c, Iterator glyphs)
|
||||||
{
|
{
|
||||||
TRACE_SERIALIZE (this);
|
TRACE_SERIALIZE (this);
|
||||||
|
|
|
@ -170,7 +170,7 @@ struct name
|
||||||
{ return min_size + count * nameRecordZ.item_size; }
|
{ return min_size + count * nameRecordZ.item_size; }
|
||||||
|
|
||||||
template <typename Iterator,
|
template <typename Iterator,
|
||||||
hb_requires (hb_is_iterator_of (Iterator, const NameRecord &))>
|
hb_requires (hb_is_source_of (Iterator, const NameRecord &))>
|
||||||
bool serialize (hb_serialize_context_t *c,
|
bool serialize (hb_serialize_context_t *c,
|
||||||
Iterator it,
|
Iterator it,
|
||||||
const void *src_string_pool)
|
const void *src_string_pool)
|
||||||
|
|
|
@ -127,7 +127,7 @@ main (int argc, char **argv)
|
||||||
array_iter_t<const int> s2 (v); /* Implicit conversion from vector. */
|
array_iter_t<const int> s2 (v); /* Implicit conversion from vector. */
|
||||||
array_iter_t<int> t (dst);
|
array_iter_t<int> t (dst);
|
||||||
|
|
||||||
static_assert (hb_is_random_access_iterator (array_iter_t<int>), "");
|
static_assert (array_iter_t<int>::is_random_access_iterator, "");
|
||||||
|
|
||||||
some_array_t<const int> a (src);
|
some_array_t<const int> a (src);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue