mirror of
https://github.com/matrix-construct/construct
synced 2025-01-15 17:16:49 +01:00
ircd::util::callbacks: Add a callback convenience template.
This commit is contained in:
parent
7192a75ac5
commit
2d83f2c201
1 changed files with 30 additions and 0 deletions
|
@ -39,7 +39,9 @@ template<class prototype>
|
|||
struct ircd::util::callbacks<prototype, true>
|
||||
:std::list<std::function<prototype>>
|
||||
{
|
||||
struct callback;
|
||||
using proto_type = prototype;
|
||||
using list_type = std::list<std::function<prototype>>;
|
||||
|
||||
template<class... args>
|
||||
void operator()(args&&... a) const
|
||||
|
@ -59,7 +61,9 @@ template<class prototype>
|
|||
struct ircd::util::callbacks<prototype, false>
|
||||
:std::list<std::function<prototype>>
|
||||
{
|
||||
struct callback;
|
||||
using proto_type = prototype;
|
||||
using list_type = std::list<std::function<prototype>>;
|
||||
|
||||
template<class... args>
|
||||
void operator()(args&&... a) const
|
||||
|
@ -81,3 +85,29 @@ struct ircd::util::callbacks<prototype, false>
|
|||
callbacks &operator=(callbacks &&) = default;
|
||||
callbacks &operator=(const callbacks &) = delete;
|
||||
};
|
||||
|
||||
template<class prototype>
|
||||
struct ircd::util::callbacks<prototype, true>::callback
|
||||
:util::unique_iterator<list_type>
|
||||
{
|
||||
template<class function>
|
||||
callback(callbacks &c, function&& f)
|
||||
:util::unique_iterator<list_type>
|
||||
{
|
||||
c, c.emplace(end(c), std::forward<function>(f))
|
||||
}
|
||||
{}
|
||||
};
|
||||
|
||||
template<class prototype>
|
||||
struct ircd::util::callbacks<prototype, false>::callback
|
||||
:util::unique_iterator<list_type>
|
||||
{
|
||||
template<class function>
|
||||
callback(callbacks &c, function&& f)
|
||||
:util::unique_iterator<list_type>
|
||||
{
|
||||
c, c.emplace(end(c), std::forward<function>(f))
|
||||
}
|
||||
{}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue