Author: Shinji Chikugi
I found an interesting C++ libraly.That is “LINQ for C++”.
What’s “LINQ”?
LINQ (Integrated Language Query) is a function of C#. LINQ issues a query to the container and gets the result.
For details, please refer to MSDN.
https://docs.microsoft.com/en-us/dotnet/csharp/linq/
LINQ for C++
“LINQ for C++” is the libraly enable to use LINQ on C++.
https://archive.codeplex.com/?p=cpplinq
Usage is simple. Just include the header file published on GitHub.
https://github.com/mrange/cpplinq
Using “LINQ for C ++” in C++ Builder, first make sure to use the new Embarcadero C++ compiler with project options.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
#pragma hdrstop #pragma argsused #ifdef _WIN32 #include <tchar.h> #else typedef char _TCHAR; #define _tmain main #endif #include <stdio.h> #include <iostream> #include "CppLinq/cpplinq.hpp" int computes_a_sum () { using namespace cpplinq; int ints[] = {3,1,4,1,5,9,2,6,5,4}; return from_array (ints) >> where ([](int i) {return i%2 ==0;}) // extract odd number >> sum () // Summing extracted numbers ; } int _tmain(int argc, _TCHAR* argv[]) { std::cout << computes_a_sum() << std::endl; return 0; } |
The sum of the even numbers extracted from the array was output.
Many libraries can be used by using the new Embarcadero C++ compiler. please try it
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition