1 #ifndef QTSERVICE_HELPERTYPES_H 2 #define QTSERVICE_HELPERTYPES_H 7 #include <QtCore/qvariant.h> 10 namespace __helpertypes {
13 struct fn_info :
public fn_info<decltype(&T::operator())> {};
15 template <
typename TClass,
typename TRet,
typename... TArgs>
16 struct fn_info<TRet(TClass::*)(TArgs...) const>
18 template <
typename TFunctor>
19 static inline std::function<QVariant(QVariantList)> pack(
const TFunctor &fn) {
20 return pack(std::make_index_sequence<
sizeof...(TArgs)>{}, fn);
23 template <
typename TFunctor, std::size_t... Is>
24 static inline std::function<QVariant(QVariantList)> pack(
const std::index_sequence<Is...> &,
const TFunctor &fn) {
25 return [fn](
const QVariantList &args) {
27 return QVariant::fromValue<TRet>(fn(args[Is].
template value<std::decay_t<TArgs>>()...));
32 template <
typename TClass,
typename... TArgs>
33 struct fn_info<void(TClass::*)(TArgs...) const>
35 template <
typename TFunctor>
36 static inline std::function<QVariant(QVariantList)> pack(
const TFunctor &fn) {
37 return pack(std::make_index_sequence<
sizeof...(TArgs)>{}, fn);
40 template <
typename TFunctor, std::size_t... Is>
41 static inline std::function<QVariant(QVariantList)> pack(
const std::index_sequence<Is...> &,
const TFunctor &fn) {
42 return [fn](
const QVariantList &args) {
44 fn(args[Is].
template value<std::decay_t<TArgs>>()...);
50 template <
typename TFunc>
51 inline std::function<QVariant(QVariantList)> pack_function(
const TFunc &fn) {
52 return fn_info<TFunc>::pack(fn);
57 #endif // QTSERVICE_HELPERTYPES_H The primary namespace of the QtService library.