diff --git a/src/hb-vector.hh b/src/hb-vector.hh index b3c3ac8cd..9eb45f502 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -32,8 +32,9 @@ #include "hb-null.hh" -template -struct hb_vector_t +template +struct hb_vector_t : std::conditional, hb_empty_t>::type { typedef Type item_t; static constexpr unsigned item_size = hb_static_size (Type); @@ -362,11 +363,14 @@ struct hb_vector_t shrink_vector (size); } + + /* Sorting API. */ void qsort (int (*cmp)(const void*, const void*)) { as_array ().qsort (cmp); } void qsort (unsigned int start = 0, unsigned int end = (unsigned int) -1) { as_array ().qsort (start, end); } + /* Unsorted search API. */ template Type *lsearch (const T &x, Type *not_found = nullptr) { return as_array ().lsearch (x, not_found); } @@ -376,6 +380,22 @@ struct hb_vector_t template bool lfind (const T &x, unsigned *pos = nullptr) const { return as_array ().lfind (x, pos); } + + /* Sorted search API. */ + template + Type *bsearch (const T &x, Type *not_found = nullptr) + { return as_array ().bsearch (x, not_found); } + template + const Type *bsearch (const T &x, const Type *not_found = nullptr) const + { return as_array ().bsearch (x, not_found); } + template + bool bfind (const T &x, unsigned int *i = nullptr, + hb_not_found_t not_found = HB_NOT_FOUND_DONT_STORE, + unsigned int to_store = (unsigned int) -1) const + { return as_array ().bfind (x, i, not_found, to_store); } }; template