[iter] Accept pointers in hb_iter()
authorBehdad Esfahbod <behdad@behdad.org>
Wed, 3 Apr 2019 01:12:01 +0000 (18:12 -0700)
committerBehdad Esfahbod <behdad@behdad.org>
Wed, 3 Apr 2019 01:12:01 +0000 (18:12 -0700)
No idea how to avoid dupicating code.  Was hoping hb_deref_pointer()
would do it, but looks like a pointer can't bind to a universal
reference T&&.  Humm.

src/hb-iter.hh
src/test-iter.cc

index f23904c..9a3c2f4 100644 (file)
@@ -137,6 +137,11 @@ static const struct
   operator () (T&& c) const
   { return c.iter (); }
 
+  template <typename T>
+  hb_iter_t (T)
+  operator () (T* c) const
+  { return c->iter (); }
+
   /* Specialization for C arrays. */
 
   template <typename Type> inline hb_array_t<Type>
index 675bbe3..dcfdd11 100644 (file)
@@ -106,6 +106,9 @@ main (int argc, char **argv)
   int dst[20];
   hb_vector_t<int> v;
 
+  hb_iter (v);
+  hb_iter (&v);
+
   array_iter_t<const int> s (src); /* Implicit conversion from static array. */
   array_iter_t<const int> s2 (v); /* Implicit conversion from vector. */
   array_iter_t<int> t (dst);