I saw an snippet CC source such as.
imagecb = [ &, xx, yy, zz] (uint32_t a1, int a2) {
...
}
- I did know what is symbol of & in the array
- this syntax declare an inline functions with 2 arguments a1, a2, right?
I saw an snippet CC source such as.
imagecb = [ &, xx, yy, zz] (uint32_t a1, int a2) {
...
}
it is not the array, it is a lambda expression. Between []
you pass elements from another scope that you need inside expression. &
means to get all elements that you need by reference.
In this specific case, variables xx, yy, zz
will be copied, but if let's say this lambda expression uses another variable like for example aa
it will be passed by reference.
It is worth mentioning that even if the element is passed by reference to a lambda expression, it cannot be modified (in default). To allow modification you need to use keyword mutable
Little code sample:
int xx=0, yy=0, zz=0;
int aa=1;
auto imagecb = [&, xx, yy, zz](uint32_t a1, int a2) mutable {
cout << aa;
aa++;
return aa;
};
cout << endl<<imagecb(2, 3);