C/C++LI Lambda selector for LINQ static method
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
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- , 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. ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- [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. ...
Recent Posts
- [Algorithm Notes]B1055 Group Photo
Ideas:  Sort the entered names and heights in descending order, then adjust the position of each row and output. When adjusting the position, it is easier to first determine the center and then adjust one side.#includeusing namespace std;const int maxn = 10010;struct student{ string name; ...
- Enumeration in Java--Enumeration
  I didn't notice the knowledge point of enumeration before, because enumeration has not been used in the project before. Maybe the reason is that the project is not very complicated. Today, I read Mr. Zhang Xiaoxiang's explanation, and I think this enumeration is really useful. There are ...
- uses python attribute in __init__?
I have a class that uses several properties() . Modifying the font, size or string etc of the text will require re-rendering the surface for caching.What is the recommended way to call a class's own properties() in init? The problem is that the variable isn't set yet, when I want to call @property D...
- the best way for JavaScript to "interleave" two arrays of JSON objects via a common property?
Suppose we have two arrays of JSON objects arr1 and arr2 that share a common property id:var arr1 = [{'id':10,'value1':'a1'}, {'id':11,'value1':'b1'}, {'id':12,'value1':'c1'}, {'id':13,'value1':'d1'}, {'id':14,'value1':'e1'}];var arr2 = [{'id':100000,'value2':'a2'}, {'id':11,'value2':'b2'}, {'id':10...
- java-Https WebService Message: Message does not contain a valid Security element
I am using axis 2 web service client.The first https call to the web service throws an exception with the following message:"The message does not contain a valid security element".I think the problem might be with the security mode: maybe it has to be message level security. In this case, how to con...
- sword point offer2: Replacement spaces implemented by C++
1. Topic descriptionPlease implement a function to replace spaces in a string with"%20". For example, when the string is We Are Happy., the replaced string is We%20Are%20Happy.2. Ideas and methods:2.1 Not recommended method:Simple violent solution, traverse the string from beginning to end, when enc...
- java - When drag and drop back to GridBagLayout, JToolBar IllegalArgumentException
Why does this code throw an IllegalArgumentException when the toolbar is dragged out of the GUI and then closed (returning it to the GUI)?I can understand why it might be inappropriate to add a component without constraints, but in this case the initial addition of the Toolbar to the panel (using Gr...
- java - how many Jolokia agents need to be installed?
Say I have 4 8 java server applications (actually instances of the same java application) running in 4 linux boxes (2 each). I want to be able to monitor these from another linux box using Jolokia application.I also need to be able to start and stop these Java applications. Can Jolokia help?Do I nee...
- Weka 3.8.1 cannot link to mtj.jar, resulting in java.lang.ClassNotFoundException: no.uib.cipr.matrix.Matrix
I'm working with some data in weka and want to use the weka API so that I can use a custom algorithm. However, when I just want to instantiate the LinearRegression class: LinearRegression myRegression = new LinearRegression() I get the same error as the following error : This person got the same pro...
- LMFIT on Python: TypeError: can only convert array of size-1 to Python scalar
I'm trying to create a curve fitting program using LMFIT on python (Anaconda), but I keep getting the same error message: TypeError: only arrays of size 1 can be converted to Python scalars. I can only use one function to perform the optimization , but when I try to optimize a function that calls ot...