You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is no way to distinguish between a functor and a lambda.
A functor may be treated the same way as a lambda and get copied into the signal. As a result, the copy gets notified instead of the functor object. This is fine if all the members are pointer or references or the operator only causes global side-effects. However, if we rely on the data in the functor, the result is wrong.
struct stuff{
int x = 0;
void operator()(int y) { x+=y; }
};
stuff s;
sig.connect(s);
sig(10);
cout << s.x; //prints 0 instead of 10
On the other hand, if we treat the functor as a regular object, it may go out of bounds without disconnecting, dangling the callback. In case of a lambda, there is actually no way to save the connection into the structure for an RAII cleanup.
The text was updated successfully, but these errors were encountered:
There is no way to distinguish between a functor and a lambda.
A functor may be treated the same way as a lambda and get copied into the signal. As a result, the copy gets notified instead of the functor object. This is fine if all the members are pointer or references or the operator only causes global side-effects. However, if we rely on the data in the functor, the result is wrong.
On the other hand, if we treat the functor as a regular object, it may go out of bounds without disconnecting, dangling the callback. In case of a lambda, there is actually no way to save the connection into the structure for an RAII cleanup.
The text was updated successfully, but these errors were encountered: