[iter] Make filter/map copyable
This commit is contained in:
parent
03a68165d8
commit
025eaa3c81
|
@ -319,12 +319,12 @@ struct hb_map_iter_t :
|
||||||
hb_iter_t<hb_map_iter_t<Iter, Proj>,
|
hb_iter_t<hb_map_iter_t<Iter, Proj>,
|
||||||
decltype (hb_declval (Proj) (hb_declval (typename Iter::item_t)))>
|
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__;
|
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;
|
static constexpr bool is_random_access_iterator = Iter::is_random_access_iterator;
|
||||||
__item_t__ __item__ () const { return hb_get (f, *it); }
|
__item_t__ __item__ () const { return hb_get (f.get (), *it); }
|
||||||
__item_t__ __item_at__ (unsigned i) const { return hb_get (f, it[i]); }
|
__item_t__ __item_at__ (unsigned i) const { return hb_get (f.get (), it[i]); }
|
||||||
bool __more__ () const { return bool (it); }
|
bool __more__ () const { return bool (it); }
|
||||||
unsigned __len__ () const { return it.len (); }
|
unsigned __len__ () const { return it.len (); }
|
||||||
void __next__ () { ++it; }
|
void __next__ () { ++it; }
|
||||||
|
@ -336,7 +336,7 @@ struct hb_map_iter_t :
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Iter it;
|
Iter it;
|
||||||
Proj f;
|
hb_reference_wrapper<Proj> f;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Proj>
|
template <typename Proj>
|
||||||
|
@ -367,22 +367,22 @@ struct hb_filter_iter_t :
|
||||||
hb_iter_with_fallback_t<hb_filter_iter_t<Iter, Pred, Proj>,
|
hb_iter_with_fallback_t<hb_filter_iter_t<Iter, Pred, Proj>,
|
||||||
typename Iter::item_t>
|
typename Iter::item_t>
|
||||||
{
|
{
|
||||||
hb_filter_iter_t (const Iter& it_, Pred p, Proj f) : it (it_), p (p), f (f)
|
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; }
|
{ while (it && !hb_has (p.get (), hb_get (f.get (), *it))) ++it; }
|
||||||
|
|
||||||
typedef typename Iter::item_t __item_t__;
|
typedef typename Iter::item_t __item_t__;
|
||||||
static constexpr bool is_sorted_iterator = Iter::is_sorted_iterator;
|
static constexpr bool is_sorted_iterator = Iter::is_sorted_iterator;
|
||||||
__item_t__ __item__ () const { return *it; }
|
__item_t__ __item__ () const { return *it; }
|
||||||
bool __more__ () const { return bool (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; }
|
void __prev__ () { --it; }
|
||||||
bool operator != (const hb_filter_iter_t& o) const
|
bool operator != (const hb_filter_iter_t& o) const
|
||||||
{ return it != o.it || p != o.p || f != o.f; }
|
{ return it != o.it || p != o.p || f != o.f; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Iter it;
|
Iter it;
|
||||||
Pred p;
|
hb_reference_wrapper<Pred> p;
|
||||||
Proj f;
|
hb_reference_wrapper<Proj> f;
|
||||||
};
|
};
|
||||||
template <typename Pred, typename Proj>
|
template <typename Pred, typename Proj>
|
||||||
struct hb_filter_iter_factory_t
|
struct hb_filter_iter_factory_t
|
||||||
|
|
|
@ -157,8 +157,8 @@ main (int argc, char **argv)
|
||||||
|
|
||||||
test_iterator (hb_zip (st, v));
|
test_iterator (hb_zip (st, v));
|
||||||
test_iterator_non_default_constructable (hb_enumerate (st));
|
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_filter ());
|
||||||
//test_iterator_non_default_constructable (hb_iter (st) | hb_map (hb_identity));
|
test_iterator_non_default_constructable (hb_iter (st) | hb_map (hb_identity));
|
||||||
|
|
||||||
hb_any (st);
|
hb_any (st);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue