Statically typed, fluent query functions for C++20 containers that are easy to discover through auto-complete.
Wrap a container in fcpp::query and chain operations on it, instead of writing loops and
temporary containers by hand.
- 🔗 Chain filtering, projection, ordering, set and grouping operations in a single expression.
- 🔍 Find every operation through auto-complete on the returned
fcpp::Queryable<T>. - ⚡ Write terse lambdas with the
EXPRandCR_EXPRmacros. - 📦 Works with move-only types; items are moved through the chain rather than copied.
Free and open source, and kept up by one person.
If it saves you time, sponsor it monthly or
leave a small one-time tip. Every bit
helps.
Each release lists the SHA-256 of its install.sh in the
release notes. Download the script, check it against that hash, then run it
(why not curl | bash):
PUB_SHA256="<install.sh SHA-256 from the release notes>"
curl -q --proto '=https' --tlsv1.2 -fsSLO https://github.com/awalsh128/fluentcpp/releases/latest/download/install.sh &&
printf '%s %s\n' "$PUB_SHA256" 'install.sh' | sha256sum --check &&
bash install.shOn macOS, use shasum -a 256 --check in place of sha256sum --check.
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 install.sh, for example bash install.sh --version v0.2 --prefix "$HOME/.local".
| 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, for example CXX=g++ bash install.sh. To read the
script before running it, leave off the last line of the command above and open the file once the
check passes (less install.sh).
Alternatively, download fluentcpp-<tag>.tar.gz from a
release, extract it and run ./install.sh from
the extracted directory.
Then query a container:
fcpp::query(xs)
.where(EXPR(x, x > 500))
.select(EXPR(x, x % 10))
.distinct()
.to_vector();Include the query header and wrap any std::vector:
#include <fluentcpp/query.h>
#include <iostream>
#include <vector>
int main() {
std::vector<int> xs;
for (int x = 0; x < 1000; x++) xs.push_back(x);
std::vector<int> result =
fcpp::query(xs)
.where(EXPR(x, x > 500))
.shuffle()
.skip(10)
.select(EXPR(x, x % 10))
.distinct()
.order_by(EXPR(x, x))
.branch(EXPR(x, x > 5))
.when_true([](auto q) { return q.select(EXPR(x, x + 100)); })
.when_false([](auto q) { return q.select(EXPR(x, x - 100)); })
.merge()
.select(EXPR(x, std::get<0>(x)))
.to_vector();
for (int x : result) std::cout << x << " ";
}Link against the installed static library:
clang++ -std=c++20 main.cpp -L/usr/local/lib/fluentcpp -lfluentcppFind more in the examples folder. Every operation on fcpp::Queryable<T> is
documented in the API reference, generated with
Doxygen from the comments in include/fluentcpp. See all of my published APIs at
awalsh128.com/api.
Building from source requires Clang (clang++), CMake and Ninja:
sudo apt-get install -y clang cmake ninja-buildThe debug preset in CMakePresets.json configures clang++, Ninja, tests and
examples into build/debug:
cmake --preset debug
cmake --build --preset debug
ctest --preset debugOr, without presets:
cmake -B build -G Ninja \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_CXX_COMPILER=clang++ \
-DBUILD_TESTS=ON
cmake --build build
ctest --test-dir build --output-on-failurecmake --preset release
cmake --build --preset release --target fluentcpp
sudo cmake --install build/release| Option | Default | Description |
|---|---|---|
BUILD_TESTS |
OFF |
Build the Catch2 unit tests in tests. |
BUILD_BENCHMARKS |
OFF |
Build the Google Benchmark tests in benchmarks. |
BUILD_EXAMPLES |
OFF |
Build the example programs in examples. |
BUILD_WEBSITE |
OFF |
Build the Doxygen API website from docs; requires Doxygen. |
include/fluentcpp/ Public headers, included as <fluentcpp/query.h>.
src/ Library implementation files.
tests/ Catch2 unit tests.
benchmarks/ Google Benchmark tests and reporting.
examples/ Example programs.
docs/ Doxygen configuration and website.
cmake/ CMake helper modules.
scripts/ Install, release and developer scripts.
assets/ Artwork and other non-code assets.
- 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.