Community
cancel
Showing results for 
Search instead for 
Did you mean: 
compila
Beginner
48 Views

How to pass a closure to the function?

Hello All!

I am using Intel C++ compiler 11.1 for Linux.
How to pass a closure to the function?
For example:
[cpp]class C
{
    void function(TYPE closure);
}[/cpp]
What TYPE should I specify, to use the following code:
[cpp]int main(void){
    C c;

    c.function([&](int x,int y){
                      return x+y;
                   });

    return 0;
}[/cpp]
Thanks!
0 Kudos
1 Reply
compila
Beginner
48 Views

I figured it out!
Something like this:
[cpp]class C{
public:
     template
     void function(const CL& closure);
};

template
void C::function(const CL& closure){
     closure(1,2,3);
}

int main(){
     C c;
     c.function([&](int x,int y,int z){cout << x << y << z ;});

     return 0;
}
[/cpp]
Reply