mirror of
https://github.com/matrix-construct/construct
synced 2024-11-25 16:22:35 +01:00
ircd::ctx: Simplify list iteration API.
This commit is contained in:
parent
1d451ca3ff
commit
793c24ce9e
2 changed files with 27 additions and 31 deletions
|
@ -45,19 +45,15 @@ class ircd::ctx::list
|
|||
ctx *front();
|
||||
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
|
||||
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 (ctx &)> &);
|
||||
|
||||
// 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 (ctx &)> &);
|
||||
|
||||
|
|
46
ircd/ctx.cc
46
ircd/ctx.cc
|
@ -1311,6 +1311,27 @@ const
|
|||
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
|
||||
ircd::ctx::list::for_each(const std::function<void (ctx &)> &closure)
|
||||
{
|
||||
|
@ -1327,28 +1348,7 @@ const
|
|||
}
|
||||
|
||||
bool
|
||||
ircd::ctx::list::runtil(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)
|
||||
ircd::ctx::list::for_each(const std::function<bool (ctx &)> &closure)
|
||||
{
|
||||
for(ctx *head{this->head}; head; head = next(head))
|
||||
if(!closure(*head))
|
||||
|
@ -1358,7 +1358,7 @@ ircd::ctx::list::until(const std::function<bool (ctx &)> &closure)
|
|||
}
|
||||
|
||||
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
|
||||
{
|
||||
for(const ctx *head{this->head}; head; head = next(head))
|
||||
|
|
Loading…
Reference in a new issue