diff options
Diffstat (limited to 'thirdparty/harfbuzz/src/hb-vector.hh')
-rw-r--r-- | thirdparty/harfbuzz/src/hb-vector.hh | 57 |
1 files changed, 43 insertions, 14 deletions
diff --git a/thirdparty/harfbuzz/src/hb-vector.hh b/thirdparty/harfbuzz/src/hb-vector.hh index 110d457caf..b0a1e5e966 100644 --- a/thirdparty/harfbuzz/src/hb-vector.hh +++ b/thirdparty/harfbuzz/src/hb-vector.hh @@ -38,10 +38,23 @@ struct hb_vector_t typedef Type item_t; static constexpr unsigned item_size = hb_static_size (Type); - hb_vector_t () { init (); } - hb_vector_t (const hb_vector_t &o) + hb_vector_t () = default; + hb_vector_t (std::initializer_list<Type> lst) : hb_vector_t () + { + alloc (lst.size ()); + for (auto&& item : lst) + push (item); + } + template <typename Iterable, + hb_requires (hb_is_iterable (Iterable))> + hb_vector_t (const Iterable &o) : hb_vector_t () + { + if (hb_iter (o).is_random_access_iterator) + alloc (hb_len (hb_iter (o))); + hb_copy (o, *this); + } + hb_vector_t (const hb_vector_t &o) : hb_vector_t () { - init (); alloc (o.length); hb_copy (o, *this); } @@ -55,11 +68,11 @@ struct hb_vector_t ~hb_vector_t () { fini (); } private: - int allocated; /* == -1 means allocation failed. */ + int allocated = 0; /* == -1 means allocation failed. */ public: - unsigned int length; + unsigned int length = 0; public: - Type *arrayZ; + Type *arrayZ = nullptr; void init () { @@ -87,6 +100,13 @@ struct hb_vector_t resize (0); } + friend void swap (hb_vector_t& a, hb_vector_t& b) + { + hb_swap (a.allocated, b.allocated); + hb_swap (a.length, b.length); + hb_swap (a.arrayZ, b.arrayZ); + } + hb_vector_t& operator = (const hb_vector_t &o) { reset (); @@ -96,11 +116,7 @@ struct hb_vector_t } hb_vector_t& operator = (hb_vector_t &&o) { - fini (); - allocated = o.allocated; - length = o.length; - arrayZ = o.arrayZ; - o.init (); + hb_swap (*this, o); return *this; } @@ -134,7 +150,7 @@ struct hb_vector_t /* Sink interface. */ template <typename T> - hb_vector_t& operator << (T&& v) { push (hb_forward<T> (v)); return *this; } + hb_vector_t& operator << (T&& v) { push (std::forward<T> (v)); return *this; } hb_array_t< Type> as_array () { return hb_array (arrayZ, length); } hb_array_t<const Type> as_array () const { return hb_array (arrayZ, length); } @@ -182,7 +198,7 @@ struct hb_vector_t // the created copy to leak memory since we won't have stored a // reference to it. return p; - *p = hb_forward<T> (v); + *p = std::forward<T> (v); return p; } @@ -239,7 +255,7 @@ struct hb_vector_t Type pop () { if (!length) return Null (Type); - return hb_move (arrayZ[--length]); /* Does this move actually work? */ + return std::move (arrayZ[--length]); /* Does this move actually work? */ } void remove (unsigned int i) @@ -295,6 +311,19 @@ struct hb_vector_t template <typename Type> struct hb_sorted_vector_t : hb_vector_t<Type> { + hb_sorted_vector_t () = default; + ~hb_sorted_vector_t () = default; + hb_sorted_vector_t (hb_sorted_vector_t& o) = default; + hb_sorted_vector_t (hb_sorted_vector_t &&o) = default; + hb_sorted_vector_t (std::initializer_list<Type> lst) : hb_vector_t<Type> (lst) {} + template <typename Iterable, + hb_requires (hb_is_iterable (Iterable))> + hb_sorted_vector_t (const Iterable &o) : hb_vector_t<Type> (o) {} + hb_sorted_vector_t& operator = (const hb_sorted_vector_t &o) = default; + hb_sorted_vector_t& operator = (hb_sorted_vector_t &&o) = default; + friend void swap (hb_sorted_vector_t& a, hb_sorted_vector_t& b) + { hb_swap ((hb_vector_t<Type>&) (a), (hb_vector_t<Type>&) (b)); } + hb_sorted_array_t< Type> as_array () { return hb_sorted_array (this->arrayZ, this->length); } hb_sorted_array_t<const Type> as_array () const { return hb_sorted_array (this->arrayZ, this->length); } |