make register_signal and auto-generated variadic funcitons use variadic templates to streamline their use
This commit is contained in:
@@ -58,6 +58,42 @@ enum Error {
|
||||
ERR_WTF = ERR_OMFG_THIS_IS_VERY_VERY_BAD ///< short version of the above
|
||||
};
|
||||
|
||||
namespace helpers {
|
||||
template <typename T, typename ValueT>
|
||||
T append_all (T appendable, ValueT value) {
|
||||
appendable.append(value);
|
||||
return appendable;
|
||||
}
|
||||
|
||||
template <typename T, typename ValueT, typename... Args>
|
||||
T append_all (T appendable, ValueT value, Args... args) {
|
||||
appendable.append(value);
|
||||
return append_all(appendable, args...);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T append_all (T appendable) {
|
||||
return appendable;
|
||||
}
|
||||
|
||||
template <typename KV, typename KeyT, typename ValueT>
|
||||
KV add_all (KV kv, KeyT key, ValueT value) {
|
||||
kv[key] = value;
|
||||
return kv;
|
||||
}
|
||||
|
||||
template <typename KV, typename KeyT, typename ValueT, typename... Args>
|
||||
KV add_all (KV kv, KeyT key, ValueT value, Args... args) {
|
||||
kv[key] = value;
|
||||
return add_all(kv, args...);
|
||||
}
|
||||
|
||||
template <typename KV>
|
||||
KV add_all (KV kv) {
|
||||
return kv;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -484,6 +484,11 @@ void register_signal(String name, Dictionary args = Dictionary())
|
||||
}
|
||||
}
|
||||
|
||||
template<class T, class... Args>
|
||||
void register_signal(String name, Args... varargs)
|
||||
{
|
||||
register_signal<T>(name, helpers::add_all(Dictionary(), varargs...));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user