1

I've a little problem in my code. I try to create a function with variadic parameter, but when I compile it, it fail, and i really don't see why. So if anyone could help me ...

here is my function:

QuerySet.hpp:

template <typename T>
class QuerySet
{
   template<typename U,typename ... Args>
   QuerySet& filter(const std::string& colum,Args ... args,const std::string& operation, const U& value);
   //...
}

template<typename T>
template<typename U,typename ... Args>
QuerySet<T>& QuerySet<T>::filter(const std::string& colum,Args ... args,const std::string& operation, const U& value)
{
     //some job
     return *this;
}

main.cpp QuerySet queryset; queryset.filter(Perso::_master,Perso::_lvl,"gt",4); //line 135

Note: Perso::_master and Perso::_lvl are some static const std::string;

Error:

g++ -g -std=c++0x -I"/my_path/cpp-ORM" -lmysqlcppconn   -o main.o -c main.cpp;
main.cpp: In function ‘int main(int, char**)’:
main.cpp:135:46: erreur: no matching function for call to ‘orm::QuerySet<Perso>::filter(const string&, const string&, const string&, int)’
main.cpp:135:46: note: candidate is:
/my_path/QuerySet.hpp:18:23: note: template<class U, class ... Args> orm::QuerySet<T>& orm::QuerySet::filter(const string&, Args ..., const string&, const U&) [with U = U, Args = {Args ...}, T = Perso, std::string = std::basic_string<char>]

Informations : I use gcc version 4.6.4 (Ubuntu/Linaro 4.6.4-1ubuntu1~12.04), but I try with gcc4.8, and I've a error to.

Krozark
  • 862
  • 9
  • 27

2 Answers2

4

The variadic parameter pack must occur at the end of the function signature, not in the middle.

For better understanding read this: Variadic function template with pack expansion not in last parameter

Community
  • 1
  • 1
ApEk
  • 41
  • 4
3

Your functions can never be called, that's a context where template parameters cannot be deduced:

n3337, 14.8.2.1/1 [temp.deduct.call]

Template argument deduction is done by comparing each function template parameter type (call it P) with the type of the corresponding argument of the call (call it A) as described below.
[...]
For a function parameter pack that occurs at the end of the parameter-declaration-list, the type A of each remaining argument of the call is compared with the type P of the declarator-id of the function parameter pack. Each comparison deduces template arguments for subsequent positions in the template parameter packs expanded by the function parameter pack. For a function parameter pack that does not occur at the end of the parameter-declaration-list, the type of the parameter pack is a non-deduced context.
[...]

Move the argument pack to the end of function's parameter list.

You could get away with specifying the template parameters explicitly, but I assume that's not what you want. E.g:

q.filter<int, int, int>("oi", 1, 2, "oi", i);
jrok
  • 54,456
  • 9
  • 109
  • 141