Nested Enumerable::Any in C++/CLI (difficult++)

I frequently use the construct in C# (C-Sharp) to cross-reference the contents of two repositories simultaneously with one compound command:

IEnumerable<string> arr_strSources = new string[]{"Alpha", "Bravo", "Charlie", "Delta"};
IEnumerable<string> arr_strPieces = new string[] { "phha", "lie", "zelt" };
bool blnRetVal = arr_strPieces.Any(strPiece => arr_strSources.Any(strSource => strSource.Contains(strPiece)));
System.Diagnostics.Debug.WriteLine("Found = {0}", blnRetVal);

That code searches for the presence of ANY string in arr_strSources that contains ANY substring in arr_strPieces.
If found, it simply returns TRUE.
In C++, this task is not syntactically as easy.
The biggest problem is the SCOPE and type of the anonymous variable.
Where the C# framework dynamically handles the conversion, it must be explicit in C++.

Here is the example:

To handle the scope of the second IEnumerable::String^, I created a class that (when instantiated) has a method that returns a Func that tests the contents.
The same thing happens with the individual Strings (another class used to handle the scoping).

This is nowhere as "cute" as the C# code, but it satisfies my curiosity.


posted @ Wednesday, April 19, 2017 10:20 AM

Comments on this entry:

# re: Nested Enumerable::Any in C++/CLI (difficult++)

Left by Protar Smith at 9/18/2017 3:28 PM

# re: Nested Enumerable::Any in C++/CLI (difficult++)

Left by Marianna Lewis at 11/22/2017 12:00 AM
well good one

Your comment:

(not displayed)


Live Comment Preview: