diff --git a/src/hb-vector.hh b/src/hb-vector.hh index a02aa3c60..0f386fc41 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -43,6 +43,7 @@ struct hb_vector_t : std::conditional, hb_empty using c_array_t = typename std::conditional, hb_array_t>::type; hb_vector_t () = default; + hb_vector_t (std::nullptr_t) : hb_vector_t () {} hb_vector_t (std::initializer_list lst) : hb_vector_t () { alloc (lst.size ()); diff --git a/src/test-map.cc b/src/test-map.cc index 71e3a81ef..f1d5fe3b3 100644 --- a/src/test-map.cc +++ b/src/test-map.cc @@ -30,6 +30,7 @@ static const std::string invalid{"invalid"}; static const hb_set_t invalid_set{}; +static const hb_vector_t invalid_vector{}; int main (int argc, char **argv) @@ -151,6 +152,7 @@ main (int argc, char **argv) } } + /* Test hashing sets. */ { hb_hashmap_t m1; hb_hashmap_t m2; @@ -172,5 +174,29 @@ main (int argc, char **argv) assert (m2.get (hb_set_t {1}) == hb_set_t {2}); } + /* Test hashing vectors. */ + { + using vector_t = hb_vector_t; + + hb_hashmap_t m1; + hb_hashmap_t m2; + + m1.set (vector_t (), vector_t ()); + m2.set (vector_t (), vector_t ()); + + m1.set (vector_t (), vector_t {1}); + m2.set (vector_t (), vector_t {1}); + + m1.set (vector_t {1}, vector_t {2}); + m2.set (vector_t {1}, vector_t {2}); + + /* Cannot override empty vector. */ + assert (m1.get (vector_t ()) == vector_t ()); + assert (m2.get (vector_t ()) == vector_t ()); + + assert (m1.get (vector_t {1}) == vector_t {2}); + assert (m2.get (vector_t {1}) == vector_t {2}); + } + return 0; }