diff --git a/src/Makefile.am b/src/Makefile.am index f405331d6..c0c77055e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -342,7 +342,20 @@ test_gsub_would_substitute_SOURCES = test-gsub-would-substitute.cc test_gsub_would_substitute_CPPFLAGS = $(HBCFLAGS) $(FREETYPE_CFLAGS) test_gsub_would_substitute_LDADD = libharfbuzz.la $(HBLIBS) $(FREETYPE_LIBS) -COMPILED_TESTS = test-algs test-array test-iter test-meta test-number test-ot-tag test-priority-queue test-unicode-ranges test-bimap test-repacker +COMPILED_TESTS = \ + test-algs \ + test-array \ + test-iter \ + test-map \ + test-number \ + test-ot-tag \ + test-priority-queue \ + test-set \ + test-unicode-ranges \ + test-vector \ + test-bimap \ + test-repacker \ + $(NULL) COMPILED_TESTS_CPPFLAGS = $(HBCFLAGS) -DMAIN -UNDEBUG COMPILED_TESTS_LDADD = libharfbuzz.la $(HBLIBS) check_PROGRAMS += $(COMPILED_TESTS) @@ -368,9 +381,9 @@ test_iter_SOURCES = test-iter.cc hb-static.cc test_iter_CPPFLAGS = $(COMPILED_TESTS_CPPFLAGS) test_iter_LDADD = $(COMPILED_TESTS_LDADD) -test_meta_SOURCES = test-meta.cc hb-static.cc -test_meta_CPPFLAGS = $(COMPILED_TESTS_CPPFLAGS) -test_meta_LDADD = $(COMPILED_TESTS_LDADD) +test_map_SOURCES = test-map.cc hb-static.cc +test_map_CPPFLAGS = $(COMPILED_TESTS_CPPFLAGS) +test_map_LDADD = $(COMPILED_TESTS_LDADD) test_number_SOURCES = test-number.cc hb-number.cc test_number_CPPFLAGS = $(COMPILED_TESTS_CPPFLAGS) @@ -380,10 +393,18 @@ test_ot_tag_SOURCES = hb-ot-tag.cc 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-aat-layout-common.hh b/src/hb-aat-layout-common.hh index f20416c17..1dcbe9290 100644 --- a/src/hb-aat-layout-common.hh +++ b/src/hb-aat-layout-common.hh @@ -162,7 +162,7 @@ struct LookupSegmentArray TRACE_SANITIZE (this); return_trace (c->check_struct (this) && first <= last && - valuesZ.sanitize (c, base, last - first + 1, hb_forward (ds)...)); + valuesZ.sanitize (c, base, last - first + 1, std::forward (ds)...)); } HBGlyphID16 last; /* Last GlyphID in this segment */ diff --git a/src/hb-aat-layout-kerx-table.hh b/src/hb-aat-layout-kerx-table.hh index e4278f199..0354b47d5 100644 --- a/src/hb-aat-layout-kerx-table.hh +++ b/src/hb-aat-layout-kerx-table.hh @@ -775,11 +775,11 @@ struct KerxSubTable unsigned int subtable_type = get_type (); TRACE_DISPATCH (this, subtable_type); switch (subtable_type) { - case 0: return_trace (c->dispatch (u.format0, hb_forward (ds)...)); - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); - case 2: return_trace (c->dispatch (u.format2, hb_forward (ds)...)); - case 4: return_trace (c->dispatch (u.format4, hb_forward (ds)...)); - case 6: return_trace (c->dispatch (u.format6, hb_forward (ds)...)); + case 0: return_trace (c->dispatch (u.format0, std::forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); + case 2: return_trace (c->dispatch (u.format2, std::forward (ds)...)); + case 4: return_trace (c->dispatch (u.format4, std::forward (ds)...)); + case 6: return_trace (c->dispatch (u.format6, std::forward (ds)...)); default: return_trace (c->default_return_value ()); } } diff --git a/src/hb-aat-layout-morx-table.hh b/src/hb-aat-layout-morx-table.hh index 377ef8721..b77c1f4d4 100644 --- a/src/hb-aat-layout-morx-table.hh +++ b/src/hb-aat-layout-morx-table.hh @@ -906,11 +906,11 @@ struct ChainSubtable unsigned int subtable_type = get_type (); TRACE_DISPATCH (this, subtable_type); switch (subtable_type) { - case Rearrangement: return_trace (c->dispatch (u.rearrangement, hb_forward (ds)...)); - case Contextual: return_trace (c->dispatch (u.contextual, hb_forward (ds)...)); - case Ligature: return_trace (c->dispatch (u.ligature, hb_forward (ds)...)); - case Noncontextual: return_trace (c->dispatch (u.noncontextual, hb_forward (ds)...)); - case Insertion: return_trace (c->dispatch (u.insertion, hb_forward (ds)...)); + case Rearrangement: return_trace (c->dispatch (u.rearrangement, std::forward (ds)...)); + case Contextual: return_trace (c->dispatch (u.contextual, std::forward (ds)...)); + case Ligature: return_trace (c->dispatch (u.ligature, std::forward (ds)...)); + case Noncontextual: return_trace (c->dispatch (u.noncontextual, std::forward (ds)...)); + case Insertion: return_trace (c->dispatch (u.insertion, std::forward (ds)...)); default: return_trace (c->default_return_value ()); } } diff --git a/src/hb-algs.hh b/src/hb-algs.hh index fc1aeb0bf..446d87e28 100644 --- a/src/hb-algs.hh +++ b/src/hb-algs.hh @@ -35,6 +35,8 @@ #include "hb-number.hh" #include +#include +#include /* * Flags @@ -126,7 +128,7 @@ struct BEInt template struct BEInt { - static_assert (!hb_is_signed (Type), ""); + static_assert (!std::is_signed::value, ""); public: BEInt () = default; constexpr BEInt (Type V) : v {uint8_t ((V >> 16) & 0xFF), @@ -180,7 +182,7 @@ struct { /* Note. This is dangerous in that if it's passed an rvalue, it returns rvalue-reference. */ template constexpr auto - operator () (T&& v) const HB_AUTO_RETURN ( hb_forward (v) ) + operator () (T&& v) const HB_AUTO_RETURN ( std::forward (v) ) } HB_FUNCOBJ (hb_identity); struct @@ -204,7 +206,7 @@ HB_FUNCOBJ (hb_ridentity); struct { template constexpr bool - operator () (T&& v) const { return bool (hb_forward (v)); } + operator () (T&& v) const { return bool (std::forward (v)); } } HB_FUNCOBJ (hb_bool); @@ -216,7 +218,7 @@ struct impl (const T& v, hb_priority<1>) const HB_RETURN (uint32_t, hb_deref (v).hash ()) template constexpr auto + hb_enable_if (std::is_integral::value)> constexpr auto impl (const T& v, hb_priority<0>) const HB_AUTO_RETURN ( /* Knuth's multiplicative method: */ @@ -238,26 +240,26 @@ struct /* Pointer-to-member-function. */ template auto impl (Appl&& a, hb_priority<2>, T &&v, Ts&&... ds) const HB_AUTO_RETURN - ((hb_deref (hb_forward (v)).*hb_forward (a)) (hb_forward (ds)...)) + ((hb_deref (std::forward (v)).*std::forward (a)) (std::forward (ds)...)) /* Pointer-to-member. */ template auto impl (Appl&& a, hb_priority<1>, T &&v) const HB_AUTO_RETURN - ((hb_deref (hb_forward (v))).*hb_forward (a)) + ((hb_deref (std::forward (v))).*std::forward (a)) /* Operator(). */ template auto impl (Appl&& a, hb_priority<0>, Ts&&... ds) const HB_AUTO_RETURN - (hb_deref (hb_forward (a)) (hb_forward (ds)...)) + (hb_deref (std::forward (a)) (std::forward (ds)...)) public: template auto operator () (Appl&& a, Ts&&... ds) const HB_AUTO_RETURN ( - impl (hb_forward (a), + impl (std::forward (a), hb_prioritize, - hb_forward (ds)...) + std::forward (ds)...) ) } HB_FUNCOBJ (hb_invoke); @@ -276,9 +278,9 @@ struct hb_partial_t hb_declval (V), hb_declval (Ts)...)) { - return hb_invoke (hb_forward (a), - hb_forward (v), - hb_forward (ds)...); + return hb_invoke (std::forward (a), + std::forward (v), + std::forward (ds)...); } template (a), - hb_forward (d0), - hb_forward (v), - hb_forward (ds)...); + return hb_invoke (std::forward (a), + std::forward (d0), + std::forward (v), + std::forward (ds)...); } private: @@ -325,14 +327,14 @@ auto hb_partial (Appl&& a, V&& v) HB_AUTO_RETURN #define HB_PARTIALIZE(Pos) \ template \ decltype(auto) operator () (_T&& _v) const \ - { return hb_partial (this, hb_forward<_T> (_v)); } \ + { return hb_partial (this, std::forward<_T> (_v)); } \ static_assert (true, "") #else /* https://github.com/harfbuzz/harfbuzz/issues/1724 */ #define HB_PARTIALIZE(Pos) \ template \ auto operator () (_T&& _v) const HB_AUTO_RETURN \ - (hb_partial (+this, hb_forward<_T> (_v))) \ + (hb_partial (+this, std::forward<_T> (_v))) \ static_assert (true, "") #endif @@ -344,22 +346,22 @@ struct template auto impl (Pred&& p, Val &&v, hb_priority<1>) const HB_AUTO_RETURN ( - hb_deref (hb_forward (p)).has (hb_forward (v)) + hb_deref (std::forward (p)).has (std::forward (v)) ) template auto impl (Pred&& p, Val &&v, hb_priority<0>) const HB_AUTO_RETURN ( - hb_invoke (hb_forward (p), - hb_forward (v)) + hb_invoke (std::forward (p), + std::forward (v)) ) public: template auto operator () (Pred&& p, Val &&v) const HB_RETURN (bool, - impl (hb_forward (p), - hb_forward (v), + impl (std::forward (p), + std::forward (v), hb_prioritize) ) } @@ -372,22 +374,22 @@ struct template auto impl (Pred&& p, Val &&v, hb_priority<1>) const HB_AUTO_RETURN ( - hb_has (hb_forward (p), - hb_forward (v)) + hb_has (std::forward (p), + std::forward (v)) ) template auto impl (Pred&& p, Val &&v, hb_priority<0>) const HB_AUTO_RETURN ( - hb_forward (p) == hb_forward (v) + std::forward (p) == std::forward (v) ) public: template auto operator () (Pred&& p, Val &&v) const HB_RETURN (bool, - impl (hb_forward (p), - hb_forward (v), + impl (std::forward (p), + std::forward (v), hb_prioritize) ) } @@ -400,20 +402,20 @@ struct template auto impl (Proj&& f, Val &&v, hb_priority<2>) const HB_AUTO_RETURN ( - hb_deref (hb_forward (f)).get (hb_forward (v)) + hb_deref (std::forward (f)).get (std::forward (v)) ) template auto impl (Proj&& f, Val &&v, hb_priority<1>) const HB_AUTO_RETURN ( - hb_invoke (hb_forward (f), - hb_forward (v)) + hb_invoke (std::forward (f), + std::forward (v)) ) template auto impl (Proj&& f, Val &&v, hb_priority<0>) const HB_AUTO_RETURN ( - hb_forward (f)[hb_forward (v)] + std::forward (f)[std::forward (v)] ) public: @@ -421,8 +423,8 @@ struct template auto operator () (Proj&& f, Val &&v) const HB_AUTO_RETURN ( - impl (hb_forward (f), - hb_forward (v), + impl (std::forward (f), + std::forward (v), hb_prioritize) ) } @@ -435,19 +437,19 @@ struct template auto impl (T1&& v1, T2 &&v2, hb_priority<2>) const HB_AUTO_RETURN ( - hb_forward (v2).cmp (hb_forward (v1)) == 0 + std::forward (v2).cmp (std::forward (v1)) == 0 ) template auto impl (T1&& v1, T2 &&v2, hb_priority<1>) const HB_AUTO_RETURN ( - hb_forward (v1).cmp (hb_forward (v2)) == 0 + std::forward (v1).cmp (std::forward (v2)) == 0 ) template auto impl (T1&& v1, T2 &&v2, hb_priority<0>) const HB_AUTO_RETURN ( - hb_forward (v1) == hb_forward (v2) + std::forward (v1) == std::forward (v2) ) public: @@ -455,8 +457,8 @@ struct template auto operator () (T1&& v1, T2 &&v2) const HB_AUTO_RETURN ( - impl (hb_forward (v1), - hb_forward (v2), + impl (std::forward (v1), + std::forward (v2), hb_prioritize) ) } @@ -516,21 +518,21 @@ struct { template constexpr auto operator () (T&& a, T2&& b) const HB_AUTO_RETURN - (a <= b ? hb_forward (a) : hb_forward (b)) + (a <= b ? std::forward (a) : std::forward (b)) } HB_FUNCOBJ (hb_min); struct { template constexpr auto operator () (T&& a, T2&& b) const HB_AUTO_RETURN - (a >= b ? hb_forward (a) : hb_forward (b)) + (a >= b ? std::forward (a) : std::forward (b)) } HB_FUNCOBJ (hb_max); struct { template constexpr auto operator () (T&& x, T2&& min, T3&& max) const HB_AUTO_RETURN - (hb_min (hb_max (hb_forward (x), hb_forward (min)), hb_forward (max))) + (hb_min (hb_max (std::forward (x), std::forward (min)), std::forward (max))) } HB_FUNCOBJ (hb_clamp); @@ -806,7 +808,7 @@ hb_ceil_to_4 (unsigned int v) template static inline bool hb_in_range (T u, T lo, T hi) { - static_assert (!hb_is_signed::value, ""); + static_assert (!std::is_signed::value, ""); /* The casts below are important as if T is smaller than int, * the subtract results will become a signed int! */ diff --git a/src/hb-array.hh b/src/hb-array.hh index ab0dd6ebe..8cae3c995 100644 --- a/src/hb-array.hh +++ b/src/hb-array.hh @@ -50,10 +50,11 @@ struct hb_array_t : hb_iter_with_fallback_t, Type&> /* * Constructors. */ - hb_array_t () : arrayZ (nullptr), length (0), backwards_length (0) {} - hb_array_t (Type *array_, unsigned int length_) : arrayZ (array_), length (length_), backwards_length (0) {} + hb_array_t () = default; + ~hb_array_t () = default; + hb_array_t (Type *array_, unsigned int length_) : arrayZ (array_), length (length_) {} template - hb_array_t (Type (&array_)[length_]) : arrayZ (array_), length (length_), backwards_length (0) {} + hb_array_t (Type (&array_)[length_]) : hb_array_t (array_, length_) {} template @@ -281,9 +282,9 @@ struct hb_array_t : hb_iter_with_fallback_t, Type&> */ public: - Type *arrayZ; - unsigned int length; - unsigned int backwards_length; + Type *arrayZ = nullptr; + unsigned int length = 0; + unsigned int backwards_length = 0; }; template inline hb_array_t hb_array (T *array, unsigned int length) @@ -302,7 +303,7 @@ struct hb_sorted_array_t : static constexpr bool is_random_access_iterator = true; static constexpr bool is_sorted_iterator = true; - hb_sorted_array_t () : hb_array_t () {} + hb_sorted_array_t () = default; hb_sorted_array_t (Type *array_, unsigned int length_) : hb_array_t (array_, length_) {} template hb_sorted_array_t (Type (&array_)[length_]) : hb_array_t (array_) {} diff --git a/src/hb-bimap.hh b/src/hb-bimap.hh index d40988075..d466af8b6 100644 --- a/src/hb-bimap.hh +++ b/src/hb-bimap.hh @@ -33,15 +33,14 @@ /* Bi-directional map */ struct hb_bimap_t { - hb_bimap_t () { init (); } - ~hb_bimap_t () { fini (); } - + /* XXX(remove) */ void init () { forw_map.init (); back_map.init (); } + /* XXX(remove) */ void fini () { forw_map.fini (); @@ -99,14 +98,6 @@ struct hb_bimap_t /* Inremental bimap: only lhs is given, rhs is incrementally assigned */ struct hb_inc_bimap_t : hb_bimap_t { - hb_inc_bimap_t () { init (); } - - void init () - { - hb_bimap_t::init (); - next_value = 0; - } - /* Add a mapping from lhs to rhs with a unique value if lhs is unknown. * Return the rhs value as the result. */ @@ -165,7 +156,7 @@ struct hb_inc_bimap_t : hb_bimap_t } protected: - unsigned int next_value; + unsigned int next_value = 0; }; #endif /* HB_BIMAP_HH */ diff --git a/src/hb-bit-set-invertible.hh b/src/hb-bit-set-invertible.hh index f48b72fe6..0832b0fc2 100644 --- a/src/hb-bit-set-invertible.hh +++ b/src/hb-bit-set-invertible.hh @@ -35,10 +35,20 @@ struct hb_bit_set_invertible_t { hb_bit_set_t s; - bool inverted; + bool inverted = false; - hb_bit_set_invertible_t () { init (); } - ~hb_bit_set_invertible_t () { fini (); } + hb_bit_set_invertible_t () = default; + hb_bit_set_invertible_t (hb_bit_set_invertible_t& o) = default; + hb_bit_set_invertible_t (hb_bit_set_invertible_t&& o) = default; + hb_bit_set_invertible_t& operator= (const hb_bit_set_invertible_t& o) = default; + hb_bit_set_invertible_t& operator= (hb_bit_set_invertible_t&& o) = default; + friend void swap (hb_bit_set_invertible_t &a, hb_bit_set_invertible_t &b) + { + if (likely (!a.s.successful || !b.s.successful)) + return; + hb_swap (a.inverted, b.inverted); + hb_swap (a.s, b.s); + } void init () { s.init (); inverted = false; } void fini () { s.fini (); } diff --git a/src/hb-bit-set.hh b/src/hb-bit-set.hh index c21778d88..a471ee48b 100644 --- a/src/hb-bit-set.hh +++ b/src/hb-bit-set.hh @@ -35,13 +35,22 @@ struct hb_bit_set_t { - hb_bit_set_t () { init (); } - ~hb_bit_set_t () { fini (); } + hb_bit_set_t () = default; + ~hb_bit_set_t () = default; hb_bit_set_t (const hb_bit_set_t& other) : hb_bit_set_t () { set (other); } - void operator= (const hb_bit_set_t& other) { set (other); } - // TODO Add move construtor/assign - // TODO Add constructor for Iterator; with specialization for (sorted) vector / array? + hb_bit_set_t ( hb_bit_set_t&& other) : hb_bit_set_t () { hb_swap (*this, other); } + hb_bit_set_t& operator= (const hb_bit_set_t& other) { set (other); return *this; } + hb_bit_set_t& operator= (hb_bit_set_t&& other) { hb_swap (*this, other); return *this; } + friend void swap (hb_bit_set_t &a, hb_bit_set_t &b) + { + if (likely (!a.successful || !b.successful)) + return; + hb_swap (a.population, b.population); + hb_swap (a.last_page_lookup, b.last_page_lookup); + hb_swap (a.page_map, b.page_map); + hb_swap (a.pages, b.pages); + } void init () { @@ -67,9 +76,9 @@ struct hb_bit_set_t uint32_t index; }; - bool successful; /* Allocations successful */ - mutable unsigned int population; - mutable unsigned int last_page_lookup; + bool successful = true; /* Allocations successful */ + mutable unsigned int population = 0; + mutable unsigned int last_page_lookup = 0; hb_sorted_vector_t page_map; hb_vector_t pages; diff --git a/src/hb-debug.hh b/src/hb-debug.hh index f80c8980b..3ac7440e8 100644 --- a/src/hb-debug.hh +++ b/src/hb-debug.hh @@ -302,7 +302,7 @@ struct hb_auto_trace_t { if (unlikely (returned)) { fprintf (stderr, "OUCH, double calls to return_trace(). This is a bug, please report.\n"); - return hb_forward (v); + return std::forward (v); } _hb_debug_msg (what, obj, func, true, plevel ? *plevel : 1, -1, @@ -311,7 +311,7 @@ struct hb_auto_trace_t if (plevel) --*plevel; plevel = nullptr; returned = true; - return hb_forward (v); + return std::forward (v); } private: @@ -333,7 +333,7 @@ struct hb_auto_trace_t<0, ret_t> template T ret (T&& v, const char *func HB_UNUSED = nullptr, - unsigned int line HB_UNUSED = 0) { return hb_forward (v); } + unsigned int line HB_UNUSED = 0) { return std::forward (v); } }; /* For disabled tracing; optimize out everything. @@ -343,7 +343,7 @@ struct hb_no_trace_t { template T ret (T&& v, const char *func HB_UNUSED = nullptr, - unsigned int line HB_UNUSED = 0) { return hb_forward (v); } + unsigned int line HB_UNUSED = 0) { return std::forward (v); } }; #define return_trace(RET) return trace.ret (RET, HB_FUNC, __LINE__) diff --git a/src/hb-dispatch.hh b/src/hb-dispatch.hh index 4b2b65a8d..37ca68146 100644 --- a/src/hb-dispatch.hh +++ b/src/hb-dispatch.hh @@ -50,7 +50,7 @@ struct hb_dispatch_context_t bool may_dispatch (const T *obj HB_UNUSED, const F *format HB_UNUSED) { return true; } template return_t dispatch (const T &obj, Ts&&... ds) - { return obj.dispatch (thiz (), hb_forward (ds)...); } + { return obj.dispatch (thiz (), std::forward (ds)...); } static return_t no_dispatch_return_value () { return Context::default_return_value (); } static bool stop_sublookup_iteration (const return_t r HB_UNUSED) { return false; } unsigned debug_depth = 0; diff --git a/src/hb-iter.hh b/src/hb-iter.hh index b8c447263..87b8ed880 100644 --- a/src/hb-iter.hh +++ b/src/hb-iter.hh @@ -162,7 +162,7 @@ struct { template hb_iter_type operator () (T&& c) const - { return hb_deref (hb_forward (c)).iter (); } + { return hb_deref (std::forward (c)).iter (); } /* Specialization for C arrays. */ @@ -353,7 +353,7 @@ static inline auto end (Iterable&& iterable) HB_AUTO_RETURN (hb_iter (iterable). template static inline auto -operator | (Lhs&& lhs, Rhs&& rhs) HB_AUTO_RETURN (hb_forward (rhs) (hb_forward (lhs))) +operator | (Lhs&& lhs, Rhs&& rhs) HB_AUTO_RETURN (std::forward (rhs) (std::forward (lhs))) /* hb_map(), hb_filter(), hb_reduce() */ @@ -674,8 +674,8 @@ struct hb_iota_iter_t : template auto inc (hb_type_identity s, hb_priority<1>) - -> hb_void_t (s), hb_declval ()))> - { v = hb_invoke (hb_forward (s), v); } + -> hb_void_t (s), hb_declval ()))> + { v = hb_invoke (std::forward (s), v); } void inc (S s, hb_priority<0>) @@ -874,7 +874,7 @@ struct Proj&& f = hb_identity) const { for (auto it = hb_iter (c); it; ++it) - if (!hb_match (hb_forward (p), hb_get (hb_forward (f), *it))) + if (!hb_match (std::forward (p), hb_get (std::forward (f), *it))) return false; return true; } @@ -891,7 +891,7 @@ struct Proj&& f = hb_identity) const { for (auto it = hb_iter (c); it; ++it) - if (hb_match (hb_forward (p), hb_get (hb_forward (f), *it))) + if (hb_match (std::forward (p), hb_get (std::forward (f), *it))) return true; return false; } @@ -908,7 +908,7 @@ struct Proj&& f = hb_identity) const { for (auto it = hb_iter (c); it; ++it) - if (hb_match (hb_forward (p), hb_get (hb_forward (f), *it))) + if (hb_match (std::forward (p), hb_get (std::forward (f), *it))) return false; return true; } diff --git a/src/hb-map.hh b/src/hb-map.hh index dcd5267d7..790457f26 100644 --- a/src/hb-map.hh +++ b/src/hb-map.hh @@ -35,16 +35,32 @@ */ template + K kINVALID = hb_is_pointer (K) ? 0 : std::is_signed::value ? hb_int_min (K) : (K) -1, + V vINVALID = hb_is_pointer (V) ? 0 : std::is_signed::value ? hb_int_min (V) : (V) -1> struct hb_hashmap_t { - HB_DELETE_COPY_ASSIGN (hb_hashmap_t); hb_hashmap_t () { init (); } ~hb_hashmap_t () { fini (); } - static_assert (hb_is_integral (K) || hb_is_pointer (K), ""); - static_assert (hb_is_integral (V) || hb_is_pointer (V), ""); + hb_hashmap_t (const hb_hashmap_t& o) : hb_hashmap_t () { hb_copy (o, *this); } + hb_hashmap_t (hb_hashmap_t&& o) : hb_hashmap_t () { hb_swap (*this, o); } + hb_hashmap_t& operator= (const hb_hashmap_t&& o) { hb_copy (o, *this); return *this; } + hb_hashmap_t& operator= (hb_hashmap_t&& o) { hb_swap (*this, o); return *this; } + + hb_hashmap_t (std::initializer_list> lst) : hb_hashmap_t () + { + for (auto&& item : lst) + set (item.first, item.second); + } + template + hb_hashmap_t (const Iterable &o) : hb_hashmap_t () + { + hb_copy (o, *this); + } + + static_assert (std::is_integral::value || hb_is_pointer (K), ""); + static_assert (std::is_integral::value || hb_is_pointer (V), ""); struct item_t { @@ -70,6 +86,16 @@ struct hb_hashmap_t unsigned int prime; item_t *items; + friend void swap (hb_hashmap_t& a, hb_hashmap_t& b) + { + if (unlikely (!a.successful || !b.successful)) + return; + hb_swap (a.population, b.population); + hb_swap (a.occupancy, b.occupancy); + hb_swap (a.mask, b.mask); + hb_swap (a.prime, b.prime); + hb_swap (a.items, b.items); + } void init_shallow () { successful = true; @@ -133,17 +159,15 @@ struct hb_hashmap_t if (old_items[i].is_real ()) set_with_hash (old_items[i].key, old_items[i].hash, - old_items[i].value); + std::move (old_items[i].value)); hb_free (old_items); return true; } - bool set (K key, V value) - { - return set_with_hash (key, hb_hash (key), value); - } + bool set (K key, const V& value) { return set_with_hash (key, hb_hash (key), value); } + bool set (K key, V&& value) { return set_with_hash (key, hb_hash (key), std::move (value)); } V get (K key) const { @@ -213,7 +237,8 @@ struct hb_hashmap_t protected: - bool set_with_hash (K key, uint32_t hash, V value) + template + bool set_with_hash (K key, uint32_t hash, VV&& value) { if (unlikely (!successful)) return false; if (unlikely (key == kINVALID)) return true; @@ -321,7 +346,22 @@ struct hb_hashmap_t struct hb_map_t : hb_hashmap_t {}; + HB_MAP_VALUE_INVALID> +{ + using hashmap = hb_hashmap_t; + hb_map_t () = default; + ~hb_map_t () = default; + hb_map_t (hb_map_t& o) = default; + hb_map_t& operator= (const hb_map_t& other) = default; + hb_map_t& operator= (hb_map_t&& other) = default; + hb_map_t (std::initializer_list> lst) : hashmap (lst) {} + template + hb_map_t (const Iterable &o) : hashmap (o) {} +}; #endif /* HB_MAP_HH */ diff --git a/src/hb-meta.hh b/src/hb-meta.hh index a714bc2bf..0ea5774a9 100644 --- a/src/hb-meta.hh +++ b/src/hb-meta.hh @@ -29,6 +29,9 @@ #include "hb.hh" +#include +#include + /* * C++ template meta-programming & fundamentals used with them. @@ -129,40 +132,7 @@ template using hb_add_pointer = decltype (_hb_try_add_pointer (h /* TODO Add feature-parity to std::decay. */ template using hb_decay = hb_remove_const>; - -template -struct _hb_conditional { typedef T type; }; -template -struct _hb_conditional { typedef F type; }; -template -using hb_conditional = typename _hb_conditional::type; - - -template -struct hb_is_convertible -{ - private: - static constexpr bool from_void = hb_is_same (void, hb_decay); - static constexpr bool to_void = hb_is_same (void, hb_decay ); - static constexpr bool either_void = from_void || to_void; - static constexpr bool both_void = from_void && to_void; - - static hb_true_type impl2 (hb_conditional); - - template - static auto impl (hb_priority<1>) -> decltype (impl2 (hb_declval (T))); - template - static hb_false_type impl (hb_priority<0>); - public: - static constexpr bool value = both_void || - (!either_void && - decltype (impl> (hb_prioritize))::value); -}; -#define hb_is_convertible(From,To) hb_is_convertible::value - -template -using hb_is_base_of = hb_is_convertible *, hb_decay *>; -#define hb_is_base_of(Base,Derived) hb_is_base_of::value +#define hb_is_convertible(From,To) std::is_convertible::value template using hb_is_cr_convertible = hb_bool_constant< @@ -172,20 +142,11 @@ using hb_is_cr_convertible = hb_bool_constant< >; #define hb_is_cr_convertible(From,To) hb_is_cr_convertible::value -/* std::move and std::forward */ - -template -static constexpr hb_remove_reference&& hb_move (T&& t) { return (hb_remove_reference&&) (t); } - -template -static constexpr T&& hb_forward (hb_remove_reference& t) { return (T&&) t; } -template -static constexpr T&& hb_forward (hb_remove_reference&& t) { return (T&&) t; } struct { template constexpr auto - operator () (T&& v) const HB_AUTO_RETURN (hb_forward (v)) + operator () (T&& v) const HB_AUTO_RETURN (std::forward (v)) template constexpr auto operator () (T *v) const HB_AUTO_RETURN (*v) @@ -195,7 +156,7 @@ HB_FUNCOBJ (hb_deref); struct { template constexpr auto - operator () (T&& v) const HB_AUTO_RETURN (hb_forward (v)) + operator () (T&& v) const HB_AUTO_RETURN (std::forward (v)) template constexpr auto operator () (T& v) const HB_AUTO_RETURN (hb_addressof (v)) @@ -226,50 +187,6 @@ struct hb_reference_wrapper /* Type traits */ -template -using hb_is_integral = hb_bool_constant< - hb_is_same (hb_decay, char) || - hb_is_same (hb_decay, signed char) || - hb_is_same (hb_decay, unsigned char) || - hb_is_same (hb_decay, signed int) || - hb_is_same (hb_decay, unsigned int) || - hb_is_same (hb_decay, signed short) || - hb_is_same (hb_decay, unsigned short) || - hb_is_same (hb_decay, signed long) || - hb_is_same (hb_decay, unsigned long) || - hb_is_same (hb_decay, signed long long) || - hb_is_same (hb_decay, unsigned long long) || - false ->; -#define hb_is_integral(T) hb_is_integral::value -template -using hb_is_floating_point = hb_bool_constant< - hb_is_same (hb_decay, float) || - hb_is_same (hb_decay, double) || - hb_is_same (hb_decay, long double) || - false ->; -#define hb_is_floating_point(T) hb_is_floating_point::value -template -using hb_is_arithmetic = hb_bool_constant< - hb_is_integral (T) || - hb_is_floating_point (T) || - false ->; -#define hb_is_arithmetic(T) hb_is_arithmetic::value - - -template struct hb_is_signed_; -template struct hb_is_signed_ : hb_false_type {}; -template struct hb_is_signed_ : hb_bool_constant<(T) -1 < (T) 0> {}; -template struct hb_is_signed : hb_is_signed_ {}; -#define hb_is_signed(T) hb_is_signed::value -template struct hb_is_unsigned_; -template struct hb_is_unsigned_ : hb_false_type {}; -template struct hb_is_unsigned_ : hb_bool_constant<(T) 0 < (T) -1> {}; -template struct hb_is_unsigned : hb_is_unsigned_ {}; -#define hb_is_unsigned(T) hb_is_unsigned::value - template struct hb_int_min; template <> struct hb_int_min : hb_integral_constant {}; template <> struct hb_int_min : hb_integral_constant {}; @@ -309,108 +226,6 @@ template <> struct hb_int_max : hb_integral_constant -struct _hb_is_destructible : hb_false_type {}; -template -struct _hb_is_destructible> : hb_true_type {}; -template -using hb_is_destructible = _hb_is_destructible; -#define hb_is_destructible(T) hb_is_destructible::value - -template -struct _hb_is_constructible : hb_false_type {}; -template -struct _hb_is_constructible, Ts...> : hb_true_type {}; -template -using hb_is_constructible = _hb_is_constructible; -#define hb_is_constructible(...) hb_is_constructible<__VA_ARGS__>::value - -template -using hb_is_default_constructible = hb_is_constructible; -#define hb_is_default_constructible(T) hb_is_default_constructible::value - -template -using hb_is_copy_constructible = hb_is_constructible>>; -#define hb_is_copy_constructible(T) hb_is_copy_constructible::value - -template -using hb_is_move_constructible = hb_is_constructible>>; -#define hb_is_move_constructible(T) hb_is_move_constructible::value - -template -struct _hb_is_assignable : hb_false_type {}; -template -struct _hb_is_assignable> : hb_true_type {}; -template -using hb_is_assignable = _hb_is_assignable; -#define hb_is_assignable(T,U) hb_is_assignable::value - -template -using hb_is_copy_assignable = hb_is_assignable, - hb_add_lvalue_reference>>; -#define hb_is_copy_assignable(T) hb_is_copy_assignable::value - -template -using hb_is_move_assignable = hb_is_assignable, - hb_add_rvalue_reference>; -#define hb_is_move_assignable(T) hb_is_move_assignable::value - -/* Trivial versions. */ - -template union hb_trivial { T value; }; - -template -using hb_is_trivially_destructible= hb_is_destructible>; -#define hb_is_trivially_destructible(T) hb_is_trivially_destructible::value - -/* Don't know how to do the following. */ -//template -//using hb_is_trivially_constructible= hb_is_constructible, hb_trivial...>; -//#define hb_is_trivially_constructible(...) hb_is_trivially_constructible<__VA_ARGS__>::value - -template -using hb_is_trivially_default_constructible= hb_is_default_constructible>; -#define hb_is_trivially_default_constructible(T) hb_is_trivially_default_constructible::value - -template -using hb_is_trivially_copy_constructible= hb_is_copy_constructible>; -#define hb_is_trivially_copy_constructible(T) hb_is_trivially_copy_constructible::value - -template -using hb_is_trivially_move_constructible= hb_is_move_constructible>; -#define hb_is_trivially_move_constructible(T) hb_is_trivially_move_constructible::value - -/* Don't know how to do the following. */ -//template -//using hb_is_trivially_assignable= hb_is_assignable, hb_trivial>; -//#define hb_is_trivially_assignable(T,U) hb_is_trivially_assignable::value - -template -using hb_is_trivially_copy_assignable= hb_is_copy_assignable>; -#define hb_is_trivially_copy_assignable(T) hb_is_trivially_copy_assignable::value - -template -using hb_is_trivially_move_assignable= hb_is_move_assignable>; -#define hb_is_trivially_move_assignable(T) hb_is_trivially_move_assignable::value - -template -using hb_is_trivially_copyable= hb_bool_constant< - hb_is_trivially_destructible (T) && - (!hb_is_move_assignable (T) || hb_is_trivially_move_assignable (T)) && - (!hb_is_move_constructible (T) || hb_is_trivially_move_constructible (T)) && - (!hb_is_copy_assignable (T) || hb_is_trivially_copy_assignable (T)) && - (!hb_is_copy_constructible (T) || hb_is_trivially_copy_constructible (T)) && - true ->; -#define hb_is_trivially_copyable(T) hb_is_trivially_copyable::value - -template -using hb_is_trivial= hb_bool_constant< - hb_is_trivially_copyable (T) && - hb_is_trivially_default_constructible (T) ->; -#define hb_is_trivial(T) hb_is_trivial::value - /* hb_unwrap_type (T) * If T has no T::type, returns T. Otherwise calls itself on T::type recursively. */ diff --git a/src/hb-mutex.hh b/src/hb-mutex.hh index 29c3f8b82..4e135027f 100644 --- a/src/hb-mutex.hh +++ b/src/hb-mutex.hh @@ -73,7 +73,6 @@ typedef CRITICAL_SECTION hb_mutex_impl_t; #elif !defined(HB_NO_MT) #include -#include typedef std::mutex hb_mutex_impl_t; #define hb_mutex_impl_init(M) HB_STMT_START { new (M) hb_mutex_impl_t; } HB_STMT_END #define hb_mutex_impl_lock(M) (M)->lock () diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh index 5199d1c48..7e524177f 100644 --- a/src/hb-open-type.hh +++ b/src/hb-open-type.hh @@ -64,7 +64,7 @@ struct IntType IntType& operator = (Type i) { v = i; return *this; } /* For reason we define cast out operator for signed/unsigned, instead of Type, see: * https://github.com/harfbuzz/harfbuzz/pull/2875/commits/09836013995cab2b9f07577a179ad7b024130467 */ - operator hb_conditional () const { return v; } + operator typename std::conditional::value, signed, unsigned>::type () const { return v; } bool operator == (const IntType &o) const { return (Type) v == (Type) o.v; } bool operator != (const IntType &o) const { return !(*this == o); } @@ -86,7 +86,7 @@ struct IntType return pb->cmp (*pa); } template ::value && sizeof (Type2) < sizeof (int) && sizeof (Type) < sizeof (int))> int cmp (Type2 a) const @@ -341,7 +341,7 @@ struct OffsetTo : Offset s->push (); - bool ret = c->dispatch (src_base+src, hb_forward (ds)...); + bool ret = c->dispatch (src_base+src, std::forward (ds)...); if (ret || !has_null) s->add_link (*this, s->pop_pack ()); @@ -358,7 +358,7 @@ struct OffsetTo : Offset *this = 0; Type* obj = c->push (); - bool ret = obj->serialize (c, hb_forward (ds)...); + bool ret = obj->serialize (c, std::forward (ds)...); if (ret) c->add_link (*this, c->pop_pack ()); @@ -384,7 +384,7 @@ struct OffsetTo : Offset c->push (); - bool ret = c->copy (src_base+src, hb_forward (ds)...); + bool ret = c->copy (src_base+src, std::forward (ds)...); c->add_link (*this, c->pop_pack (), whence, dst_bias); @@ -410,7 +410,7 @@ struct OffsetTo : Offset TRACE_SANITIZE (this); return_trace (sanitize_shallow (c, base) && (this->is_null () || - c->dispatch (StructAtOffset (base, *this), hb_forward (ds)...) || + c->dispatch (StructAtOffset (base, *this), std::forward (ds)...) || neuter (c))); } @@ -518,9 +518,9 @@ struct UnsizedArrayOf { TRACE_SANITIZE (this); if (unlikely (!sanitize_shallow (c, count))) return_trace (false); - if (!sizeof... (Ts) && hb_is_trivially_copyable (Type)) return_trace (true); + if (!sizeof... (Ts) && std::is_trivially_copyable::value) return_trace (true); for (unsigned int i = 0; i < count; i++) - if (unlikely (!c->dispatch (arrayZ[i], hb_forward (ds)...))) + if (unlikely (!c->dispatch (arrayZ[i], std::forward (ds)...))) return_trace (false); return_trace (true); } @@ -565,7 +565,7 @@ struct UnsizedListOfOffset16To : UnsizedArray16OfOffsetTo - ::sanitize (c, count, this, hb_forward (ds)...))); + ::sanitize (c, count, this, std::forward (ds)...))); } }; @@ -707,10 +707,10 @@ struct ArrayOf { TRACE_SANITIZE (this); if (unlikely (!sanitize_shallow (c))) return_trace (false); - if (!sizeof... (Ts) && hb_is_trivially_copyable (Type)) return_trace (true); + if (!sizeof... (Ts) && std::is_trivially_copyable::value) return_trace (true); unsigned int count = len; for (unsigned int i = 0; i < count; i++) - if (unlikely (!c->dispatch (arrayZ[i], hb_forward (ds)...))) + if (unlikely (!c->dispatch (arrayZ[i], std::forward (ds)...))) return_trace (false); return_trace (true); } @@ -768,7 +768,7 @@ struct List16OfOffset16To : Array16OfOffset16To bool sanitize (hb_sanitize_context_t *c, Ts&&... ds) const { TRACE_SANITIZE (this); - return_trace (Array16OfOffset16To::sanitize (c, this, hb_forward (ds)...)); + return_trace (Array16OfOffset16To::sanitize (c, this, std::forward (ds)...)); } }; @@ -835,10 +835,10 @@ struct HeadlessArrayOf { TRACE_SANITIZE (this); if (unlikely (!sanitize_shallow (c))) return_trace (false); - if (!sizeof... (Ts) && hb_is_trivially_copyable (Type)) return_trace (true); + if (!sizeof... (Ts) && std::is_trivially_copyable::value) return_trace (true); unsigned int count = get_length (); for (unsigned int i = 0; i < count; i++) - if (unlikely (!c->dispatch (arrayZ[i], hb_forward (ds)...))) + if (unlikely (!c->dispatch (arrayZ[i], std::forward (ds)...))) return_trace (false); return_trace (true); } @@ -884,10 +884,10 @@ struct ArrayOfM1 { TRACE_SANITIZE (this); if (unlikely (!sanitize_shallow (c))) return_trace (false); - if (!sizeof... (Ts) && hb_is_trivially_copyable (Type)) return_trace (true); + if (!sizeof... (Ts) && std::is_trivially_copyable::value) return_trace (true); unsigned int count = lenM1 + 1; for (unsigned int i = 0; i < count; i++) - if (unlikely (!c->dispatch (arrayZ[i], hb_forward (ds)...))) + if (unlikely (!c->dispatch (arrayZ[i], std::forward (ds)...))) return_trace (false); return_trace (true); } @@ -1070,10 +1070,10 @@ struct VarSizedBinSearchArrayOf { TRACE_SANITIZE (this); if (unlikely (!sanitize_shallow (c))) return_trace (false); - if (!sizeof... (Ts) && hb_is_trivially_copyable (Type)) return_trace (true); + if (!sizeof... (Ts) && std::is_trivially_copyable::value) return_trace (true); unsigned int count = get_length (); for (unsigned int i = 0; i < count; i++) - if (unlikely (!(*this)[i].sanitize (c, hb_forward (ds)...))) + if (unlikely (!(*this)[i].sanitize (c, std::forward (ds)...))) return_trace (false); return_trace (true); } diff --git a/src/hb-ot-cff-common.hh b/src/hb-ot-cff-common.hh index eaaf5e12e..180c87cb8 100644 --- a/src/hb-ot-cff-common.hh +++ b/src/hb-ot-cff-common.hh @@ -373,7 +373,7 @@ struct Dict : UnsizedByteStr { TRACE_SERIALIZE (this); for (unsigned int i = 0; i < dictval.get_count (); i++) - if (unlikely (!opszr.serialize (c, dictval[i], hb_forward (ds)...))) + if (unlikely (!opszr.serialize (c, dictval[i], std::forward (ds)...))) return_trace (false); return_trace (true); diff --git a/src/hb-ot-color-colr-table.hh b/src/hb-ot-color-colr-table.hh index 9f34e56fb..936ea0b99 100644 --- a/src/hb-ot-color-colr-table.hh +++ b/src/hb-ot-color-colr-table.hh @@ -925,8 +925,8 @@ struct ClipBox TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); - case 2: return_trace (c->dispatch (u.format2, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); + case 2: return_trace (c->dispatch (u.format2, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } @@ -1065,38 +1065,38 @@ struct Paint TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.paintformat1, hb_forward (ds)...)); - case 2: return_trace (c->dispatch (u.paintformat2, hb_forward (ds)...)); - case 3: return_trace (c->dispatch (u.paintformat3, hb_forward (ds)...)); - case 4: return_trace (c->dispatch (u.paintformat4, hb_forward (ds)...)); - case 5: return_trace (c->dispatch (u.paintformat5, hb_forward (ds)...)); - case 6: return_trace (c->dispatch (u.paintformat6, hb_forward (ds)...)); - case 7: return_trace (c->dispatch (u.paintformat7, hb_forward (ds)...)); - case 8: return_trace (c->dispatch (u.paintformat8, hb_forward (ds)...)); - case 9: return_trace (c->dispatch (u.paintformat9, hb_forward (ds)...)); - case 10: return_trace (c->dispatch (u.paintformat10, hb_forward (ds)...)); - case 11: return_trace (c->dispatch (u.paintformat11, hb_forward (ds)...)); - case 12: return_trace (c->dispatch (u.paintformat12, hb_forward (ds)...)); - case 13: return_trace (c->dispatch (u.paintformat13, hb_forward (ds)...)); - case 14: return_trace (c->dispatch (u.paintformat14, hb_forward (ds)...)); - case 15: return_trace (c->dispatch (u.paintformat15, hb_forward (ds)...)); - case 16: return_trace (c->dispatch (u.paintformat16, hb_forward (ds)...)); - case 17: return_trace (c->dispatch (u.paintformat17, hb_forward (ds)...)); - case 18: return_trace (c->dispatch (u.paintformat18, hb_forward (ds)...)); - case 19: return_trace (c->dispatch (u.paintformat19, hb_forward (ds)...)); - case 20: return_trace (c->dispatch (u.paintformat20, hb_forward (ds)...)); - case 21: return_trace (c->dispatch (u.paintformat21, hb_forward (ds)...)); - case 22: return_trace (c->dispatch (u.paintformat22, hb_forward (ds)...)); - case 23: return_trace (c->dispatch (u.paintformat23, hb_forward (ds)...)); - case 24: return_trace (c->dispatch (u.paintformat24, hb_forward (ds)...)); - case 25: return_trace (c->dispatch (u.paintformat25, hb_forward (ds)...)); - case 26: return_trace (c->dispatch (u.paintformat26, hb_forward (ds)...)); - case 27: return_trace (c->dispatch (u.paintformat27, hb_forward (ds)...)); - case 28: return_trace (c->dispatch (u.paintformat28, hb_forward (ds)...)); - case 29: return_trace (c->dispatch (u.paintformat29, hb_forward (ds)...)); - case 30: return_trace (c->dispatch (u.paintformat30, hb_forward (ds)...)); - case 31: return_trace (c->dispatch (u.paintformat31, hb_forward (ds)...)); - case 32: return_trace (c->dispatch (u.paintformat32, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.paintformat1, std::forward (ds)...)); + case 2: return_trace (c->dispatch (u.paintformat2, std::forward (ds)...)); + case 3: return_trace (c->dispatch (u.paintformat3, std::forward (ds)...)); + case 4: return_trace (c->dispatch (u.paintformat4, std::forward (ds)...)); + case 5: return_trace (c->dispatch (u.paintformat5, std::forward (ds)...)); + case 6: return_trace (c->dispatch (u.paintformat6, std::forward (ds)...)); + case 7: return_trace (c->dispatch (u.paintformat7, std::forward (ds)...)); + case 8: return_trace (c->dispatch (u.paintformat8, std::forward (ds)...)); + case 9: return_trace (c->dispatch (u.paintformat9, std::forward (ds)...)); + case 10: return_trace (c->dispatch (u.paintformat10, std::forward (ds)...)); + case 11: return_trace (c->dispatch (u.paintformat11, std::forward (ds)...)); + case 12: return_trace (c->dispatch (u.paintformat12, std::forward (ds)...)); + case 13: return_trace (c->dispatch (u.paintformat13, std::forward (ds)...)); + case 14: return_trace (c->dispatch (u.paintformat14, std::forward (ds)...)); + case 15: return_trace (c->dispatch (u.paintformat15, std::forward (ds)...)); + case 16: return_trace (c->dispatch (u.paintformat16, std::forward (ds)...)); + case 17: return_trace (c->dispatch (u.paintformat17, std::forward (ds)...)); + case 18: return_trace (c->dispatch (u.paintformat18, std::forward (ds)...)); + case 19: return_trace (c->dispatch (u.paintformat19, std::forward (ds)...)); + case 20: return_trace (c->dispatch (u.paintformat20, std::forward (ds)...)); + case 21: return_trace (c->dispatch (u.paintformat21, std::forward (ds)...)); + case 22: return_trace (c->dispatch (u.paintformat22, std::forward (ds)...)); + case 23: return_trace (c->dispatch (u.paintformat23, std::forward (ds)...)); + case 24: return_trace (c->dispatch (u.paintformat24, std::forward (ds)...)); + case 25: return_trace (c->dispatch (u.paintformat25, std::forward (ds)...)); + case 26: return_trace (c->dispatch (u.paintformat26, std::forward (ds)...)); + case 27: return_trace (c->dispatch (u.paintformat27, std::forward (ds)...)); + case 28: return_trace (c->dispatch (u.paintformat28, std::forward (ds)...)); + case 29: return_trace (c->dispatch (u.paintformat29, std::forward (ds)...)); + case 30: return_trace (c->dispatch (u.paintformat30, std::forward (ds)...)); + case 31: return_trace (c->dispatch (u.paintformat31, std::forward (ds)...)); + case 32: return_trace (c->dispatch (u.paintformat32, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } diff --git a/src/hb-ot-kern-table.hh b/src/hb-ot-kern-table.hh index 3563cab8b..ffa11bc24 100644 --- a/src/hb-ot-kern-table.hh +++ b/src/hb-ot-kern-table.hh @@ -134,11 +134,11 @@ struct KernSubTable switch (subtable_type) { case 0: return_trace (c->dispatch (u.format0)); #ifndef HB_NO_AAT_SHAPE - case 1: return_trace (u.header.apple ? c->dispatch (u.format1, hb_forward (ds)...) : c->default_return_value ()); + case 1: return_trace (u.header.apple ? c->dispatch (u.format1, std::forward (ds)...) : c->default_return_value ()); #endif case 2: return_trace (c->dispatch (u.format2)); #ifndef HB_NO_AAT_SHAPE - case 3: return_trace (u.header.apple ? c->dispatch (u.format3, hb_forward (ds)...) : c->default_return_value ()); + case 3: return_trace (u.header.apple ? c->dispatch (u.format3, std::forward (ds)...) : c->default_return_value ()); #endif default: return_trace (c->default_return_value ()); } @@ -325,9 +325,9 @@ struct kern unsigned int subtable_type = get_type (); TRACE_DISPATCH (this, subtable_type); switch (subtable_type) { - case 0: return_trace (c->dispatch (u.ot, hb_forward (ds)...)); + case 0: return_trace (c->dispatch (u.ot, std::forward (ds)...)); #ifndef HB_NO_AAT_SHAPE - case 1: return_trace (c->dispatch (u.aat, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.aat, std::forward (ds)...)); #endif default: return_trace (c->default_return_value ()); } diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh index 87ac8781d..a43f5f8c0 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -1286,7 +1286,7 @@ struct Lookup TRACE_DISPATCH (this, lookup_type); unsigned int count = get_subtable_count (); for (unsigned int i = 0; i < count; i++) { - typename context_t::return_t r = get_subtable (i).dispatch (c, lookup_type, hb_forward (ds)...); + typename context_t::return_t r = get_subtable (i).dispatch (c, lookup_type, std::forward (ds)...); if (c->stop_sublookup_iteration (r)) return_trace (r); } @@ -2984,7 +2984,7 @@ struct Condition TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } diff --git a/src/hb-ot-layout-gdef-table.hh b/src/hb-ot-layout-gdef-table.hh index 31a4a3e84..41c5a1e1a 100644 --- a/src/hb-ot-layout-gdef-table.hh +++ b/src/hb-ot-layout-gdef-table.hh @@ -248,9 +248,9 @@ struct CaretValue TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); - case 2: return_trace (c->dispatch (u.format2, hb_forward (ds)...)); - case 3: return_trace (c->dispatch (u.format3, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); + case 2: return_trace (c->dispatch (u.format2, std::forward (ds)...)); + case 3: return_trace (c->dispatch (u.format3, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } diff --git a/src/hb-ot-layout-gpos-table.hh b/src/hb-ot-layout-gpos-table.hh index ac8f6eaf8..a8fb5c7ac 100644 --- a/src/hb-ot-layout-gpos-table.hh +++ b/src/hb-ot-layout-gpos-table.hh @@ -1050,8 +1050,8 @@ struct SinglePos TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); - case 2: return_trace (c->dispatch (u.format2, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); + case 2: return_trace (c->dispatch (u.format2, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } @@ -1702,8 +1702,8 @@ struct PairPos TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); - case 2: return_trace (c->dispatch (u.format2, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); + case 2: return_trace (c->dispatch (u.format2, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } @@ -1959,7 +1959,7 @@ struct CursivePos TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } @@ -2194,7 +2194,7 @@ struct MarkBasePos TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } @@ -2434,7 +2434,7 @@ struct MarkLigPos TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } @@ -2653,7 +2653,7 @@ struct MarkMarkPos TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } @@ -2704,15 +2704,15 @@ struct PosLookupSubTable { TRACE_DISPATCH (this, lookup_type); switch (lookup_type) { - case Single: return_trace (u.single.dispatch (c, hb_forward (ds)...)); - case Pair: return_trace (u.pair.dispatch (c, hb_forward (ds)...)); - case Cursive: return_trace (u.cursive.dispatch (c, hb_forward (ds)...)); - case MarkBase: return_trace (u.markBase.dispatch (c, hb_forward (ds)...)); - case MarkLig: return_trace (u.markLig.dispatch (c, hb_forward (ds)...)); - case MarkMark: return_trace (u.markMark.dispatch (c, hb_forward (ds)...)); - case Context: return_trace (u.context.dispatch (c, hb_forward (ds)...)); - case ChainContext: return_trace (u.chainContext.dispatch (c, hb_forward (ds)...)); - case Extension: return_trace (u.extension.dispatch (c, hb_forward (ds)...)); + case Single: return_trace (u.single.dispatch (c, std::forward (ds)...)); + case Pair: return_trace (u.pair.dispatch (c, std::forward (ds)...)); + case Cursive: return_trace (u.cursive.dispatch (c, std::forward (ds)...)); + case MarkBase: return_trace (u.markBase.dispatch (c, std::forward (ds)...)); + case MarkLig: return_trace (u.markLig.dispatch (c, std::forward (ds)...)); + case MarkMark: return_trace (u.markMark.dispatch (c, std::forward (ds)...)); + case Context: return_trace (u.context.dispatch (c, std::forward (ds)...)); + case ChainContext: return_trace (u.chainContext.dispatch (c, std::forward (ds)...)); + case Extension: return_trace (u.extension.dispatch (c, std::forward (ds)...)); default: return_trace (c->default_return_value ()); } } @@ -2800,7 +2800,7 @@ struct PosLookup : Lookup template typename context_t::return_t dispatch (context_t *c, Ts&&... ds) const - { return Lookup::dispatch (c, hb_forward (ds)...); } + { return Lookup::dispatch (c, std::forward (ds)...); } bool subset (hb_subset_context_t *c) const { return Lookup::subset (c); } diff --git a/src/hb-ot-layout-gsub-table.hh b/src/hb-ot-layout-gsub-table.hh index 55edfd4da..0dcc98cc0 100644 --- a/src/hb-ot-layout-gsub-table.hh +++ b/src/hb-ot-layout-gsub-table.hh @@ -290,8 +290,8 @@ struct SingleSubst TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); - case 2: return_trace (c->dispatch (u.format2, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); + case 2: return_trace (c->dispatch (u.format2, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } @@ -524,7 +524,7 @@ struct MultipleSubst TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } @@ -767,7 +767,7 @@ struct AlternateSubst TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } @@ -1152,7 +1152,7 @@ struct LigatureSubst TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } @@ -1395,7 +1395,7 @@ struct ReverseChainSingleSubst TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } @@ -1434,14 +1434,14 @@ struct SubstLookupSubTable { TRACE_DISPATCH (this, lookup_type); switch (lookup_type) { - case Single: return_trace (u.single.dispatch (c, hb_forward (ds)...)); - case Multiple: return_trace (u.multiple.dispatch (c, hb_forward (ds)...)); - case Alternate: return_trace (u.alternate.dispatch (c, hb_forward (ds)...)); - case Ligature: return_trace (u.ligature.dispatch (c, hb_forward (ds)...)); - case Context: return_trace (u.context.dispatch (c, hb_forward (ds)...)); - case ChainContext: return_trace (u.chainContext.dispatch (c, hb_forward (ds)...)); - case Extension: return_trace (u.extension.dispatch (c, hb_forward (ds)...)); - case ReverseChainSingle: return_trace (u.reverseChainContextSingle.dispatch (c, hb_forward (ds)...)); + case Single: return_trace (u.single.dispatch (c, std::forward (ds)...)); + case Multiple: return_trace (u.multiple.dispatch (c, std::forward (ds)...)); + case Alternate: return_trace (u.alternate.dispatch (c, std::forward (ds)...)); + case Ligature: return_trace (u.ligature.dispatch (c, std::forward (ds)...)); + case Context: return_trace (u.context.dispatch (c, std::forward (ds)...)); + case ChainContext: return_trace (u.chainContext.dispatch (c, std::forward (ds)...)); + case Extension: return_trace (u.extension.dispatch (c, std::forward (ds)...)); + case ReverseChainSingle: return_trace (u.reverseChainContextSingle.dispatch (c, std::forward (ds)...)); default: return_trace (c->default_return_value ()); } } @@ -1667,7 +1667,7 @@ struct SubstLookup : Lookup template typename context_t::return_t dispatch (context_t *c, Ts&&... ds) const - { return Lookup::dispatch (c, hb_forward (ds)...); } + { return Lookup::dispatch (c, std::forward (ds)...); } bool subset (hb_subset_context_t *c) const { return Lookup::subset (c); } diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index 9b958a8c6..fde273e69 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -2288,9 +2288,9 @@ struct Context TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); - case 2: return_trace (c->dispatch (u.format2, hb_forward (ds)...)); - case 3: return_trace (c->dispatch (u.format3, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); + case 2: return_trace (c->dispatch (u.format2, std::forward (ds)...)); + case 3: return_trace (c->dispatch (u.format3, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } @@ -3358,9 +3358,9 @@ struct ChainContext TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); - case 2: return_trace (c->dispatch (u.format2, hb_forward (ds)...)); - case 3: return_trace (c->dispatch (u.format3, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); + case 2: return_trace (c->dispatch (u.format2, std::forward (ds)...)); + case 3: return_trace (c->dispatch (u.format3, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } @@ -3389,7 +3389,7 @@ struct ExtensionFormat1 { TRACE_DISPATCH (this, format); if (unlikely (!c->may_dispatch (this, this))) return_trace (c->no_dispatch_return_value ()); - return_trace (get_subtable ().dispatch (c, get_type (), hb_forward (ds)...)); + return_trace (get_subtable ().dispatch (c, get_type (), std::forward (ds)...)); } void collect_variation_indices (hb_collect_variation_indices_context_t *c) const @@ -3469,7 +3469,7 @@ struct Extension TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (u.format1.dispatch (c, hb_forward (ds)...)); + case 1: return_trace (u.format1.dispatch (c, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index cf3e1df96..d02a3c0ea 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -2011,14 +2011,14 @@ struct hb_get_glyph_alternates_dispatch_t : private: template auto _dispatch (const T &obj, hb_priority<1>, Ts&&... ds) HB_AUTO_RETURN - ( obj.get_glyph_alternates (hb_forward (ds)...) ) + ( obj.get_glyph_alternates (std::forward (ds)...) ) template auto _dispatch (const T &obj, hb_priority<0>, Ts&&... ds) HB_AUTO_RETURN ( default_return_value () ) public: template auto dispatch (const T &obj, Ts&&... ds) HB_AUTO_RETURN - ( _dispatch (obj, hb_prioritize, hb_forward (ds)...) ) + ( _dispatch (obj, hb_prioritize, std::forward (ds)...) ) }; /** diff --git a/src/hb-sanitize.hh b/src/hb-sanitize.hh index 56c46015a..2e536c7a8 100644 --- a/src/hb-sanitize.hh +++ b/src/hb-sanitize.hh @@ -145,14 +145,14 @@ struct hb_sanitize_context_t : private: template auto _dispatch (const T &obj, hb_priority<1>, Ts&&... ds) HB_AUTO_RETURN - ( obj.sanitize (this, hb_forward (ds)...) ) + ( obj.sanitize (this, std::forward (ds)...) ) template auto _dispatch (const T &obj, hb_priority<0>, Ts&&... ds) HB_AUTO_RETURN - ( obj.dispatch (this, hb_forward (ds)...) ) + ( obj.dispatch (this, std::forward (ds)...) ) public: template auto dispatch (const T &obj, Ts&&... ds) HB_AUTO_RETURN - ( _dispatch (obj, hb_prioritize, hb_forward (ds)...) ) + ( _dispatch (obj, hb_prioritize, std::forward (ds)...) ) void init (hb_blob_t *b) diff --git a/src/hb-serialize.hh b/src/hb-serialize.hh index 7212d9872..7b83fe1a2 100644 --- a/src/hb-serialize.hh +++ b/src/hb-serialize.hh @@ -189,8 +189,8 @@ struct hb_serialize_context_t { return check_success (!hb_deref (obj).in_error ()); } template bool propagate_error (T1 &&o1, Ts&&... os) - { return propagate_error (hb_forward (o1)) && - propagate_error (hb_forward (os)...); } + { return propagate_error (std::forward (o1)) && + propagate_error (std::forward (os)...); } /* To be called around main operation. */ template @@ -376,7 +376,7 @@ struct hb_serialize_context_t err (HB_SERIALIZE_ERROR_OTHER); link.width = sizeof (T); - link.is_signed = hb_is_signed (hb_unwrap_type (T)); + link.is_signed = std::is_signed::value; link.whence = (unsigned) whence; link.position = (const char *) &ofs - current->head; link.bias = bias; @@ -494,7 +494,7 @@ struct hb_serialize_context_t template auto _copy (const Type &src, hb_priority<1>, Ts&&... ds) HB_RETURN - (Type *, src.copy (this, hb_forward (ds)...)) + (Type *, src.copy (this, std::forward (ds)...)) template auto _copy (const Type &src, hb_priority<0>) -> decltype (&(hb_declval () = src)) @@ -509,16 +509,16 @@ struct hb_serialize_context_t * instead of memcpy(). */ template Type *copy (const Type &src, Ts&&... ds) - { return _copy (src, hb_prioritize, hb_forward (ds)...); } + { return _copy (src, hb_prioritize, std::forward (ds)...); } template Type *copy (const Type *src, Ts&&... ds) - { return copy (*src, hb_forward (ds)...); } + { return copy (*src, std::forward (ds)...); } template void copy_all (Iterator it, Ts&&... ds) - { for (decltype (*it) _ : it) copy (_, hb_forward (ds)...); } + { for (decltype (*it) _ : it) copy (_, std::forward (ds)...); } template hb_serialize_context_t& operator << (const Type &obj) & { embed (obj); return *this; } @@ -546,10 +546,10 @@ struct hb_serialize_context_t template Type *extend (Type *obj, Ts&&... ds) - { return extend_size (obj, obj->get_size (hb_forward (ds)...)); } + { return extend_size (obj, obj->get_size (std::forward (ds)...)); } template Type *extend (Type &obj, Ts&&... ds) - { return extend (hb_addressof (obj), hb_forward (ds)...); } + { return extend (hb_addressof (obj), std::forward (ds)...); } /* Output routines. */ hb_bytes_t copy_bytes () const diff --git a/src/hb-set.hh b/src/hb-set.hh index 437e23436..884142718 100644 --- a/src/hb-set.hh +++ b/src/hb-set.hh @@ -42,9 +42,22 @@ struct hb_sparseset_t ~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 = 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) { 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 lst) : hb_sparseset_t () + { + for (auto&& item : lst) + add (item); + } + template + hb_sparseset_t (const Iterable &o) : hb_sparseset_t () + { + hb_copy (o, *this); + } void init_shallow () { s.init (); } void init () @@ -140,7 +153,18 @@ struct hb_sparseset_t operator iter_t () const { return iter (); } }; -struct hb_set_t : hb_sparseset_t {}; +struct hb_set_t : hb_sparseset_t +{ + hb_set_t () = default; + ~hb_set_t () = default; + hb_set_t (hb_set_t& o) = default; + hb_set_t& operator= (const hb_set_t& other) = default; + hb_set_t& operator= (hb_set_t&& other) = default; + hb_set_t (std::initializer_list lst) : hb_sparseset_t (lst) {} + template + hb_set_t (const Iterable &o) : hb_sparseset_t (o) {} +}; static_assert (hb_set_t::INVALID == HB_SET_VALUE_INVALID, ""); diff --git a/src/hb-subset.hh b/src/hb-subset.hh index c9b01c67f..98c5f06fb 100644 --- a/src/hb-subset.hh +++ b/src/hb-subset.hh @@ -45,14 +45,14 @@ struct hb_subset_context_t : private: template auto _dispatch (const T &obj, hb_priority<1>, Ts&&... ds) HB_AUTO_RETURN - ( obj.subset (this, hb_forward (ds)...) ) + ( obj.subset (this, std::forward (ds)...) ) template auto _dispatch (const T &obj, hb_priority<0>, Ts&&... ds) HB_AUTO_RETURN - ( obj.dispatch (this, hb_forward (ds)...) ) + ( obj.dispatch (this, std::forward (ds)...) ) public: template auto dispatch (const T &obj, Ts&&... ds) HB_AUTO_RETURN - ( _dispatch (obj, hb_prioritize, hb_forward (ds)...) ) + ( _dispatch (obj, hb_prioritize, std::forward (ds)...) ) hb_blob_t *source_blob; hb_subset_plan_t *plan; diff --git a/src/hb-vector.hh b/src/hb-vector.hh index 44c174d07..b0a1e5e96 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -38,10 +38,23 @@ struct hb_vector_t typedef Type item_t; static constexpr unsigned item_size = hb_static_size (Type); - hb_vector_t () { init (); } - hb_vector_t (const hb_vector_t &o) + hb_vector_t () = default; + hb_vector_t (std::initializer_list lst) : hb_vector_t () + { + alloc (lst.size ()); + for (auto&& item : lst) + push (item); + } + template + hb_vector_t (const Iterable &o) : hb_vector_t () + { + if (hb_iter (o).is_random_access_iterator) + alloc (hb_len (hb_iter (o))); + hb_copy (o, *this); + } + hb_vector_t (const hb_vector_t &o) : hb_vector_t () { - init (); alloc (o.length); hb_copy (o, *this); } @@ -55,11 +68,11 @@ struct hb_vector_t ~hb_vector_t () { fini (); } private: - int allocated; /* == -1 means allocation failed. */ + int allocated = 0; /* == -1 means allocation failed. */ public: - unsigned int length; + unsigned int length = 0; public: - Type *arrayZ; + Type *arrayZ = nullptr; void init () { @@ -103,11 +116,7 @@ struct hb_vector_t } hb_vector_t& operator = (hb_vector_t &&o) { - fini (); - allocated = o.allocated; - length = o.length; - arrayZ = o.arrayZ; - o.init (); + hb_swap (*this, o); return *this; } @@ -141,7 +150,7 @@ struct hb_vector_t /* Sink interface. */ template - hb_vector_t& operator << (T&& v) { push (hb_forward (v)); return *this; } + hb_vector_t& operator << (T&& v) { push (std::forward (v)); return *this; } hb_array_t< Type> as_array () { return hb_array (arrayZ, length); } hb_array_t as_array () const { return hb_array (arrayZ, length); } @@ -189,7 +198,7 @@ struct hb_vector_t // the created copy to leak memory since we won't have stored a // reference to it. return p; - *p = hb_forward (v); + *p = std::forward (v); return p; } @@ -246,7 +255,7 @@ struct hb_vector_t Type pop () { if (!length) return Null (Type); - return hb_move (arrayZ[--length]); /* Does this move actually work? */ + return std::move (arrayZ[--length]); /* Does this move actually work? */ } void remove (unsigned int i) @@ -302,6 +311,19 @@ struct hb_vector_t template struct 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) {} + 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)); } + hb_sorted_array_t< Type> as_array () { return hb_sorted_array (this->arrayZ, this->length); } hb_sorted_array_t as_array () const { return hb_sorted_array (this->arrayZ, this->length); } diff --git a/src/meson.build b/src/meson.build index db4208f5c..bda44c683 100644 --- a/src/meson.build +++ b/src/meson.build @@ -488,10 +488,12 @@ if get_option('tests').enabled() 'test-repacker': ['test-repacker.cc', 'hb-static.cc'], 'test-priority-queue': ['test-priority-queue.cc', 'hb-static.cc'], 'test-iter': ['test-iter.cc', 'hb-static.cc'], - 'test-meta': ['test-meta.cc', 'hb-static.cc'], + 'test-map': ['test-map.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'], } foreach name, source : compiled_tests diff --git a/src/test-map.cc b/src/test-map.cc new file mode 100644 index 000000000..5761cc8d6 --- /dev/null +++ b/src/test-map.cc @@ -0,0 +1,102 @@ +/* + * 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-map.hh" + + +int +main (int argc, char **argv) +{ + + /* Test copy constructor. */ + { + hb_map_t v1; + v1.set (1, 2); + hb_map_t v2 {v1}; + assert (v1.get_population () == 1); + assert (v2.get_population () == 1); + assert (v1[1] == 2); + assert (v2[1] == 2); + } + + /* Test copy assignment. */ + { + hb_map_t v1; + v1.set (1, 2); + hb_map_t v2 = v1; + assert (v1.get_population () == 1); + assert (v2.get_population () == 1); + assert (v1[1] == 2); + assert (v2[1] == 2); + } + + /* Test move constructor. */ + { + hb_map_t v {hb_map_t {}}; + } + + /* Test move assignment. */ + { + hb_map_t v; + v = hb_map_t {}; + } + + /* Test initializing from iterable. */ + { + hb_map_t s; + + s.set (1, 2); + s.set (3, 4); + + hb_map_t v (s); + + assert (v.get_population () == 2); + } + + /* Test initializing from iterator. */ + { + hb_map_t s; + + s.set (1, 2); + s.set (3, 4); + + hb_map_t v (hb_iter (s)); + + assert (v.get_population () == 2); + } + + /* Test initializing from initializer list and swapping. */ + { + using pair_t = hb_pair_t; + hb_map_t v1 {pair_t{1,2}, pair_t{4,5}}; + hb_map_t v2 {pair_t{3,4}}; + hb_swap (v1, v2); + assert (v1.get_population () == 1); + assert (v2.get_population () == 2); + } + + return 0; +} diff --git a/src/test-meta.cc b/src/test-meta.cc deleted file mode 100644 index 9436b9038..000000000 --- a/src/test-meta.cc +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright © 2019 Facebook, Inc. - * - * 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. - * - * Facebook Author(s): Behdad Esfahbod - */ - -#include "hb.hh" -#include "hb-meta.hh" - -#include - -template struct U { typedef T type; }; - -int -main (int argc, char **argv) -{ - static_assert (hb_is_convertible (void, void), ""); - static_assert (hb_is_convertible (void, const void), ""); - static_assert (hb_is_convertible (const void, void), ""); - - static_assert (hb_is_convertible (int, int), ""); - static_assert (hb_is_convertible (char, int), ""); - static_assert (hb_is_convertible (long, int), ""); - - static_assert (hb_is_convertible (int, int), ""); - - static_assert (hb_is_convertible (const int, int), ""); - static_assert (hb_is_convertible (int, const int), ""); - static_assert (hb_is_convertible (const int, const int), ""); - - static_assert (hb_is_convertible (int&, int), ""); - static_assert (!hb_is_convertible (int, int&), ""); - - static_assert (hb_is_convertible (int, const int&), ""); - static_assert (!hb_is_convertible (const int, int&), ""); - static_assert (hb_is_convertible (const int, const int&), ""); - static_assert (hb_is_convertible (int&, const int), ""); - static_assert (hb_is_convertible (const int&, int), ""); - static_assert (hb_is_convertible (const int&, const int), ""); - static_assert (hb_is_convertible (const int&, const int), ""); - - struct X {}; - struct Y : X {}; - - static_assert (hb_is_convertible (const X &, const X), ""); - static_assert (hb_is_convertible (X &, const X), ""); - static_assert (hb_is_convertible (X &, const X &), ""); - static_assert (hb_is_convertible (X, const X &), ""); - static_assert (hb_is_convertible (const X, const X &), ""); - static_assert (!hb_is_convertible (const X, X &), ""); - static_assert (!hb_is_convertible (X, X &), ""); - static_assert (hb_is_convertible (X &, X &), ""); - - static_assert (hb_is_convertible (int&, long), ""); - static_assert (!hb_is_convertible (int&, long&), ""); - - static_assert (hb_is_convertible (int *, int *), ""); - static_assert (hb_is_convertible (int *, const int *), ""); - static_assert (!hb_is_convertible (const int *, int *), ""); - static_assert (!hb_is_convertible (int *, long *), ""); - static_assert (hb_is_convertible (int *, void *), ""); - static_assert (!hb_is_convertible (void *, int *), ""); - - static_assert (hb_is_base_of (void, void), ""); - static_assert (hb_is_base_of (void, int), ""); - static_assert (!hb_is_base_of (int, void), ""); - - static_assert (hb_is_base_of (int, int), ""); - static_assert (hb_is_base_of (const int, int), ""); - static_assert (hb_is_base_of (int, const int), ""); - - static_assert (hb_is_base_of (X, X), ""); - static_assert (hb_is_base_of (X, Y), ""); - static_assert (hb_is_base_of (const X, Y), ""); - static_assert (hb_is_base_of (X, const Y), ""); - static_assert (!hb_is_base_of (Y, X), ""); - - static_assert (hb_is_constructible (int), ""); - static_assert (hb_is_constructible (int, int), ""); - static_assert (hb_is_constructible (int, char), ""); - static_assert (hb_is_constructible (int, long), ""); - static_assert (!hb_is_constructible (int, X), ""); - static_assert (!hb_is_constructible (int, int, int), ""); - static_assert (hb_is_constructible (X), ""); - static_assert (!hb_is_constructible (X, int), ""); - static_assert (hb_is_constructible (X, X), ""); - static_assert (!hb_is_constructible (X, X, X), ""); - static_assert (hb_is_constructible (X, Y), ""); - static_assert (!hb_is_constructible (Y, X), ""); - - static_assert (hb_is_trivially_default_constructible (X), ""); - static_assert (hb_is_trivially_default_constructible (Y), ""); - static_assert (hb_is_trivially_copy_constructible (X), ""); - static_assert (hb_is_trivially_copy_constructible (Y), ""); - static_assert (hb_is_trivially_move_constructible (X), ""); - static_assert (hb_is_trivially_move_constructible (Y), ""); - static_assert (hb_is_trivially_destructible (Y), ""); - - static_assert (hb_is_trivially_copyable (int), ""); - static_assert (hb_is_trivially_copyable (X), ""); - static_assert (hb_is_trivially_copyable (Y), ""); - - static_assert (hb_is_trivial (int), ""); - static_assert (hb_is_trivial (X), ""); - static_assert (hb_is_trivial (Y), ""); - - static_assert (hb_is_signed (hb_unwrap_type (U>>)), ""); - static_assert (hb_is_unsigned (hb_unwrap_type (U>>>)), ""); - - /* TODO Add more meaningful tests. */ - - return 0; -} diff --git a/src/test-set.cc b/src/test-set.cc new file mode 100644 index 000000000..286f1a997 --- /dev/null +++ b/src/test-set.cc @@ -0,0 +1,97 @@ +/* + * 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 from iterable. */ + { + hb_set_t s; + + s.add (18); + s.add (12); + + hb_set_t v (s); + + assert (v.get_population () == 2); + } + + /* Test initializing 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 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; +} diff --git a/src/test-vector.cc b/src/test-vector.cc new file mode 100644 index 000000000..6418a84ae --- /dev/null +++ b/src/test-vector.cc @@ -0,0 +1,140 @@ +/* + * 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-vector.hh" +#include "hb-set.hh" + + +int +main (int argc, char **argv) +{ + + /* Test copy constructor. */ + { + 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); + assert (v2.length == 2); + assert (v2[0] == 1); + assert (v2[1] == 2); + } + + /* Test copy assignment. */ + { + 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); + assert (v2.length == 2); + assert (v2[0] == 1); + assert (v2[1] == 2); + } + + /* 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); + } + + /* 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 from iterable. */ + { + hb_set_t s; + + s.add (18); + 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 from iterator. */ + { + hb_set_t s; + + s.add (18); + 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 from initializer list and swapping. */ + { + hb_vector_t v1 {1, 2, 3}; + hb_vector_t v2 {4, 5}; + hb_swap (v1, v2); + assert (v1.length == 2); + assert (v1[0] == 4); + assert (v2.length == 3); + assert (v2[2] == 3); + } + + /* Test initializing sorted-vector from initializer list and swapping. */ + { + hb_sorted_vector_t v1 {1, 2, 3}; + hb_sorted_vector_t v2 {4, 5}; + hb_swap (v1, v2); + assert (v1.length == 2); + assert (v1[0] == 4); + assert (v2.length == 3); + assert (v2[2] == 3); + } + + return 0; +}