Your latest example above would not work if that piece of code was executed more than once because the static_lambda would contain a dangling reference to an old version of c that no longer exist. You can indeed use global and static variables from lambdas without capturing them but you need to be a bit careful with that. Update: After reading more carefully that is actually not what you are saying. What you are essentially saying is that you want to capture a lambda from a capturless lambda, but that doesn't make sense, because if it captures it's no longer capturless. A pointer to a member function is useless unless you have an object to call it on. The situation is similar to that of pointers to member functions. If you were able to convert a capturing lambda into a function pointer you would lose everything that had been captured. the lambda body) does not use anything within the object (because it's empty). In C, lambda is not naturely supported, so you have to define a function by name and pass a pointer. This should be fine because the code that the function pointer refers to (i.e. A lambda that does not capture anything can be implicitly converted to a function pointer. You can think of a lambda as creating an object that contains a function pointer plus everything that has been captured. So the idea is to wrap capturing lambda in capturless one :)Ī function pointer is just a pointer to some piece of code. #include #include #include using FrameCallback = int(*)( int, int)
0 Comments
Leave a Reply. |