{"id":24381900,"url":"https://github.com/Very-Generic-Software/rusty-iterators-cpp","last_synced_at":"2025-09-29T12:32:34.460Z","repository":{"id":268103832,"uuid":"902911030","full_name":"uncommon-nickname/rusty-iterators-cpp","owner":"uncommon-nickname","description":"Light, lazy and fast iterators. Inspired by Rust, built in modern C++23.","archived":false,"fork":false,"pushed_at":"2025-01-14T07:11:52.000Z","size":87,"stargazers_count":0,"open_issues_count":33,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-14T07:19:17.497Z","etag":null,"topics":["cpp23","iterators","rust"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uncommon-nickname.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-13T14:21:04.000Z","updated_at":"2025-01-14T07:11:55.000Z","dependencies_parsed_at":"2024-12-14T11:19:09.230Z","dependency_job_id":"0e4c99ce-55c5-47d9-9a0a-869ca8ffb181","html_url":"https://github.com/uncommon-nickname/rusty-iterators-cpp","commit_stats":null,"previous_names":["uncommon-nickname/rusty-iterators-cpp"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uncommon-nickname%2Frusty-iterators-cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uncommon-nickname%2Frusty-iterators-cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uncommon-nickname%2Frusty-iterators-cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uncommon-nickname%2Frusty-iterators-cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uncommon-nickname","download_url":"https://codeload.github.com/uncommon-nickname/rusty-iterators-cpp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234620096,"owners_count":18861462,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp23","iterators","rust"],"created_at":"2025-01-19T09:14:27.262Z","updated_at":"2025-09-29T12:32:29.188Z","avatar_url":"https://github.com/uncommon-nickname.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rusty iterators\n\nThis is a small proof of concept showing a port of Rust iterator interface to modern C++. Is it better than C++ stdlib iterators? Probably not, but it is cool.\n\n## Coding code of conduct\n\nAny contributions are welcome, but please adhere to our code of conduct.\n\n### Conventional commits\n\nWe utilize [conventional commits](https://gist.github.com/qoomon/5dfcdf8eec66a051ecd85625518cfd13). We don't maintain a `changelog` manually. Squashed commits, keeping the correct convention should be more than enough to create a release summary.\n\n### Linting and formatting\n\nWe use both `clang-tidy` and `clang-format`. The former is integrated with CMake and will be run during build. The latter can be run using provided formatting script.\n\n```bash\n./tools/format.sh\n```\n\n## Building the project\n\nWe provide a small utility script to build the project. We use both CMake and Ninja, so make sure you have those installed.\n\n```bash\n# Clean build:\n./tools/build.sh --no-cache --compile-tests\n\n# Build with specified compiler:\n./tools/build.sh --compiler g++-14 --compile-tests --no-cache\n\n# Cached build:\n./tools/build.sh --compile-tests\n\n# Build in release mode\n./tools/build.sh --compile-tests --release\n```\n\n## Examples\n\nSome actual real-life inspired examples can be found in the `examples/` directory. You can build them using provided build script:\n\n```bash\n./tools/build.sh --compile-examples\n```\n\nHere we will list some of the simple examples, to show you the power of lazy iteration!\n\n### Count all even numbers in the iterator\n\n```c++\nauto data = std::vector{1, 2, 3, 4, 5, 6};\nauto result = LazyIterator{data}\n                .filter([](auto x) { return x % 2 == 0; })\n                .count();\n```\n\n### Get `n` items from cycle iterator\n\n```c++\nauto data = std::vector{1, 2, 3};\nauto result = LazyIterator{data}.cycle().take(10).collect();\n```\n\n### Run a callable on every element of the iterator\n\n```c++\nauto data = std::vector{1, 2, 3, 4};\nauto f = [](auto x){ ... } // Do some business logic.\n\nLazyIterator{data}.forEach(std::move(f));\n```\n\n### Find the length of the shortest string in the iterator\n\n```c++\nauto data = std::vector\u003cstd::string\u003e{\"a\", \"abc\", \"defg\"};\nauto result = LazyIterator{data}\n                .map([](auto x) { return x.get().size(); })\n                .min();\n```\n\n### Filter out all even numbers and square the odd numbers\n\n```c++\nauto data = std::vector{1, 2, 3, 4};\nauto result = LazyIterator{data}\n                .filter([](auto x) { return x % 2 != 0; })\n                .map([](auto x) { return x * x; })\n                .collect();\n```\n\n### Chain two iterators\n\n```c++\nauto v1 = std::vector{1, 2, 3};\nauto v2 = std::vector{4, 5, 6};\n\nauto result = LazyIterator{v1}\n                .chain(LazyIterator{v2}\n                .map([](auto x) { return x * 2; }))\n                .collect();\n```\n\n### Find biggest difference between elements of two iterators\n\n```c++\nauto v1 = std::vector{1, 2, 3, 4, 5};\nauto v2 = std::vector{2, 7, 4, 8, 1};\n\nauto result = LazyIterator{v1}\n                    .zip(LazyIterator{v2})\n                    .map([](auto x) { return std::abs(std::get\u003c0\u003e(x) - std::get\u003c1\u003e(x)); })\n                    .max();\n```\n\n### Parse file containing numbers in lazy manner\n\n```c++\nauto fileName = std::string{\"test.txt\"};\nauto numbers = FileIterator\u003cFIterType::Lazy\u003e{fileName}\n                    .filter([](auto x) { return std::all_of(x.begin(), x.end(), std::isdigit); })\n                    .map([](auto x) { return std::atoi(x.c_str()); })\n                    .collect();\n```\n\n## Benchmarks\n\nWe provide a small set of benchmarks located in the `benchmarks/` directory. You can build them using provided build script.\n\n```bash\n./tools/build.sh --compile-benchmarks\n```\n\nAll of the benchmarks measure the performance in release mode and run similar scenario using C++20 `std::ranges` (if it is possible to recreate tested feature without writing a lot of code) to compare how fast, or how slow we are.\n\n### Current measurements\n\nAll of the measurements were taken on MacBook M3 Pro 18GB.\n\n#### Filter and map\n\nApply filter and map on 1'000'000 integers\n\n|          **Benchmark**         | **Time [ns]** | **CPU [ns]** |\n|:------------------------------:|:-------------:|:------------:|\n| benchmarkRustyIterFilterAndMap |     559108    |    559065    |\n|   benchmarkRustyIterFilterMap  |     556122    |    556120    |\n| benchmarkRangesFilterTransform |     539868    |    539786    |\n\nApply filter and map on 10'000'000 integers\n\n|          **Benchmark**         | **Time [ns]** | **CPU [ns]** |\n|:------------------------------:|:-------------:|:------------:|\n| benchmarkRustyIterFilterAndMap |    5644164    |    5643854   |\n|   benchmarkRustyIterFilterMap  |    5599177    |    5599185   |\n| benchmarkRangesFilterTransform |    5988982    |    5988701   |\n\n## Authors\n\n- [Wiktor Nowak](@uncommon-nickname)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FVery-Generic-Software%2Frusty-iterators-cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FVery-Generic-Software%2Frusty-iterators-cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FVery-Generic-Software%2Frusty-iterators-cpp/lists"}