[algs] Rename hb_bind to hb_partial
Since our API is the invers of what std::bind is, and closer to Python functools.partial().
This commit is contained in:
parent
0888e7bc86
commit
6f51e55524
|
@ -120,9 +120,9 @@ struct
|
|||
HB_FUNCOBJ (hb_invoke);
|
||||
|
||||
template <unsigned Pos, typename Appl, typename V>
|
||||
struct hb_binder_t
|
||||
struct hb_partial_t
|
||||
{
|
||||
hb_binder_t (Appl a, V v) : a (a), v (v) {}
|
||||
hb_partial_t (Appl a, V v) : a (a), v (v) {}
|
||||
|
||||
static_assert (Pos > 0, "");
|
||||
|
||||
|
@ -155,13 +155,13 @@ struct hb_binder_t
|
|||
hb_reference_wrapper<Appl> a;
|
||||
V 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) ))
|
||||
template <unsigned Pos=1, typename Appl, typename V>
|
||||
auto hb_partial (Appl&& a, V&& v) HB_AUTO_RETURN
|
||||
(( hb_partial_t<Pos, Appl, V> (a, v) ))
|
||||
|
||||
#define HB_PARTIALIZE(Pos) \
|
||||
template <typename _T> \
|
||||
auto operator () (_T&& _v) const HB_AUTO_RETURN (hb_bind<Pos> (this, hb_forward<_T> (_v))) \
|
||||
auto operator () (_T&& _v) const HB_AUTO_RETURN (hb_partial<Pos> (this, hb_forward<_T> (_v))) \
|
||||
static_assert (true, "")
|
||||
|
||||
|
||||
|
|
|
@ -77,10 +77,10 @@ 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<1> (hb_min, 3) (4));
|
||||
assert (3 == hb_bind<2> (hb_min, 4) (3));
|
||||
assert (3 == hb_partial (hb_min, 3) (4));
|
||||
assert (3 == hb_partial<1> (hb_min, 4) (3));
|
||||
|
||||
auto M0 = hb_bind<2> (hb_max, 0);
|
||||
auto M0 = hb_partial<2> (hb_max, 0);
|
||||
assert (M0 (-2) == 0);
|
||||
assert (M0 (+2) == 2);
|
||||
|
||||
|
|
Loading…
Reference in New Issue