lambda not working with template function

Hi,

I have the following template function:

template<typename F, typename ...T>
void call( F&& f, T&&... t) {

f(std::forward<T>(t)...);
}

It works fine with:

int i = 99;
const char p[] {"Trying"};

call(g2<int,const char [7]>, i, p);


But not with:


call( [](int i){ cout << "lambda2(int): " << endl; });

I get:

no matching function for call to object of type '(lambda at ....)'

What is going on??

Thanks for the help

Juan
Your parameterized call function requires (at least) two arguments and isn't getting them.
I think that's no it because the first argument is a function (in this case a lambda) and the second would be the integer parameter to the lambda...


Makes sense?

Thanks

Juan
To be specific, the following call DOES NOT produce errors (and it only takes 1 parameter, the lambda):

call( [](){ cout << "lambda1()\n"; });

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>

template< typename F, typename ...T > void call( F&& f, T&&... t) {

    std::forward<F>(f)( std::forward<T>(t)... );
}

int main() {
    
    call( [] { std::cout << "nullary closure()\n" ; } ) ; // fine: empty argument pack
    // call( [](){ std::cout << "nullary closure()\n" ; }, 100 ) ; // *** error: too many arguments

    call( [] (int) { std::cout << "unary closure(int)\n" ; }, 100 ) ; // fine: argument pack of size one
    // call( [] (int) { std::cout << "unary closure(int)\n" ; } ) ; // *** error: too few arguments
    // call( [] (int) { std::cout << "unary closure(int)\n" ; }, 100, 200 ) ; // *** error: too many arguments

    call( [] (int,int) { std::cout << "binary closure(int,int)\n" ; }, 100, 200 ) ; // fine: argument pack of size two
    // call( [] (int,int) { std::cout << "binary closure(int,int)\n" ; }, 100 ) ; // *** error: too few arguments
    // call( [] (int,int) { std::cout << "binary closure(int,int)\n" ; }, 100, 200, 300 ) ; // *** error: too many arguments
}

http://coliru.stacked-crooked.com/a/c8055c99158203e2
Topic archived. No new replies allowed.