<picture> <source media="(prefers-color-scheme: dark)" srcset="assets/artwork/fluentcpp-sm.png">
</picture>
Fluent C++
Statically typed, fluent query functions for C++20 containers that are easy to discover through auto-complete.
- Remarks
- If you find this project useful, please consider supporting it as a sponsor and show some ❤️ for open source maintainers.
Wrap a container in fcpp::query and chain operations on it, instead of writing loops and temporary containers by hand.
- :link: Chain filtering, projection, ordering, set and grouping operations in a single expression.
- :mag: Find every operation through auto-complete on the returned fcpp::Queryable<T>.
- :zap: Write terse lambdas with the EXPR and CR_EXPR macros.
- :package: Works with move-only types; items are moved through the chain rather than copied.
Installation
Install the latest release with a single command:
This downloads the source, builds the library and installs it to /usr/local/lib/fluentcpp, with the headers in /usr/local/include/fluentcpp. It runs as your user and only asks for sudo to copy the files if the install location isn't writable. Requires curl, CMake 3.16.3 or newer, and a C++20 compiler; clang++ and Ninja are used when available.
Pass options after bash -s -- to pick a version or install location:
| Option | Default | Description |
|---|---|---|
| --version | Latest release | Release tag or branch to install, such as v0.2 or master. |
| --prefix | /usr/local | Installation prefix for the lib and include directories. |
To build with a specific compiler, set CXX on the bash side of the pipe, for example ... | CXX=g++ bash. To read the script before running it, download it with curl -fsSLO and run bash install.sh.
Alternatively, download fluentcpp-<tag>.tar.gz from a release, extract it and run ./install.sh from the extracted directory.
Usage
Include the query header and wrap any std::vector:
Link against the installed static library:
Find more in the [examples folder](examples). The full API reference is generated with Doxygen from the comments in include/fluentcpp and published at awalsh128.com/fluentcpp. See all of my published APIs at awalsh128.com/api.
Operations
| Category | Operations |
|---|---|
| Filtering | where, distinct, skip, take, take_random, slice, trim |
| Projection | select, flatten, zip, join |
| Ordering | order_by, sort, reverse, shuffle |
| Sets | difference, intersect, unionize |
| Grouping | group_by, keyed_group_by, branch, when_true, when_false, merge |
| Aggregation | accumulate, all, any, min, max, first_or_default |
| Side effects | action |
| Conversion | to_vector, to_set, to_single_value_map, to_multi_value_map |
Building
Building from source requires Clang (clang++), CMake and Ninja:
Debug Build with Tests
The debug preset in CMakePresets.json configures clang++, Ninja, tests and examples into build/debug:
Or, without presets:
Release Build and Install
Build Options
| Option | Default | Description |
|---|---|---|
| BUILD_TESTS | OFF | Build the Catch2 unit tests in [tests](tests). |
| BUILD_BENCHMARKS | OFF | Build the Google Benchmark tests in [benchmarks](benchmarks). |
| BUILD_EXAMPLES | OFF | Build the example programs in [examples](examples). |
| BUILD_WEBSITE | OFF | Build the Doxygen API website from [docs](docs); requires Doxygen. |
Project Layout
Dependencies
- CMake - Build system.
- Clang - C++20 compiler used for builds, formatting and static analysis.
- Catch2 - Unit test framework, fetched by CMake when BUILD_TESTS=ON.
- Google Benchmark - Benchmark framework, fetched by CMake when BUILD_BENCHMARKS=ON.
- Doxygen - API documentation generator, used when BUILD_WEBSITE=ON.
Report bugs or request features through GitHub Issues. For development guidelines, see CONTRIBUTING.md.
License
[Apache 2.0](LICENSE).