From 2e48fd077954410f59156b3100c16bf56a507948 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 2 Jul 2019 17:55:58 -0700 Subject: [PATCH] Sprinkle constexpr around Being conservative. Also not sure it makes any real difference in our codebase. --- src/hb-algs.hh | 48 ++++++++++++++++++++++++------------------------ src/hb-meta.hh | 18 +++++++++--------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/hb-algs.hh b/src/hb-algs.hh index c8d83c8..7886894 100644 --- a/src/hb-algs.hh +++ b/src/hb-algs.hh @@ -50,31 +50,31 @@ struct { /* Note. This is dangerous in that if it's passed an rvalue, it returns rvalue-reference. */ - template auto + template constexpr auto operator () (T&& v) const HB_AUTO_RETURN ( hb_forward (v) ) } HB_FUNCOBJ (hb_identity); struct { /* Like identity(), but only retains lvalue-references. Rvalues are returned as rvalues. */ - template T& + template constexpr T& operator () (T& v) const { return v; } - template hb_remove_reference + template constexpr hb_remove_reference operator () (T&& v) const { return v; } } HB_FUNCOBJ (hb_lidentity); struct { /* Like identity(), but always returns rvalue. */ - template hb_remove_reference + template constexpr hb_remove_reference operator () (T&& v) const { return v; } } HB_FUNCOBJ (hb_ridentity); struct { - template bool + template constexpr bool operator () (T&& v) const { return bool (hb_forward (v)); } } HB_FUNCOBJ (hb_bool); @@ -82,11 +82,11 @@ HB_FUNCOBJ (hb_bool); struct { private: - template auto + template constexpr auto impl (const T& v, hb_priority<1>) const HB_RETURN (uint32_t, hb_deref (v).hash ()) template auto + hb_enable_if (hb_is_integral (T))> constexpr auto impl (const T& v, hb_priority<0>) const HB_AUTO_RETURN ( /* Knuth's multiplicative method: */ @@ -95,7 +95,7 @@ struct public: - template auto + template constexpr auto operator () (const T& v) const HB_RETURN (uint32_t, impl (v, hb_prioritize)) } HB_FUNCOBJ (hb_hash); @@ -328,14 +328,14 @@ hb_pair (T1&& a, T2&& b) { return hb_pair_t (a, b); } struct { - template typename Pair::first_t + template constexpr typename Pair::first_t operator () (const Pair& pair) const { return pair.first; } } HB_FUNCOBJ (hb_first); struct { - template typename Pair::second_t + template constexpr typename Pair::second_t operator () (const Pair& pair) const { return pair.second; } } HB_FUNCOBJ (hb_second); @@ -346,14 +346,14 @@ HB_FUNCOBJ (hb_second); * comparing integers of different signedness. */ struct { - template auto + template constexpr auto operator () (T&& a, T2&& b) const HB_AUTO_RETURN (hb_forward (a) <= hb_forward (b) ? hb_forward (a) : hb_forward (b)) } HB_FUNCOBJ (hb_min); struct { - template auto + template constexpr auto operator () (T&& a, T2&& b) const HB_AUTO_RETURN (hb_forward (a) >= hb_forward (b) ? hb_forward (a) : hb_forward (b)) } @@ -917,7 +917,7 @@ struct hb_bitwise_and { HB_PARTIALIZE(2); static constexpr bool passthru_left = false; static constexpr bool passthru_right = false; - template auto + template constexpr auto operator () (const T &a, const T &b) const HB_AUTO_RETURN (a & b) } HB_FUNCOBJ (hb_bitwise_and); @@ -925,7 +925,7 @@ struct hb_bitwise_or { HB_PARTIALIZE(2); static constexpr bool passthru_left = true; static constexpr bool passthru_right = true; - template auto + template constexpr auto operator () (const T &a, const T &b) const HB_AUTO_RETURN (a | b) } HB_FUNCOBJ (hb_bitwise_or); @@ -933,7 +933,7 @@ struct hb_bitwise_xor { HB_PARTIALIZE(2); static constexpr bool passthru_left = true; static constexpr bool passthru_right = true; - template auto + template constexpr auto operator () (const T &a, const T &b) const HB_AUTO_RETURN (a ^ b) } HB_FUNCOBJ (hb_bitwise_xor); @@ -941,56 +941,56 @@ struct hb_bitwise_sub { HB_PARTIALIZE(2); static constexpr bool passthru_left = true; static constexpr bool passthru_right = false; - template auto + template constexpr auto operator () (const T &a, const T &b) const HB_AUTO_RETURN (a & ~b) } HB_FUNCOBJ (hb_bitwise_sub); struct { - template auto + template constexpr auto operator () (const T &a) const HB_AUTO_RETURN (~a) } HB_FUNCOBJ (hb_bitwise_neg); struct { HB_PARTIALIZE(2); - template auto + template constexpr auto operator () (const T &a, const T2 &b) const HB_AUTO_RETURN (a + b) } HB_FUNCOBJ (hb_add); struct { HB_PARTIALIZE(2); - template auto + template constexpr auto operator () (const T &a, const T2 &b) const HB_AUTO_RETURN (a - b) } HB_FUNCOBJ (hb_sub); struct { HB_PARTIALIZE(2); - template auto + template constexpr auto operator () (const T &a, const T2 &b) const HB_AUTO_RETURN (a * b) } HB_FUNCOBJ (hb_mul); struct { HB_PARTIALIZE(2); - template auto + template constexpr auto operator () (const T &a, const T2 &b) const HB_AUTO_RETURN (a / b) } HB_FUNCOBJ (hb_div); struct { HB_PARTIALIZE(2); - template auto + template constexpr auto operator () (const T &a, const T2 &b) const HB_AUTO_RETURN (a % b) } HB_FUNCOBJ (hb_mod); struct { - template auto + template constexpr auto operator () (const T &a) const HB_AUTO_RETURN (+a) } HB_FUNCOBJ (hb_pos); struct { - template auto + template constexpr auto operator () (const T &a) const HB_AUTO_RETURN (-a) } HB_FUNCOBJ (hb_neg); diff --git a/src/hb-meta.hh b/src/hb-meta.hh index df8ebd1..2dfaeb7 100644 --- a/src/hb-meta.hh +++ b/src/hb-meta.hh @@ -80,8 +80,8 @@ template using hb_type_identity = typename hb_type_identity_t::t struct { - template - T* operator () (T& arg) const + template constexpr T* + operator () (T& arg) const { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wcast-align" @@ -171,29 +171,29 @@ using hb_is_cr_convertible = hb_bool_constant< /* std::move and std::forward */ template -static hb_remove_reference&& hb_move (T&& t) { return (hb_remove_reference&&) (t); } +static constexpr hb_remove_reference&& hb_move (T&& t) { return (hb_remove_reference&&) (t); } template -static T&& hb_forward (hb_remove_reference& t) { return (T&&) t; } +static constexpr T&& hb_forward (hb_remove_reference& t) { return (T&&) t; } template -static T&& hb_forward (hb_remove_reference&& t) { return (T&&) t; } +static constexpr T&& hb_forward (hb_remove_reference&& t) { return (T&&) t; } struct { - template auto + template constexpr auto operator () (T&& v) const HB_AUTO_RETURN (hb_forward (v)) - template auto + template constexpr auto operator () (T *v) const HB_AUTO_RETURN (*v) } HB_FUNCOBJ (hb_deref); struct { - template auto + template constexpr auto operator () (T&& v) const HB_AUTO_RETURN (hb_forward (v)) - template auto + template constexpr auto operator () (T& v) const HB_AUTO_RETURN (hb_addressof (v)) } HB_FUNCOBJ (hb_ref); -- 2.7.4