[set] Fix set copy/move constructors to actually work

Ouch!
This commit is contained in:
Behdad Esfahbod 2022-05-12 12:58:07 -06:00
parent 76fc27713f
commit a09dd87ca3
2 changed files with 24 additions and 11 deletions

View File

@ -44,7 +44,7 @@ struct hb_sparseset_t
hb_sparseset_t (const hb_sparseset_t& other) : hb_sparseset_t () { set (other); }
hb_sparseset_t (hb_sparseset_t&& other) : hb_sparseset_t () { s = std::move (other.s); }
hb_sparseset_t& operator= (const hb_sparseset_t& other) { set (other); return *this; }
hb_sparseset_t& operator= (hb_sparseset_t&& other) { s = std::move (other.s); return *this; }
hb_sparseset_t& operator= (hb_sparseset_t&& other) { s = std::move (other.s); 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> lst) : hb_sparseset_t ()
@ -158,15 +158,19 @@ struct hb_sparseset_t
struct hb_set_t : hb_sparseset_t<hb_bit_set_invertible_t>
{
hb_set_t () = default;
using sparseset = hb_sparseset_t<hb_bit_set_invertible_t>;
~hb_set_t () = default;
hb_set_t (hb_set_t&) = default;
hb_set_t () : sparseset () {};
hb_set_t (const hb_set_t &o) : sparseset ((sparseset &) o) {};
hb_set_t (hb_set_t&& o) : sparseset (std::move ((sparseset &) o)) {}
hb_set_t& operator= (const hb_set_t&) = default;
hb_set_t& operator= (hb_set_t&&) = default;
hb_set_t (std::initializer_list<hb_codepoint_t> lst) : hb_sparseset_t<hb_bit_set_invertible_t> (lst) {}
hb_set_t (std::initializer_list<hb_codepoint_t> lst) : sparseset (lst) {}
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_requires (hb_is_iterable (Iterable) &&
!hb_is_same (hb_decay<Iterable>, hb_set_t))>
hb_set_t (const Iterable &o) : sparseset (o) {}
};
static_assert (hb_set_t::INVALID == HB_SET_VALUE_INVALID, "");

View File

@ -42,21 +42,24 @@ main (int argc, char **argv)
/* Test copy assignment. */
{
hb_set_t v1 {1, 2};
hb_set_t v2 = v1;
hb_set_t v2;
v2 = v1;
assert (v1.get_population () == 2);
assert (v2.get_population () == 2);
}
/* Test move constructor. */
{
hb_set_t v {hb_set_t {1, 2}};
hb_set_t v (hb_set_t {1, 2});
assert (v.get_population () == 2);
}
/* Test move assignment. */
{
hb_set_t s = hb_set_t {1, 2};
hb_set_t v;
v = hb_set_t {1, 2};
v = std::move (s);
assert (s.get_population () == 0);
assert (v.get_population () == 2);
}
@ -67,9 +70,15 @@ main (int argc, char **argv)
s.add (18);
s.add (12);
hb_set_t v (s);
hb_vector_t<hb_codepoint_t> v (s);
hb_set_t v0 (v);
hb_set_t v1 (s);
hb_set_t v2 (std::move (s));
assert (v.get_population () == 2);
assert (s.get_population () == 0);
assert (v0.get_population () == 2);
assert (v1.get_population () == 2);
assert (v2.get_population () == 2);
}
/* Test initializing from iterator. */