An open API service indexing awesome lists of open source software.

https://github.com/cemdervis/linq

linq is a minimalistic, header-only LINQ library for C++ 17 and newer.
https://github.com/cemdervis/linq

cpp cpp17 cpp20 linq modern-cpp sql

Last synced: about 1 year ago
JSON representation

linq is a minimalistic, header-only LINQ library for C++ 17 and newer.

Awesome Lists containing this project

README

          

# linq - LINQ for C++

![logo](docs/img/logo.png)

linq is a header-only LINQ library for C++ 17 and newer.

It has no dependencies and neatly integrates into the STL by taking advantage of modern C++ features.

- offers a simpler alternative to C++20 ``
- resolves all type related functionality at compile-time; no virtual dispatch is used
- uses lazy evaluation, so your queries still work even after you modify the container they're based on
- focuses on immutability, so your queries stay predictable by minimizing surprising side-effects
- is efficient in the way it works with your data; it avoids copies and instead moves data wherever it can
- generates an operation chain at compile-time (supports `constexpr`)
- works with all generic container types, not just the STL

---

[![Linux-Clang](https://github.com/cemdervis/linq/actions/workflows/build-linux-clang.yml/badge.svg)](https://github.com/cemdervis/linq/actions/workflows/build-linux-clang.yml) [![Linux-GCC](https://github.com/cemdervis/linq/actions/workflows/build-linux-gcc.yml/badge.svg)](https://github.com/cemdervis/linq/actions/workflows/build-linux-gcc.yml) [![macOS-AppleClang](https://github.com/cemdervis/linq/actions/workflows/build-macos-appleclang.yml/badge.svg)](https://github.com/cemdervis/linq/actions/workflows/build-macos-appleclang.yml) [![Windows-MSVC](https://github.com/cemdervis/linq/actions/workflows/build-windows-msvc.yml/badge.svg)](https://github.com/cemdervis/linq/actions/workflows/build-windows-msvc.yml)

## Documentation

The documentation is available on the [home page](https://dervis.de/linq).

## Example

```cpp linenums="1"
#include
#include
#include
#include

struct Person {
std::string name;
int age;
};

int main() {
auto people = std::vector {
{ "Person 1", 20 },
{ "Person 2", 21 },
{ "Person 3", 22 }
};

auto query = linq::from( &people )
.where( []( const Person& p ) { return p.age > 20; } )
.select( []( const Person& p ) { return p.name; } );

for ( const auto& name : query )
std::println( "{}", name );

return 0;
}
```

Output:

```
Person 2
Person 3
```