[algs] Partialize all operators

This commit is contained in:
Behdad Esfahbod 2019-05-15 21:12:22 -07:00
parent edc69ec935
commit a06a236891
2 changed files with 44 additions and 26 deletions

View File

@ -153,7 +153,7 @@ struct hb_binder_t
hb_reference_wrapper<Appl> a;
V v;
};
template <unsigned Pos=0, typename Appl, typename V>
template <unsigned Pos, typename Appl, typename V>
auto hb_bind (Appl&& a, V&& v) HB_AUTO_RETURN
(( hb_binder_t<Pos, Appl, V> (a, v) ))
@ -790,64 +790,82 @@ hb_codepoint_parse (const char *s, unsigned int len, int base, hb_codepoint_t *o
}
/* Operators. */
struct hb_bitwise_and
{
{ HB_PARTIALIZE(1);
static constexpr bool passthru_left = false;
static constexpr bool passthru_right = false;
template <typename T>
auto operator () (const T &a, const T &b) const HB_AUTO_RETURN (a & b)
template <typename T> auto
operator () (const T &a, const T &b) const HB_AUTO_RETURN (a & b)
}
HB_FUNCOBJ (hb_bitwise_and);
struct hb_bitwise_or
{
{ HB_PARTIALIZE(1);
static constexpr bool passthru_left = true;
static constexpr bool passthru_right = true;
template <typename T>
auto operator () (const T &a, const T &b) const HB_AUTO_RETURN (a | b)
template <typename T> auto
operator () (const T &a, const T &b) const HB_AUTO_RETURN (a | b)
}
HB_FUNCOBJ (hb_bitwise_or);
struct hb_bitwise_xor
{
{ HB_PARTIALIZE(1);
static constexpr bool passthru_left = true;
static constexpr bool passthru_right = true;
template <typename T>
auto operator () (const T &a, const T &b) const HB_AUTO_RETURN (a ^ b)
template <typename T> auto
operator () (const T &a, const T &b) const HB_AUTO_RETURN (a ^ b)
}
HB_FUNCOBJ (hb_bitwise_xor);
struct hb_bitwise_sub
{
{ HB_PARTIALIZE(1);
static constexpr bool passthru_left = true;
static constexpr bool passthru_right = false;
template <typename T>
auto operator () (const T &a, const T &b) const HB_AUTO_RETURN (a & ~b)
template <typename T> auto
operator () (const T &a, const T &b) const HB_AUTO_RETURN (a & ~b)
}
HB_FUNCOBJ (hb_bitwise_sub);
struct
{
HB_PARTIALIZE(0);
template <typename T, typename T2>
auto operator () (const T &a, const T2 &b) const HB_AUTO_RETURN (a + b)
{ HB_PARTIALIZE(1);
template <typename T, typename T2> auto
operator () (const T &a, const T2 &b) const HB_AUTO_RETURN (a + b)
}
HB_FUNCOBJ (hb_add);
struct
{ template <typename T, typename T2> auto operator () (const T &a, const T2 &b) const HB_AUTO_RETURN (a - b) }
{ HB_PARTIALIZE(1);
template <typename T, typename T2> auto
operator () (const T &a, const T2 &b) const HB_AUTO_RETURN (a - b)
}
HB_FUNCOBJ (hb_sub);
struct
{ template <typename T, typename T2> auto operator () (const T &a, const T2 &b) const HB_AUTO_RETURN (a * b) }
{ HB_PARTIALIZE(1);
template <typename T, typename T2> auto
operator () (const T &a, const T2 &b) const HB_AUTO_RETURN (a * b)
}
HB_FUNCOBJ (hb_mul);
struct
{ template <typename T, typename T2> auto operator () (const T &a, const T2 &b) const HB_AUTO_RETURN (a / b) }
{ HB_PARTIALIZE(1);
template <typename T, typename T2> auto
operator () (const T &a, const T2 &b) const HB_AUTO_RETURN (a / b)
}
HB_FUNCOBJ (hb_div);
struct
{ template <typename T, typename T2> auto operator () (const T &a, const T2 &b) const HB_AUTO_RETURN (a % b) }
{ HB_PARTIALIZE(1);
template <typename T, typename T2> auto
operator () (const T &a, const T2 &b) const HB_AUTO_RETURN (a % b)
}
HB_FUNCOBJ (hb_mod);
struct
{ template <typename T> auto operator () (const T &a) const HB_AUTO_RETURN (+a) }
{
template <typename T> auto
operator () (const T &a) const HB_AUTO_RETURN (+a)
}
HB_FUNCOBJ (hb_pos);
struct
{ template <typename T> auto operator () (const T &a) const HB_AUTO_RETURN (-a) }
{
template <typename T> auto
operator () (const T &a) const HB_AUTO_RETURN (-a)
}
HB_FUNCOBJ (hb_neg);

View File

@ -77,8 +77,8 @@ main (int argc, char **argv)
xp = hb_pair_t<int *, double> (nullptr, 1);
xp = hb_pair_t<const int*, int> (nullptr, 1);
assert (3 == hb_bind (hb_min, 3) (4));
assert (3 == hb_bind (hb_min, 4) (3));
assert (3 == hb_bind<0> (hb_min, 3) (4));
assert (3 == hb_bind<0> (hb_min, 4) (3));
auto M0 = hb_bind<1> (hb_max, 0);
assert (M0 (-2) == 0);