This is the interface I am trying to achieve:
Statement select("SELECT * FROM People WHERE ID > ? AND ID < ?");
select.execute(1462, 1477, [](int ID, std::string const& person, double item1, float item2){
std::cout << "Got Row:"
<< ID << ", "
<< person << ", "
<< item1 << ", "
<< item2 << "\n";
});
Where the '?' in the select string are matched against the variable argument list 1462, 1477 at runtime.
This is the class definition:
class Statement
{
public:
Statement(std::string const&);
template<class Action, class ...Args>
void execute(Args... param, Action action);
};
Unfortunately this generates an error:
test.cpp:133:12: error: no matching member function for call to 'execute'
select.execute(1462, 1477, [](int ID, std::string const& person, double item1, float item2){
~~~~~^~~~~~~test.cpp:86:14: note: candidate template ignored: couldn't infer template argument 'Action'
void execute(Args... param, Action action)
~~~^~~~~~~1 error generated.
But if I change the function definition slightly (below) it compiles fine.
class Statement
{
public:
Statement(std::string const&);
template<class Action, class ...Args>
void execute(Action action, Args... param);
// ^^^^^^^ Move action to the front.
};
// Also changed the call by moving the lambda to the first argument.
I know its some syntactic sugar where the variable argument list goes, but I would like to put the variable argument list first. Are there any tricks I can use to help the compiler deduce the var arg list correctly?
select.execute(1462, 1477)([](int ID...){...})- lethal-guitarauto& bind = select.bind(1462, 1477);- Martin York