From 6f74d80ed1f20a31744f78ee5a290b76b1dfb102 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 1 Nov 2021 21:49:32 -0600 Subject: [PATCH] [vector] Complete sorted_vector 5-methods --- src/hb-vector.hh | 11 +++++++++-- src/test-vector.cc | 19 ++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/hb-vector.hh b/src/hb-vector.hh index 43e21d498..c34498bbc 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -313,9 +313,16 @@ struct hb_vector_t template struct hb_sorted_vector_t : hb_vector_t { - hb_sorted_vector_t () : hb_vector_t () {} + 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 lst) : hb_vector_t (lst) {} - hb_sorted_vector_t (hb_sorted_vector_t& o) : hb_vector_t (o) {} + template + hb_sorted_vector_t (const Iterable &o) : hb_vector_t (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&) (a), (hb_vector_t&) (b)); } diff --git a/src/test-vector.cc b/src/test-vector.cc index 1aeb86bdd..7dacec818 100644 --- a/src/test-vector.cc +++ b/src/test-vector.cc @@ -36,6 +36,7 @@ main (int argc, char **argv) { hb_vector_t v1 {1, 2}; hb_vector_t v2 {v1}; + hb_vector_t V2 {v1}; assert (v1.length == 2); assert (v1[0] == 1); assert (v1[1] == 2); @@ -48,6 +49,7 @@ main (int argc, char **argv) { hb_vector_t v1 {1, 2}; hb_vector_t v2 = v1; + hb_vector_t V2 = v1; assert (v1.length == 2); assert (v1[0] == 1); assert (v1[1] == 2); @@ -59,6 +61,7 @@ main (int argc, char **argv) /* Test move constructor. */ { hb_vector_t v {hb_vector_t {1, 2}}; + hb_vector_t V {hb_vector_t {1, 2}}; assert (v.length == 2); assert (v[0] == 1); assert (v[1] == 2); @@ -67,12 +70,14 @@ main (int argc, char **argv) /* Test move assignment. */ { hb_vector_t v; + hb_sorted_vector_t V; v = hb_vector_t {1, 2}; + V = hb_sorted_vector_t {1, 2}; assert (v.length == 2); assert (v[0] == 1); assert (v[1] == 2); } - /* Test initializing vector from iterable. */ + /* Test initializing from iterable. */ { hb_set_t s; @@ -80,13 +85,17 @@ main (int argc, char **argv) s.add (12); hb_vector_t v (s); + hb_sorted_vector_t V (s); assert (v.length == 2); + assert (V.length == 2); assert (v[0] == 12); + assert (V[0] == 12); assert (v[1] == 18); + assert (V[1] == 18); } - /* Test initializing vector from iterator. */ + /* Test initializing from iterator. */ { hb_set_t s; @@ -94,13 +103,17 @@ main (int argc, char **argv) s.add (12); hb_vector_t v (hb_iter (s)); + hb_vector_t V (hb_iter (s)); assert (v.length == 2); + assert (V.length == 2); assert (v[0] == 12); + assert (V[0] == 12); assert (v[1] == 18); + assert (V[1] == 18); } - /* Test initializing vector from initializer list and swapping. */ + /* Test initializing from initializer list and swapping. */ { hb_vector_t v1 {1, 2, 3}; hb_vector_t v2 {4, 5};