Unpack variadic arguments into QGenericArguments without boost::tuple.

This commit is contained in:
John Maguire 2012-11-22 17:57:26 +01:00
parent 8171192df5
commit 4e9231976e
2 changed files with 15 additions and 29 deletions

View File

@ -48,15 +48,7 @@ void ObjectHelper::Invoked() {
deleteLater(); deleteLater();
} }
template<> void Unpack(QList<QGenericArgument>*) {}
void Arg<boost::tuples::tuple<>>(
const boost::tuples::tuple<>&,
QList<QGenericArgument>* list) {}
template<>
void Arg<boost::tuples::null_type>(
const boost::tuples::null_type&,
QList<QGenericArgument>* list) {}
} // namespace _detail } // namespace _detail

View File

@ -26,7 +26,6 @@
#include <boost/function.hpp> #include <boost/function.hpp>
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
#include <boost/tuple/tuple.hpp>
namespace _detail { namespace _detail {
@ -65,25 +64,21 @@ class ObjectHelper : public QObject {
Q_DISABLE_COPY(ObjectHelper); Q_DISABLE_COPY(ObjectHelper);
}; };
// Helper to unpack a tuple into a QList. // Helpers for unpacking a variadic template list.
template<typename T>
void Arg(const T& tail, QList<QGenericArgument>* list) { // Base case of no arguments.
typedef decltype(tail.get_head()) HeadType; void Unpack(QList<QGenericArgument>*);
list->append(Q_ARG(HeadType, tail.get_head()));
Arg(tail.get_tail(), list); template <typename Arg>
void Unpack(QList<QGenericArgument>* list, const Arg& arg) {
list->append(Q_ARG(Arg, arg));
} }
// Specialisation for starting with an empty tuple, ie. no arguments. template <typename Head, typename... Tail>
template<> void Unpack(QList<QGenericArgument>* list, const Head& head, const Tail&... tail) {
void Arg<boost::tuples::tuple<>>( Unpack(list, head);
const boost::tuples::tuple<>&, Unpack(list, tail...);
QList<QGenericArgument>* list); }
// Specialisation for the end of a tuple, where get_tail() returns null_type.
template<>
void Arg<boost::tuples::null_type>(
const boost::tuples::null_type&,
QList<QGenericArgument>* list);
template <typename... Args> template <typename... Args>
class Closure : public ClosureBase { class Closure : public ClosureBase {
@ -111,9 +106,8 @@ class Closure : public ClosureBase {
private: private:
void Call(const Args&... args) { void Call(const Args&... args) {
auto t = boost::make_tuple(args...);
QList<QGenericArgument> arg_list; QList<QGenericArgument> arg_list;
Arg(t, &arg_list); Unpack(&arg_list, args...);
slot_.invoke( slot_.invoke(
receiver_, receiver_,