C++ with LINQ

by May 18, 2018

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.


LINQ for C++

"LINQ for C++" is the libraly enable to use LINQ on C++.


Usage is simple. Just include the header file published on GitHub.


Using "LINQ for C ++" in C++ Builder, first make sure to use the new Embarcadero C++ compiler with project options.

#pragma hdrstop
#pragma argsused

#ifdef _WIN32
#include <tchar.h>
  typedef char _TCHAR;
  #define _tmain main

#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};

      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