I suggest you ...

Add lambda support to C++/CLI

Lambda is now supported in C++ 0x but not in C++/CLI. It means we are not able to use C++ lambda to define delegates in ref class. This makes using .Net libraries like Task<T> and System::Linq a very tedious work.

165 votes
Vote
Sign in
(thinking…)
Password icon
Signed in as (Sign out)
You have left! (?) (thinking…)
Justin Shen shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

6 comments

Sign in
(thinking…)
Password icon
Signed in as (Sign out)
Submitting...
  • Anonymous commented  ·   ·  Flag as inappropriate

    NUnit uses C# lambdas in a number of cases, in particular under `Assert.Multiple`. So it would be nice if those APIs could be accessible from C++.

    If anyone is interested in this particular use case, please also see https://github.com/nunit/nunit/issues/2612 and provide any ideas you may have.

  • David Hunter commented  ·   ·  Flag as inappropriate

    I just realized there is one C++ lambda feature that is no possible in C++/CLI. You can't define a
    C++ lambda inside the body of a managed type member function. This seems a bit stricter than not being able to define a C++ class inside a Managed class. The C++ lambda may represent a class but it is an anonymous one so I would think the compiler could treat it in a special way.

  • pgroke commented  ·   ·  Flag as inappropriate

    I also think that "extending the extension" would be the way to go: don't try to make C++11 lambdas somehow work with .NET, but provide an additional lambda syntax that creates a .NET lambda. The closer to the C# x => f(x) syntax the better.

  • David Hunter commented  ·   ·  Flag as inappropriate

    I'm a bit confused by this. C++ lambda are supported by C++/CLI but .NET lambdas are not. The suggestion seems to talk about C++ 0x and then LINQ. Anyway I would love to see .NET lambdas supported by C++/CLI, capturing unmanaged types in them would be an extra bonus!

Feedback and Knowledge Base