{"id":23739118,"url":"https://github.com/serengti/cpp_iterzip","last_synced_at":"2026-03-02T14:30:16.520Z","repository":{"id":206682473,"uuid":"679249493","full_name":"SerenGTI/cpp_iterzip","owner":"SerenGTI","description":"Header-only C++17 implementation for a python-style zip iterator.","archived":false,"fork":false,"pushed_at":"2023-11-13T16:49:19.000Z","size":21,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-31T09:34:49.442Z","etag":null,"topics":["cpp17","iterator"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SerenGTI.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2023-08-16T12:26:36.000Z","updated_at":"2023-08-22T12:06:43.000Z","dependencies_parsed_at":"2023-11-13T17:54:22.109Z","dependency_job_id":null,"html_url":"https://github.com/SerenGTI/cpp_iterzip","commit_stats":null,"previous_names":["serengti/cpp_iterzip"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SerenGTI%2Fcpp_iterzip","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SerenGTI%2Fcpp_iterzip/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SerenGTI%2Fcpp_iterzip/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SerenGTI%2Fcpp_iterzip/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SerenGTI","download_url":"https://codeload.github.com/SerenGTI/cpp_iterzip/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239880657,"owners_count":19712449,"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":["cpp17","iterator"],"created_at":"2024-12-31T09:32:28.767Z","updated_at":"2026-03-02T14:30:16.449Z","avatar_url":"https://github.com/SerenGTI.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# iterzip for C++17\n\nHeader-only implementation for a python-style `zip` iterator.\nSimplifies iteration over multiple containers at once.\nSupports all standard iterator categories and conforms to `std::iterator_traits`.\n\n## Usage\n\nSupports all iterator-conforming containers.\nThis, of course, includes all STL containers such as `std::array`, `std::vector`, `std::list` etc.\nYou can `zip` arbitrary many containers and iterate them all at once!\n\n```c++\n#include \"iterzip.hpp\"\nusing iterzip::zip;\n\nstd::array\u003cint, 5\u003e a{1,2,3,4,5};\nstd::array\u003cint, 5\u003e b{6,7,8,9,10};\n\nfor(auto [x,y] : zip(a,b)) {\n    std::cout \u003c\u003c x \u003c\u003c \", \" \u003c\u003c y \u003c\u003c std::endl;\n}\n```\nWill produce the following output\n```\n1, 6\n2, 7\n3, 8\n4, 9\n5, 10\n```\n\n### Containers of different size\nFor containers with different sizes, the smallest container determines the length of of the `zip` iteration.\n\n```c++\nstd::array\u003cint, 4\u003e d{1,2,3,4};\nstd::array\u003cint, 2\u003e e{5,6};\n\nfor(auto [x,y] : zip(d,e)) {\n    std::cout \u003c\u003c x \u003c\u003c \", \" \u003c\u003c y \u003c\u003c std::endl;\n}\n```\nWill produce the following output\n```\n1, 5\n2, 6\n```\n\nSpecifically, two `zip` iterators are equal (`operator!=` is false) as soon as at least one of the individual iterators are equal. \n\n### Higher iterator acategories\n\nIf the containers support it, it is possible to use higher iterator categories' functions.\nFor example, the `iterator::operator[]` on two `std::array`s:\n```c++\nstd::array\u003cint, 2\u003e d{1,2};\nstd::array\u003cint, 2\u003e e{3,4};\n\nauto zipped = zip(d, e);\n// only works with random access iterators\nstd::cout \u003c\u003c std::get\u003c0\u003e(zipped.begin()[1]) \u003c\u003c std::endl; // outputs 2 (which is the second element in the first container.)\n```\n\n## Iterator traits for zip iterators\n\nThe `zip` iterator category depends on the given input containers' iterators.\nTo achieve that, the `iterzip` namespace provides a natural extension of `std::iterator_traits`, called `iterzip::iterator_traits`.\nThe chosen iterator category is always the lowest category of all input iterator types.\n\n```c++\nusing T1 = std::list\u003cint\u003e::iterator;\nusing T2 = std::array\u003cint\u003e::iterator;\nusing cat = typename iterzip::iterator_traits\u003cT1,T2\u003e::iterator_category;\n// cat == std::bidirectional_iterator_tag;\n```\n\nThe zipped `value_type` is a `std::tuple\u003cX, ...\u003e` where the `X` are the individual iterators' `value_type`.\nThe `reference` typedef is `std::tuple\u003cX\u0026, ...\u003e` and `pointer` is mapped to `reference*`.\n\n## Compiling / Building / Including\n\nIn your project, simply include the header file `iterzip.hpp` and make sure you have support for C++17.\n\nTo build the example file provided in the repository, run\n```bash\n$ gcc main.cpp -o main -lstdc++ -std=c++17\n$ ./main\n```\n\nThe implementation of iterzip uses fold expressions, which are only available after C++17.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserengti%2Fcpp_iterzip","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fserengti%2Fcpp_iterzip","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserengti%2Fcpp_iterzip/lists"}