[set] Add standard the 5 standard methods & tests
diff --git a/src/Makefile.am b/src/Makefile.am
index bdd7568..bd88fa0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -350,6 +350,7 @@
test-number \
test-ot-tag \
test-priority-queue \
+ test-set \
test-unicode-ranges \
test-vector \
test-bimap \
@@ -392,10 +393,18 @@
test_ot_tag_CPPFLAGS = $(COMPILED_TESTS_CPPFLAGS)
test_ot_tag_LDADD = $(COMPILED_TESTS_LDADD)
+test_set_SOURCES = test-set.cc hb-static.cc
+test_set_CPPFLAGS = $(COMPILED_TESTS_CPPFLAGS)
+test_set_LDADD = $(COMPILED_TESTS_LDADD)
+
test_unicode_ranges_SOURCES = test-unicode-ranges.cc
test_unicode_ranges_CPPFLAGS = $(COMPILED_TESTS_CPPFLAGS)
test_unicode_ranges_LDADD = $(COMPILED_TESTS_LDADD)
+test_vector_SOURCES = test-vector.cc hb-static.cc
+test_vector_CPPFLAGS = $(COMPILED_TESTS_CPPFLAGS)
+test_vector_LDADD = $(COMPILED_TESTS_LDADD)
+
test_bimap_SOURCES = test-bimap.cc hb-static.cc
test_bimap_CPPFLAGS = $(COMPILED_TESTS_CPPFLAGS)
test_bimap_LDADD = $(COMPILED_TESTS_LDADD)
diff --git a/src/hb-set.hh b/src/hb-set.hh
index 437e234..17eb8ad 100644
--- a/src/hb-set.hh
+++ b/src/hb-set.hh
@@ -31,6 +31,8 @@
#include "hb.hh"
#include "hb-bit-set-invertible.hh"
+#include <initializer_list>
+
template <typename impl_t>
struct hb_sparseset_t
@@ -42,9 +44,22 @@
~hb_sparseset_t () { fini (); }
hb_sparseset_t (const hb_sparseset_t& other) : hb_sparseset_t () { set (other); }
- void operator= (const hb_sparseset_t& other) { set (other); }
- // TODO Add move construtor/assign
- // TODO Add constructor for Iterator
+ hb_sparseset_t (hb_sparseset_t&& other) : hb_sparseset_t () { s = hb_move (other.s); }
+ hb_sparseset_t& operator= (const hb_sparseset_t& other) { set (other); return *this; }
+ hb_sparseset_t& operator= (hb_sparseset_t&& other) { hb_swap (*this, other); return *this; }
+ friend void swap (hb_sparseset_t& a, hb_sparseset_t& b) { hb_swap (a.s, b.s); }
+
+ hb_sparseset_t (std::initializer_list<hb_codepoint_t> l) : hb_sparseset_t ()
+ {
+ for (auto&& i : l)
+ add (i);
+ }
+ template <typename Iterable,
+ hb_requires (hb_is_iterable (Iterable))>
+ hb_sparseset_t (const Iterable &o) : hb_sparseset_t ()
+ {
+ hb_copy (o, *this);
+ }
void init_shallow () { s.init (); }
void init ()
@@ -140,7 +155,17 @@
operator iter_t () const { return iter (); }
};
-struct hb_set_t : hb_sparseset_t<hb_bit_set_invertible_t> {};
+struct hb_set_t : hb_sparseset_t<hb_bit_set_invertible_t>
+{
+ hb_set_t () : hb_sparseset_t<hb_bit_set_invertible_t> () {}
+ hb_set_t (std::initializer_list<hb_codepoint_t> l) : hb_sparseset_t<hb_bit_set_invertible_t> (l) {}
+ hb_set_t (hb_set_t& o) : hb_sparseset_t<hb_bit_set_invertible_t> (o) {}
+ template <typename Iterable,
+ hb_requires (hb_is_iterable (Iterable))>
+ hb_set_t (const Iterable &o) : hb_sparseset_t<hb_bit_set_invertible_t> (o) {}
+ hb_set_t& operator= (const hb_set_t& other) { hb_sparseset_t<hb_bit_set_invertible_t>::operator= (other); return *this; }
+ hb_set_t& operator= (hb_set_t&& other) { hb_sparseset_t<hb_bit_set_invertible_t>::operator= (hb_move (other)); return *this; }
+};
static_assert (hb_set_t::INVALID == HB_SET_VALUE_INVALID, "");
diff --git a/src/meson.build b/src/meson.build
index 8209fb5..ca40176 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -491,6 +491,7 @@
'test-meta': ['test-meta.cc', 'hb-static.cc'],
'test-number': ['test-number.cc', 'hb-number.cc'],
'test-ot-tag': ['hb-ot-tag.cc'],
+ 'test-set': ['test-set.cc', 'hb-static.cc'],
'test-unicode-ranges': ['test-unicode-ranges.cc'],
'test-vector': ['test-vector.cc', 'hb-static.cc'],
'test-bimap': ['test-bimap.cc', 'hb-static.cc'],
diff --git a/src/test-set.cc b/src/test-set.cc
new file mode 100644
index 0000000..531df17
--- /dev/null
+++ b/src/test-set.cc
@@ -0,0 +1,96 @@
+/*
+ * Copyright © 2021 Behdad Esfahbod
+ *
+ * This is part of HarfBuzz, a text shaping library.
+ *
+ * Permission is hereby granted, without written agreement and without
+ * license or royalty fees, to use, copy, modify, and distribute this
+ * software and its documentation for any purpose, provided that the
+ * above copyright notice and the following two paragraphs appear in
+ * all copies of this software.
+ *
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
+ * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
+ * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ *
+ * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ *
+ */
+
+#include "hb.hh"
+#include "hb-set.hh"
+
+
+int
+main (int argc, char **argv)
+{
+
+ /* Test copy constructor. */
+ {
+ hb_set_t v1 {1, 2};
+ hb_set_t v2 {v1};
+ assert (v1.get_population () == 2);
+ assert (v2.get_population () == 2);
+ }
+
+ /* Test copy assignment. */
+ {
+ hb_set_t v1 {1, 2};
+ hb_set_t v2 = v1;
+ assert (v1.get_population () == 2);
+ assert (v2.get_population () == 2);
+ }
+
+ /* Test move constructor. */
+ {
+ hb_set_t v {hb_set_t {1, 2}};
+ assert (v.get_population () == 2);
+ }
+
+ /* Test move assignment. */
+ {
+ hb_set_t v;
+ v = hb_set_t {1, 2};
+ assert (v.get_population () == 2);
+ }
+ /* Test initializing set from iterable. */
+ {
+ hb_set_t s;
+
+ s.add (18);
+ s.add (12);
+
+ hb_set_t v (s);
+
+ assert (v.get_population () == 2);
+ }
+
+ /* Test initializing set from iterator. */
+ {
+ hb_set_t s;
+
+ s.add (18);
+ s.add (12);
+
+ hb_set_t v (hb_iter (s));
+
+ assert (v.get_population () == 2);
+ }
+
+ /* Test initializing set from initializer list and swapping. */
+ {
+ hb_set_t v1 {1, 2, 3};
+ hb_set_t v2 {4, 5};
+ hb_swap (v1, v2);
+ assert (v1.get_population () == 2);
+ assert (v2.get_population () == 3);
+ }
+
+ return 0;
+}