]> 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 6931f4849ff21ff6fee354fb9ac904011422e284..23298428df659303185075b212c7ada5604d6778 100644 (file)
@@ -24,9 +24,9 @@ Base class for loader actions.
 class LoaderAction
 {
 protected:
-       LoaderAction() { }
+       LoaderAction() = default;
 public:
-       virtual ~LoaderAction() { }
+       virtual ~LoaderAction() = default;
 
        /** Called to process a statement. */
        virtual void execute(Loader &, const Statement &) const = 0;
@@ -113,8 +113,8 @@ public:
        {
                std::vector<A0> values;
                values.reserve(st.args.size());
-               for(Statement::Arguments::const_iterator i=st.args.begin(); i!=st.args.end(); ++i)
-                       values.push_back(i->get<A0>());
+               for(const Value &a: st.args)
+                       values.push_back(a.get<A0>());
                (dynamic_cast<L &>(l).*func)(values);
        }
 
@@ -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
        {