[iter] Make filter/map copyable

This commit is contained in:
Behdad Esfahbod 2019-05-07 00:05:37 -07:00
parent 03a68165d8
commit 025eaa3c81
2 changed files with 11 additions and 11 deletions

View File

@ -319,12 +319,12 @@ struct hb_map_iter_t :
hb_iter_t<hb_map_iter_t<Iter, Proj>,
decltype (hb_declval (Proj) (hb_declval (typename Iter::item_t)))>
{
hb_map_iter_t (const Iter& it, Proj f) : it (it), f (f) {}
hb_map_iter_t (const Iter& it, Proj f_) : it (it), f (f_) {}
typedef decltype (hb_declval (Proj) (hb_declval (typename Iter::item_t))) __item_t__;
static constexpr bool is_random_access_iterator = Iter::is_random_access_iterator;
__item_t__ __item__ () const { return hb_get (f, *it); }
__item_t__ __item_at__ (unsigned i) const { return hb_get (f, it[i]); }
__item_t__ __item__ () const { return hb_get (f.get (), *it); }
__item_t__ __item_at__ (unsigned i) const { return hb_get (f.get (), it[i]); }
bool __more__ () const { return bool (it); }
unsigned __len__ () const { return it.len (); }
void __next__ () { ++it; }
@ -336,7 +336,7 @@ struct hb_map_iter_t :
private:
Iter it;
Proj f;
hb_reference_wrapper<Proj> f;
};
template <typename Proj>
@ -367,22 +367,22 @@ struct hb_filter_iter_t :
hb_iter_with_fallback_t<hb_filter_iter_t<Iter, Pred, Proj>,
typename Iter::item_t>
{
hb_filter_iter_t (const Iter& it_, Pred p, Proj f) : it (it_), p (p), f (f)
{ while (it && !hb_has (p, hb_get (f, *it))) ++it; }
hb_filter_iter_t (const Iter& it_, Pred p_, Proj f_) : it (it_), p (p_), f (f_)
{ while (it && !hb_has (p.get (), hb_get (f.get (), *it))) ++it; }
typedef typename Iter::item_t __item_t__;
static constexpr bool is_sorted_iterator = Iter::is_sorted_iterator;
__item_t__ __item__ () const { return *it; }
bool __more__ () const { return bool (it); }
void __next__ () { do ++it; while (it && !hb_has (p, hb_get (f, *it))); }
void __next__ () { do ++it; while (it && !hb_has (p.get (), hb_get (f.get (), *it))); }
void __prev__ () { --it; }
bool operator != (const hb_filter_iter_t& o) const
{ return it != o.it || p != o.p || f != o.f; }
private:
Iter it;
Pred p;
Proj f;
hb_reference_wrapper<Pred> p;
hb_reference_wrapper<Proj> f;
};
template <typename Pred, typename Proj>
struct hb_filter_iter_factory_t

View File

@ -157,8 +157,8 @@ main (int argc, char **argv)
test_iterator (hb_zip (st, v));
test_iterator_non_default_constructable (hb_enumerate (st));
//test_iterator_non_default_constructable (hb_iter (st) | hb_filter ());
//test_iterator_non_default_constructable (hb_iter (st) | hb_map (hb_identity));
test_iterator_non_default_constructable (hb_iter (st) | hb_filter ());
test_iterator_non_default_constructable (hb_iter (st) | hb_map (hb_identity));
hb_any (st);