{"id":18049548,"url":"https://github.com/krzmbrzl/iterators","last_synced_at":"2025-06-12T14:32:25.279Z","repository":{"id":96474425,"uuid":"588083034","full_name":"Krzmbrzl/iterators","owner":"Krzmbrzl","description":"A C++17 header-only library for easy implementation of STL-conforming iterators","archived":false,"fork":false,"pushed_at":"2023-01-18T10:19:56.000Z","size":27,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-03T14:30:29.166Z","etag":null,"topics":["c-plus-plus","custom-iterators","iterator","iterator-library","iterators"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Krzmbrzl.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-01-12T09:34:45.000Z","updated_at":"2024-01-02T22:24:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"2596d9c3-8681-41e4-b3e4-82b79c51110d","html_url":"https://github.com/Krzmbrzl/iterators","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Krzmbrzl%2Fiterators","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Krzmbrzl%2Fiterators/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Krzmbrzl%2Fiterators/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Krzmbrzl%2Fiterators/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Krzmbrzl","download_url":"https://codeload.github.com/Krzmbrzl/iterators/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Krzmbrzl%2Fiterators/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":258965383,"owners_count":22785184,"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":["c-plus-plus","custom-iterators","iterator","iterator-library","iterators"],"created_at":"2024-10-30T21:08:03.912Z","updated_at":"2025-06-12T14:32:25.259Z","avatar_url":"https://github.com/Krzmbrzl.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# iterators\n\nA C++17 header-only library allowing easy implementation of STL-conforming iterators without any additional dependencies. Think of a light-weight\nversion of [Boost.Iterator](https://github.com/boostorg/iterator) without the Boost dependency.\n\nBy using the provided `iterator_facade` type to create your iterators, you will expose only the minimum required interface for the chosen iterator\ncategory, even if your type would in principle support a richer interface. This is in order to prevent downstream users from depending on parts of\nyour iterator's API that is not covered by the C++ standard for the given iterator category and therefore is very likely to fail, should you ever\nreplace your iterator implementation with another one that meets the same iterator category requirements.\n\n## Features\n\n- Easily implement new iterators by only implementing the iterator's _Core_ that only implements the required functions. All boilerplate for the\n  actual iterator interface will be inferred by the `iterator_facade` class.\n- Compile-time checks that your iterator implementation conforms to the chosen iterator category as defined by the C++ standard\n- Your iterator will expose _exactly_ the required interface and _nothing more_. This prevents downstream users from accidentally depending on an\n  implementation detail of your iterator.\n- Automatic support for iterators returning a value on dereferencing (e.g. a wrapper type). Note: due to the C++ standard requirements this is only\n  possible for input and output iterators.\n\n## Requirements\n\n- An ISO-C++17 compliant compiler and standard library implementation\n\nThat's it. No external dependencies.\n\n## Example\n\nSee also the [examples](examples) directory. Using this library, you can create a new iterator implementation by implementing what we refer to as the\niterator's _Core_. This contains the iterator's state as well as functions that implement the underlying functionality of your iterator:\n```cpp\n#include \u003citerators/iterator_facade.hpp\u003e\n\n#include \u003ccstddef\u003e\n#include \u003ciostream\u003e\n#include \u003citerator\u003e\n\nstruct MyCore {\n    // Declare what iterator category we are aiming for\n    using  target_iterator_category = std::input_iterator_tag;\n\n    // These functions are required for all iterator cores\n\n    MyCore(int *ptr) : m_ptr(ptr) {}\n    MyCore(const MyCore \u0026) = default;\n    MyCore \u0026operator=(const MyCore \u0026) = default;\n\n    int \u0026dereference() const { return *m_ptr; }\n\n    void increment() { m_ptr += 1; }\n\n    // Required from forward iterators onwards\n    MyCore() = default;\n\n    // Required for all iterator categories except output iterators\n    bool equals(const MyCore \u0026other) const { return m_ptr == other.m_ptr; }\n\n    // Required only for bidirectional and random access iterators\n    void decrement() { m_ptr -= 1; }\n\n    // Required only for random access iterators\n    std::ptrdiff_t distance_to(const MyCore \u0026other) const { return other.m_ptr - m_ptr; }\n\n    // Required only for random access iterators\n    void advance(std::ptrdiff_t amount) { m_ptr += amount; }\n\nprivate:\n    int * m_ptr = nullptr;\n};\n\nusing MyIterator = iterators::iterator_facade\u003c MyCore \u003e;\n\nint main() {\n    int numbers[3] = { 1, 2, 3 };\n\n    MyIterator iter(MyCore{numbers});\n\n    std::cout \u003c\u003c *iter \u003c\u003c \"\\n\";\n    iter++;\n    std::cout \u003c\u003c *iter \u003c\u003c \"\\n\";\n    ++iter;\n    std::cout \u003c\u003c *iter \u003c\u003c \"\\n\";\n\n    return 0;\n}\n```\n\n## References\n\nThe following references were very helpful for implementing this library and might be useful for anyone looking into this subject:\n- https://vector-of-bool.github.io/2020/06/13/cpp20-iter-facade.html\n  ([source](https://github.com/vector-of-bool/vector-of-bool.github.io/blob/7597b411d95cc9e5d24158c2eaddabec87f93a59/_posts/2020-06-13-cpp20-iter-facade.md))\n- [Boost.Iterator source code](https://github.com/boostorg/iterator)\n- https://quuxplusone.github.io/blog/2019/02/06/arrow-proxy/\n- https://cplusplus.com/reference/iterator/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrzmbrzl%2Fiterators","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrzmbrzl%2Fiterators","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrzmbrzl%2Fiterators/lists"}