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:
AnyAny

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.

Tom

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

Comments on this entry:

No comments posted yet.

Your comment:



(not displayed)

 
 
 
 

Live Comment Preview:

 
«April»
SunMonTueWedThuFriSat
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456