Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7956 Discussions

How to pass a closure to the function?

compila
Beginner
279 Views
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
279 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]
0 Kudos
Reply