Sprinkle constexpr around

Being conservative.  Also not sure it makes any real difference
in our codebase.
pull/1813/head
Behdad Esfahbod 5 years ago
parent df4448064e
commit 2e48fd0779
  1. 48
      src/hb-algs.hh
  2. 18
      src/hb-meta.hh

@ -50,31 +50,31 @@
struct struct
{ {
/* Note. This is dangerous in that if it's passed an rvalue, it returns rvalue-reference. */ /* Note. This is dangerous in that if it's passed an rvalue, it returns rvalue-reference. */
template <typename T> auto template <typename T> constexpr auto
operator () (T&& v) const HB_AUTO_RETURN ( hb_forward<T> (v) ) operator () (T&& v) const HB_AUTO_RETURN ( hb_forward<T> (v) )
} }
HB_FUNCOBJ (hb_identity); HB_FUNCOBJ (hb_identity);
struct struct
{ {
/* Like identity(), but only retains lvalue-references. Rvalues are returned as rvalues. */ /* Like identity(), but only retains lvalue-references. Rvalues are returned as rvalues. */
template <typename T> T& template <typename T> constexpr T&
operator () (T& v) const { return v; } operator () (T& v) const { return v; }
template <typename T> hb_remove_reference<T> template <typename T> constexpr hb_remove_reference<T>
operator () (T&& v) const { return v; } operator () (T&& v) const { return v; }
} }
HB_FUNCOBJ (hb_lidentity); HB_FUNCOBJ (hb_lidentity);
struct struct
{ {
/* Like identity(), but always returns rvalue. */ /* Like identity(), but always returns rvalue. */
template <typename T> hb_remove_reference<T> template <typename T> constexpr hb_remove_reference<T>
operator () (T&& v) const { return v; } operator () (T&& v) const { return v; }
} }
HB_FUNCOBJ (hb_ridentity); HB_FUNCOBJ (hb_ridentity);
struct struct
{ {
template <typename T> bool template <typename T> constexpr bool
operator () (T&& v) const { return bool (hb_forward<T> (v)); } operator () (T&& v) const { return bool (hb_forward<T> (v)); }
} }
HB_FUNCOBJ (hb_bool); HB_FUNCOBJ (hb_bool);
@ -82,11 +82,11 @@ HB_FUNCOBJ (hb_bool);
struct struct
{ {
private: private:
template <typename T> auto template <typename T> constexpr auto
impl (const T& v, hb_priority<1>) const HB_RETURN (uint32_t, hb_deref (v).hash ()) impl (const T& v, hb_priority<1>) const HB_RETURN (uint32_t, hb_deref (v).hash ())
template <typename T, template <typename T,
hb_enable_if (hb_is_integral (T))> auto hb_enable_if (hb_is_integral (T))> constexpr auto
impl (const T& v, hb_priority<0>) const HB_AUTO_RETURN impl (const T& v, hb_priority<0>) const HB_AUTO_RETURN
( (
/* Knuth's multiplicative method: */ /* Knuth's multiplicative method: */
@ -95,7 +95,7 @@ struct
public: public:
template <typename T> auto template <typename T> constexpr auto
operator () (const T& v) const HB_RETURN (uint32_t, impl (v, hb_prioritize)) operator () (const T& v) const HB_RETURN (uint32_t, impl (v, hb_prioritize))
} }
HB_FUNCOBJ (hb_hash); HB_FUNCOBJ (hb_hash);
@ -328,14 +328,14 @@ hb_pair (T1&& a, T2&& b) { return hb_pair_t<T1, T2> (a, b); }
struct struct
{ {
template <typename Pair> typename Pair::first_t template <typename Pair> constexpr typename Pair::first_t
operator () (const Pair& pair) const { return pair.first; } operator () (const Pair& pair) const { return pair.first; }
} }
HB_FUNCOBJ (hb_first); HB_FUNCOBJ (hb_first);
struct struct
{ {
template <typename Pair> typename Pair::second_t template <typename Pair> constexpr typename Pair::second_t
operator () (const Pair& pair) const { return pair.second; } operator () (const Pair& pair) const { return pair.second; }
} }
HB_FUNCOBJ (hb_second); HB_FUNCOBJ (hb_second);
@ -346,14 +346,14 @@ HB_FUNCOBJ (hb_second);
* comparing integers of different signedness. */ * comparing integers of different signedness. */
struct struct
{ {
template <typename T, typename T2> auto template <typename T, typename T2> constexpr auto
operator () (T&& a, T2&& b) const HB_AUTO_RETURN operator () (T&& a, T2&& b) const HB_AUTO_RETURN
(hb_forward<T> (a) <= hb_forward<T2> (b) ? hb_forward<T> (a) : hb_forward<T2> (b)) (hb_forward<T> (a) <= hb_forward<T2> (b) ? hb_forward<T> (a) : hb_forward<T2> (b))
} }
HB_FUNCOBJ (hb_min); HB_FUNCOBJ (hb_min);
struct struct
{ {
template <typename T, typename T2> auto template <typename T, typename T2> constexpr auto
operator () (T&& a, T2&& b) const HB_AUTO_RETURN operator () (T&& a, T2&& b) const HB_AUTO_RETURN
(hb_forward<T> (a) >= hb_forward<T2> (b) ? hb_forward<T> (a) : hb_forward<T2> (b)) (hb_forward<T> (a) >= hb_forward<T2> (b) ? hb_forward<T> (a) : hb_forward<T2> (b))
} }
@ -917,7 +917,7 @@ struct hb_bitwise_and
{ HB_PARTIALIZE(2); { HB_PARTIALIZE(2);
static constexpr bool passthru_left = false; static constexpr bool passthru_left = false;
static constexpr bool passthru_right = false; static constexpr bool passthru_right = false;
template <typename T> auto template <typename T> constexpr auto
operator () (const T &a, const T &b) const HB_AUTO_RETURN (a & b) operator () (const T &a, const T &b) const HB_AUTO_RETURN (a & b)
} }
HB_FUNCOBJ (hb_bitwise_and); HB_FUNCOBJ (hb_bitwise_and);
@ -925,7 +925,7 @@ struct hb_bitwise_or
{ HB_PARTIALIZE(2); { HB_PARTIALIZE(2);
static constexpr bool passthru_left = true; static constexpr bool passthru_left = true;
static constexpr bool passthru_right = true; static constexpr bool passthru_right = true;
template <typename T> auto template <typename T> constexpr auto
operator () (const T &a, const T &b) const HB_AUTO_RETURN (a | b) operator () (const T &a, const T &b) const HB_AUTO_RETURN (a | b)
} }
HB_FUNCOBJ (hb_bitwise_or); HB_FUNCOBJ (hb_bitwise_or);
@ -933,7 +933,7 @@ struct hb_bitwise_xor
{ HB_PARTIALIZE(2); { HB_PARTIALIZE(2);
static constexpr bool passthru_left = true; static constexpr bool passthru_left = true;
static constexpr bool passthru_right = true; static constexpr bool passthru_right = true;
template <typename T> auto template <typename T> constexpr auto
operator () (const T &a, const T &b) const HB_AUTO_RETURN (a ^ b) operator () (const T &a, const T &b) const HB_AUTO_RETURN (a ^ b)
} }
HB_FUNCOBJ (hb_bitwise_xor); HB_FUNCOBJ (hb_bitwise_xor);
@ -941,56 +941,56 @@ struct hb_bitwise_sub
{ HB_PARTIALIZE(2); { HB_PARTIALIZE(2);
static constexpr bool passthru_left = true; static constexpr bool passthru_left = true;
static constexpr bool passthru_right = false; static constexpr bool passthru_right = false;
template <typename T> auto template <typename T> constexpr auto
operator () (const T &a, const T &b) const HB_AUTO_RETURN (a & ~b) operator () (const T &a, const T &b) const HB_AUTO_RETURN (a & ~b)
} }
HB_FUNCOBJ (hb_bitwise_sub); HB_FUNCOBJ (hb_bitwise_sub);
struct struct
{ {
template <typename T> auto template <typename T> constexpr auto
operator () (const T &a) const HB_AUTO_RETURN (~a) operator () (const T &a) const HB_AUTO_RETURN (~a)
} }
HB_FUNCOBJ (hb_bitwise_neg); HB_FUNCOBJ (hb_bitwise_neg);
struct struct
{ HB_PARTIALIZE(2); { HB_PARTIALIZE(2);
template <typename T, typename T2> auto template <typename T, typename T2> constexpr auto
operator () (const T &a, const T2 &b) const HB_AUTO_RETURN (a + b) operator () (const T &a, const T2 &b) const HB_AUTO_RETURN (a + b)
} }
HB_FUNCOBJ (hb_add); HB_FUNCOBJ (hb_add);
struct struct
{ HB_PARTIALIZE(2); { HB_PARTIALIZE(2);
template <typename T, typename T2> auto template <typename T, typename T2> constexpr auto
operator () (const T &a, const T2 &b) const HB_AUTO_RETURN (a - b) operator () (const T &a, const T2 &b) const HB_AUTO_RETURN (a - b)
} }
HB_FUNCOBJ (hb_sub); HB_FUNCOBJ (hb_sub);
struct struct
{ HB_PARTIALIZE(2); { HB_PARTIALIZE(2);
template <typename T, typename T2> auto template <typename T, typename T2> constexpr auto
operator () (const T &a, const T2 &b) const HB_AUTO_RETURN (a * b) operator () (const T &a, const T2 &b) const HB_AUTO_RETURN (a * b)
} }
HB_FUNCOBJ (hb_mul); HB_FUNCOBJ (hb_mul);
struct struct
{ HB_PARTIALIZE(2); { HB_PARTIALIZE(2);
template <typename T, typename T2> auto template <typename T, typename T2> constexpr auto
operator () (const T &a, const T2 &b) const HB_AUTO_RETURN (a / b) operator () (const T &a, const T2 &b) const HB_AUTO_RETURN (a / b)
} }
HB_FUNCOBJ (hb_div); HB_FUNCOBJ (hb_div);
struct struct
{ HB_PARTIALIZE(2); { HB_PARTIALIZE(2);
template <typename T, typename T2> auto template <typename T, typename T2> constexpr auto
operator () (const T &a, const T2 &b) const HB_AUTO_RETURN (a % b) operator () (const T &a, const T2 &b) const HB_AUTO_RETURN (a % b)
} }
HB_FUNCOBJ (hb_mod); HB_FUNCOBJ (hb_mod);
struct struct
{ {
template <typename T> auto template <typename T> constexpr auto
operator () (const T &a) const HB_AUTO_RETURN (+a) operator () (const T &a) const HB_AUTO_RETURN (+a)
} }
HB_FUNCOBJ (hb_pos); HB_FUNCOBJ (hb_pos);
struct struct
{ {
template <typename T> auto template <typename T> constexpr auto
operator () (const T &a) const HB_AUTO_RETURN (-a) operator () (const T &a) const HB_AUTO_RETURN (-a)
} }
HB_FUNCOBJ (hb_neg); HB_FUNCOBJ (hb_neg);

@ -80,8 +80,8 @@ template <typename T> using hb_type_identity = typename hb_type_identity_t<T>::t
struct struct
{ {
template <typename T> template <typename T> constexpr T*
T* operator () (T& arg) const operator () (T& arg) const
{ {
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align" #pragma GCC diagnostic ignored "-Wcast-align"
@ -171,29 +171,29 @@ using hb_is_cr_convertible = hb_bool_constant<
/* std::move and std::forward */ /* std::move and std::forward */
template <typename T> template <typename T>
static hb_remove_reference<T>&& hb_move (T&& t) { return (hb_remove_reference<T>&&) (t); } static constexpr hb_remove_reference<T>&& hb_move (T&& t) { return (hb_remove_reference<T>&&) (t); }
template <typename T> template <typename T>
static T&& hb_forward (hb_remove_reference<T>& t) { return (T&&) t; } static constexpr T&& hb_forward (hb_remove_reference<T>& t) { return (T&&) t; }
template <typename T> template <typename T>
static T&& hb_forward (hb_remove_reference<T>&& t) { return (T&&) t; } static constexpr T&& hb_forward (hb_remove_reference<T>&& t) { return (T&&) t; }
struct struct
{ {
template <typename T> auto template <typename T> constexpr auto
operator () (T&& v) const HB_AUTO_RETURN (hb_forward<T> (v)) operator () (T&& v) const HB_AUTO_RETURN (hb_forward<T> (v))
template <typename T> auto template <typename T> constexpr auto
operator () (T *v) const HB_AUTO_RETURN (*v) operator () (T *v) const HB_AUTO_RETURN (*v)
} }
HB_FUNCOBJ (hb_deref); HB_FUNCOBJ (hb_deref);
struct struct
{ {
template <typename T> auto template <typename T> constexpr auto
operator () (T&& v) const HB_AUTO_RETURN (hb_forward<T> (v)) operator () (T&& v) const HB_AUTO_RETURN (hb_forward<T> (v))
template <typename T> auto template <typename T> constexpr auto
operator () (T& v) const HB_AUTO_RETURN (hb_addressof (v)) operator () (T& v) const HB_AUTO_RETURN (hb_addressof (v))
} }
HB_FUNCOBJ (hb_ref); HB_FUNCOBJ (hb_ref);

Loading…
Cancel
Save