]> git.tdb.fi Git - libs/datafile.git/blobdiff - source/loaderaction.h
Use variadic templates and forwarding references for better flexibility
[libs/datafile.git] / source / loaderaction.h
index 9d5baae63aa4de770a70eb7ef7a99f05f1099d43..23298428df659303185075b212c7ada5604d6778 100644 (file)
@@ -174,15 +174,15 @@ template<unsigned I>
 struct Apply<I>
 {
        template<typename L, typename F, typename... Args>
-       static void apply(L &l, F func, const Statement &, Args... args)
+       static void apply(L &l, F func, const Statement &, Args &&... args)
        {
-               (l.*func)(args...);
+               (l.*func)(std::forward<Args>(args)...);
        }
 
        template<typename L, typename F, typename... Args>
-       static void apply(L &l, F func, const ArgumentStore &, Args... args)
+       static void apply(L &l, F func, const ArgumentStore &, Args &&... args)
        {
-               (l.*func)(args...);
+               (l.*func)(std::forward<Args>(args)...);
        }
 };
 
@@ -190,15 +190,15 @@ template<unsigned I, typename Head, typename... Tail>
 struct Apply<I, Head, Tail...>
 {
        template<typename L, typename F, typename... Args>
-       static void apply(L &l, F func, const Statement &st, Args... args)
+       static void apply(L &l, F func, const Statement &st, Args &&... args)
        {
-               Apply<I+1, Tail...>::apply(l, func, st, args..., st.args[I].get<Head>());
+               Apply<I+1, Tail...>::apply(l, func, st, std::forward<Args>(args)..., std::move(st.args[I].get<Head>()));
        }
 
        template<typename L, typename F, typename... Args>
-       static void apply(L &l, F func, const ArgumentStore &as, Args... args)
+       static void apply(L &l, F func, const ArgumentStore &as, Args &&... args)
        {
-               Apply<I+1, Tail...>::apply(l, func, as, args..., as.get<Head>(I));
+               Apply<I+1, Tail...>::apply(l, func, as, std::forward<Args>(args)..., std::move(as.get<Head>(I)));
        }
 };
 
@@ -240,7 +240,8 @@ protected:
        Bound0Type bound0;
 
 public:
-       LoaderFuncNBound1(FuncType f, const Bound0Type &b0): func(f), bound0(b0) { }
+       LoaderFuncNBound1(FuncType f, const B0 &b0): func(f), bound0(b0) { }
+       LoaderFuncNBound1(FuncType f, B0 &&b0): func(f), bound0(std::move(b0)) { }
 
        virtual void execute(Loader &l, const Statement &st) const
        {