From 2658e40ffb66dba6e2e5525d6ee4792fe1ea1dd1 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 8 Jan 2019 12:53:02 -0800 Subject: [PATCH] [iter] Add hb_is_random_access_iterator() --- src/hb-iter.hh | 10 +++++++--- src/test-iter.cc | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/hb-iter.hh b/src/hb-iter.hh index a3987b3f7..c9b5d4ce0 100644 --- a/src/hb-iter.hh +++ b/src/hb-iter.hh @@ -159,7 +159,7 @@ struct hb_is_iterable { enum { value = _hb_is_iterable::value }; } #define hb_is_iterable(Iterable) hb_is_iterable::value -/* hb_is_iterator() / hb_is_sorted_iterator() */ +/* hb_is_iterator() / hb_is_random_access_iterator() / hb_is_sorted_iterator() */ template struct _hb_is_iterator_of @@ -177,9 +177,13 @@ struct hb_is_iterator_of { enum { #define hb_is_iterator_of(Iter, Item) hb_is_iterator_of::value #define hb_is_iterator(Iter) hb_is_iterator_of (Iter, typename Iter::item_t) +#define hb_is_random_access_iterator_of(Iter, Item) \ + hb_is_iterator_of (Iter, Item) && Iter::is_random_access_iterator +#define hb_is_random_access_iterator(Iter) \ + hb_is_random_access_iterator_of (Iter, typename Iter::item_t) + #define hb_is_sorted_iterator_of(Iter, Item) \ - hb_is_iterator_of (Iter, Item) && \ - Iter::is_sorted_iterator + hb_is_iterator_of (Iter, Item) && Iter::is_sorted_iterator #define hb_is_sorted_iterator(Iter) \ hb_is_sorted_iterator_of (Iter, typename Iter::item_t) diff --git a/src/test-iter.cc b/src/test-iter.cc index d508e249d..5836551db 100644 --- a/src/test-iter.cc +++ b/src/test-iter.cc @@ -105,6 +105,8 @@ main (int argc, char **argv) array_iter_t s2 (v); /* Implicit conversion from vector. */ array_iter_t t (dst); + assert (hb_is_random_access_iterator (array_iter_t)); + some_array_t a (src); s2 = s;