0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 10:12:39 +01:00

ircd::ctx: Simplify list iteration API.

This commit is contained in:
Jason Volk 2018-04-19 14:47:56 -07:00
parent 1d451ca3ff
commit 793c24ce9e
2 changed files with 27 additions and 31 deletions

View file

@ -45,19 +45,15 @@ class ircd::ctx::list
ctx *front(); ctx *front();
ctx *back(); ctx *back();
// until convention
bool until(const std::function<bool (const ctx &)> &) const;
bool until(const std::function<bool (ctx &)> &);
// reverse until convention
bool runtil(const std::function<bool (const ctx &)> &) const;
bool runtil(const std::function<bool (ctx &)> &);
// iteration // iteration
bool for_each(const std::function<bool (const ctx &)> &) const;
bool for_each(const std::function<bool (ctx &)> &);
void for_each(const std::function<void (const ctx &)> &) const; void for_each(const std::function<void (const ctx &)> &) const;
void for_each(const std::function<void (ctx &)> &); void for_each(const std::function<void (ctx &)> &);
// reverse iteration // reverse iteration
bool rfor_each(const std::function<bool (const ctx &)> &) const;
bool rfor_each(const std::function<bool (ctx &)> &);
void rfor_each(const std::function<void (const ctx &)> &) const; void rfor_each(const std::function<void (const ctx &)> &) const;
void rfor_each(const std::function<void (ctx &)> &); void rfor_each(const std::function<void (ctx &)> &);

View file

@ -1311,6 +1311,27 @@ const
closure(*tail); closure(*tail);
} }
bool
ircd::ctx::list::rfor_each(const std::function<bool (ctx &)> &closure)
{
for(ctx *tail{this->tail}; tail; tail = prev(tail))
if(!closure(*tail))
return false;
return true;
}
bool
ircd::ctx::list::rfor_each(const std::function<bool (const ctx &)> &closure)
const
{
for(const ctx *tail{this->tail}; tail; tail = prev(tail))
if(!closure(*tail))
return false;
return true;
}
void void
ircd::ctx::list::for_each(const std::function<void (ctx &)> &closure) ircd::ctx::list::for_each(const std::function<void (ctx &)> &closure)
{ {
@ -1327,28 +1348,7 @@ const
} }
bool bool
ircd::ctx::list::runtil(const std::function<bool (ctx &)> &closure) ircd::ctx::list::for_each(const std::function<bool (ctx &)> &closure)
{
for(ctx *tail{this->tail}; tail; tail = prev(tail))
if(!closure(*tail))
return false;
return true;
}
bool
ircd::ctx::list::runtil(const std::function<bool (const ctx &)> &closure)
const
{
for(const ctx *tail{this->tail}; tail; tail = prev(tail))
if(!closure(*tail))
return false;
return true;
}
bool
ircd::ctx::list::until(const std::function<bool (ctx &)> &closure)
{ {
for(ctx *head{this->head}; head; head = next(head)) for(ctx *head{this->head}; head; head = next(head))
if(!closure(*head)) if(!closure(*head))
@ -1358,7 +1358,7 @@ ircd::ctx::list::until(const std::function<bool (ctx &)> &closure)
} }
bool bool
ircd::ctx::list::until(const std::function<bool (const ctx &)> &closure) ircd::ctx::list::for_each(const std::function<bool (const ctx &)> &closure)
const const
{ {
for(const ctx *head{this->head}; head; head = next(head)) for(const ctx *head{this->head}; head; head = next(head))