coveo::linq
Implementation of .NET-like LINQ operators in C++

Introduction

Welcome to the documentation of the coveo::linq library. This library implements .NET-like LINQ operators in C++. These can be chained to build powerful expressions to query, filter and transform data in any type of sequence, like arrays, containers, etc. (anything that supports std::begin() and std::end() should work).

If this is your first time with the library, start at LINQ expressions.

Example

Here is an example that chains many operators to produce a filtered, ordered sequence:

#include <coveo/linq.h>
#include <iostream>
int main()
{
const int FIRST[] = { 42, 23, 66, 13, 11, 7, 24, 10 };
const int SECOND[] = { 67, 22, 13, 23, 41, 66, 6, 7, 10 };
using namespace coveo::linq;
auto is_even = [](int i) { return i % 2 == 0; };
auto seq = from(FIRST)
| intersect(SECOND) // Intersect both arrays
| where([](int i) { return i != 13; }) // I'm supersticious, remove 13
| order_by_descending(is_even) // Place even numbers first
| then_by([](int i) { return i; }); // Then sort numbers ascending
std::cout << std::endl;
for (auto&& elem : seq) {
std::cout << elem << " ";
}
std::cout << std::endl;
// Prints "10 66 7 23"
return 0;
}

coveo::linq::operator|() is used to chain together the various LINQ operators, and coveo::linq::from() is used as the entry point of the expression, providing the initial sequence on which operators will be applied. The sequence is then transformed by each operator, and the result is passed to the next operator.

Installing / requirements

The coveo::linq library is header-only. Therefore, it is not necessary to "build" it to use. Simply copy the lib directory with all its files to a suitable place and add it to your project's include path.

The library requires C++11 support. Several compilers meet that requirements, including the following (as tested by Continuous Integration):

  • GCC 5.4.1
  • Clang 3.4
  • Visual Studio 2015 Update 3

Help / bugs / etc.

Need help with the library? Found a bug? Please visit the coveo::linq GitHub project page at:

    https://github.com/coveo/linq

There, you can file issues with questions or problems.