I have this in C/C++LI (Visual Studio 2012)

Enumerable::Max((IEnumerable^) Foos, [](IFoo^ f){return f->Id;});

but it results in this error:

No instance of overloaded function “System::Linq::Enumerable::Max”
matches argument list

It frustrates me because there is nothing wrong with the lambda. Do I need to cast it to the Func somehow?

Solution:

The C/C++ LI compiler does not support C++11 lambda expressions, they cannot be converted to delegate objects. While .NET had a big head start, support for managed lambdas was never added, and certainly never will be.

You need a delegate object with a helper function that returns IFoo->id that looks like this:

int returnId(IFoo^ obj) { return obj->Id; }... int max = Enumerable::Max((IEnumerable^) Foos, gcnew Func(returnId));

C/C++LI Lambda selector for LINQ static method Related posts

  1. F# Concise Tutorial One: Overview of F# and Functional Programming

    F# is a programming language of Microsoft's .NET development platform. Its biggest feature is the introduction of functional programming (FP, Functional Programming); F# also has excellent support for object-oriented (OOP) programming. Use F# language to develop People can freely choose functional p ...

  2. javascript-How to implement f(g)== g(f)

    I answered a question yesterday, and it reminded me of an interesting (for me) puzzleDue to restrictions on the use of lambda, number and only (no if,?: or other language features), the goal is to achieve some f and some g like this// contractf(x) => f'g(y) => g'f'(g') == g'(f')// or more simp ...

  3. Reserve field names at F#/C# boundary

    As a learning exercise, I'm doing some data analysis on a 5000 row csv file using F# and F#'s type provider functionality. When I use a type provider-generated type in f#, the header row of the csv file naturally becomes that type field name of .type restaurantCsv = CsvProvider<"C:\Users\Paul\Des ...

  4. c#-implement interface in f#

    This is my c# interface:public interface ITemplateService{ string RenderTemplate(object model, string templateName); string RenderTemplate(object model, string templateName, string directory);}I am trying to implement in F#, but I get an error at the end of the keyword. (Unexpected end in implementa ...

  5. C++ core criterion F.50: Use lambda expressions when you are unwilling to use functions

    F.50: Use a lambda when a function won't do (to capture local variables, or to write a local function) F.50: Use lambda expressions when you are unwilling to use functions (for example, read local variables, access local functions) Reason Functions can't capture local variables or ...

  6. c#-Create native functions in F#

    For example, I have 2 additional functions:module Addlet add2 a = let innerFn a = a + 2 innerFn alet add2' a = let innerFn' () = a + 2 innerFn' ()let res1 = add2 0let res2 = add2' 1As far as I know, both innerFns will be compiled into FSharpFunc<int,int> and FSharpFunc<unit,int> are init ...

  7. python-NameError Use "finally: f.close()" and "with open(..)as f" together

    I have code like below in python. I am using the'with' keyword to open the file and parse its content. But when I try to close the file an error occurs. Please help.Error message:"NameError: name'f' is not defined"try: user_xml_name = raw_input('Enter the xml name: ') xml_name = user_xml_name.replac ...

  8. c# - Dynamically create an expression that selects object properties

    I want to be able to dynamically build an expression which is essentially an attribute selector.I'm trying to use this in order to provide a flexible search UI and then convert selected search parameters into Entity Framework queries.Since another library is used, I have most of the resources I need ...

  9. php-About $_FILES ['MF__F_0_0'], what does MF__F_0_0 mean?

    My dilemma comes from a function in a WordPress plugin called NextGen Public Uploader. In handleUpload(), the value of $_FILES ['MF__F_0_0'] ['error'] is used to determine whether the upload failed. MF__F_0_0 is not in $_FILES Named fields. Also, I can't find any references or discussions of keys or ...

  10. Pass the expression and lambdas parameters to the C# extension method in F#

    I am trying to solve this problem because I am just a beginner in F#, and currently I am learning F#, by creating unit tests for C# code in F#, as shown in F#, for fun and profit.problem.I have the following C# classpublic class ObjectMapper where TTarget: class, new() {public readonly TSource Sourc ...

  11. c#-How to get the attribute name string used in Func of F

    I have a scenario where I have to get an array of strings representing each attribute name used in the Func parameter. Here is a sample implementation:public class CustomClass{ public string[] GetPropertiesUsed { get { // do magical parsing based upon parameter passed into CustomMethod } } public void CustomMethod(Func method) { // do stuff } }This is an example usage:var customClass = new CustomClass(); customClass.CustomMethod(src =>"("+ src.AreaCode +")"+ src.Phone); ... var propertiesUsed ...

  12. [python] c, m, F, f, v, p in PyCharm meaning

    The difference between function (Function) and method (Method) in Python:Functions that are not bound to classes and instances belong to functions;Functions that are bound to classes and instances belong to methods. ...

  13. F# hurts my brain... Can anyone help translate C# to F#?

    I found a quick project that I think is very suitable for learning F#. However, for some reason, I cannot wrap my brain. After a few hours of tutorials, and even some movies, I still just...don’t understand.So I want to use Enterprise Manager"Generate Scripts"to start version control of our stored p ...

  14. , what does -f stand for in "php -f"?

    What does"-f"say* * * * * php -f myscript.phprepresent?Solution:According to the PHP command line option reference: http://php.net/manual/en/features.commandline.options.php, the -f option indicates which file the PHP engine should execute, in this case myscript.php. ...

  15. F#CSV parsing to C# application

    I have a C# console application that calls the F# library, which does some CSV parsing by using CSVTypeProvider. (http://fsharp.github.io/FSharp.Data/reference/fsharp-data-csvprovider.html )Unfortunately, I am new to F#, so I haven't found a way to efficiently pass parsed data from F# to C# in the form of a list of C# objects.Suppose I have a C# data model:public class Customer{ public int ID { get; set; } public string Name { get; set; } }Then I want to convert the data from the csv type provid ...

  16. F# properties and C# properties

    When developing F# applications, my type contains Lazy<'T> type attributes.Obviously, an interesting side effect (forgive the pun) of the way F# handles the syntactic sugar of properties (as opposed to the C# way) is that property getters and setters may return/accept different types. (At leas ...

Recent Posts

  1. php-Xampp: Web browser will not display localhost page

    I installed xampp on Windows7 (64 bit). I want to use PHP, Apache and MySql. The server Apache and MySql service are running normally on the Xampp control panel. But when I run localhost on my web browser, it only Show connection. Nothing else. Compared to the previous environment, it works well wit...

  2. c#-What is the audio playback framework in WPF?

    I know this may sound like a subjective question, but I need some educated opinions on this subject:In C#/WPF GUI, I need to play shortwave files as a response to user interaction. The specifications are as follows:> Low latency (start playing immediately) > The code should be native C# (.NET ...

  3. C# Knowledge points note: the use of IEnumerable<>

    Create an IEnumerable object Listfruits = new List{"apple","pear","banana","orange"};IEnumerablef = fruits as IEnumerable;The obtained iterator initially points to empty//After obtaining the Enumerator, the current pointer is empty var o = em.Current; Console.WriteLine("Is the current pointer empty"...

  4. Data Structure and Algorithm——KMP Algorithm Template

    KMP algorithmThe KMP algorithm refers to the string pattern matching algorithm. The problem is: find the starting position when the complete substring P appears for the first time in the main string T. The algorithm was discovered by three big cows: DEKnuth, JHMorris, and VRPratt at the same time, n...

  5. javascript-define each part of the image and assign it to hover, click event

    Let's say that we have a human image, and I hope that when the user hover over a part of the body (head, arms, etc.), this organ will turn green when he clicks on a defined action.Can it use JavaScript? If so, what is the concept?Reason for asking:Purpose:This is only a small part of the existing it...

  6. python – the difference between run_wsgi_app and wsgiref.handlers.CGIHandler

    I just learned how to use python and GAE, and I noticed that the main URL handler is displayed in two different ways. What is the difference between calling run_wsgi_app vs wsgiref.handlers.CGIHandler? I have seen sample code shown in two ways.application = webapp.WSGIApplication( [('/', MainPage), ...

  7. php-How to insert table data and select from another table?

    I want to do something like this:My tb_b:--------------- B | C // Columns---------------'y' |'z' // row- --------------For example: insert tb_a(a,b,c) value ('x',SELECT * from tb_b)I want this result:My tb_a:----------------- A | B | C // Columns-----------------'x' | ' y'|'z' // row----------------...

  8. Python-How to use and manipulate files in the directory in parallel

    Current scenario: I have 900 files in a directory named directoryA. These files are named file0.txt through file 899.txt, and each file size is 15MB. I traverse each file in order in python. I will each The files are loaded as a list, perform some operations, and write out the output files in direct...

  9. Does Android support Java 11?

    I am new to android development. I installed eclipse, java 11 and android sdk tools on my computer. However, when I try to build a project, it says to upgrade the tools. But I have installed the latest sdk.When I read it online, I found that android does not fully support java SE, and it mainly supp...

  10. c#-Set low thread priority for heavy tasks

    First of all, thank you for all your replies!I want to be more specific-I have a website that displays some current and historical reports. I want to be able to allow users to delete all or part of their history while still browsing the website.Therefore, I want to run a separate thread to handle de...