c++ cli - Workaround for not having lambdas that can capture managed variables -
in c++/cli, cannot create managed lambdas (like can in c#), , can't capture managed variables. can create regular methods (rather lambdas), still left without being able capture managed variables.
is there standard workaround employ in c++/cli code? in other words i'm looking standard pattern use in c++/cli following c#:
class { } class b { void foo() { a = new a(); func<a> afunc = () => a; // captures } }
i
- create member variable each variable want capture, , in delegate use member variable. wouldn't work in general case might have 2 invocations of method want work on different captured a's, work common case.
- create nested class capturing in ctor, , use method of nested class delegate. should work in general case, means need nested class every time want capture different variables.
question: there better option ones above, or option above go-to approach?
related questions:
if @ decompilation of c# lambda, you'll see c# compiler same thing option #2. it's annoying create bunch of single-use classes, that's i'd recommend.
with c# lambda, when creates nested class instance, uses everywhere instead of local variable. keep in mind write method uses nested class.
Comments
Post a Comment