diff --git a/src/hb-vector.hh b/src/hb-vector.hh index f6915209c..7b08e3b4d 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -189,12 +189,14 @@ struct hb_vector_t : std::conditional, hb_empty { if (unlikely (!resize (length + 1))) return &Crap (Type); - return &arrayZ[length - 1]; + return std::addressof (arrayZ[length - 1]); } - template + template ::value && + std::is_copy_assignable::value)> Type *push (T&& v) { - /* TODO Emplace? */ Type *p = push (); if (p == &Crap (Type)) // If push failed to allocate then don't copy v, since this may cause @@ -204,6 +206,22 @@ struct hb_vector_t : std::conditional, hb_empty *p = std::forward (v); return p; } + template ::value)> + Type *push (T&& v) + { + if (unlikely (!alloc (length + 1))) + // If push failed to allocate then don't copy v, since this may cause + // the created copy to leak memory since we won't have stored a + // reference to it. + return &Crap (Type); + + /* Emplace. */ + length++; + Type *p = std::addressof (arrayZ[length - 1]); + return new (p) Type (std::forward (v)); + } bool in_error () const { return allocated < 0; }