{"id":15387426,"url":"https://github.com/rhysd/array_view","last_synced_at":"2025-04-15T17:32:54.213Z","repository":{"id":12519341,"uuid":"15189155","full_name":"rhysd/array_view","owner":"rhysd","description":"Wrapper for references to array in C++.","archived":false,"fork":false,"pushed_at":"2016-05-18T11:16:33.000Z","size":39,"stargazers_count":59,"open_issues_count":1,"forks_count":8,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-10-05T12:34:12.466Z","etag":null,"topics":["array","c-plus-plus","library"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rhysd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-12-14T17:03:16.000Z","updated_at":"2023-11-27T01:14:47.000Z","dependencies_parsed_at":"2022-09-23T07:41:05.158Z","dependency_job_id":null,"html_url":"https://github.com/rhysd/array_view","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Farray_view","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Farray_view/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Farray_view/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Farray_view/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rhysd","download_url":"https://codeload.github.com/rhysd/array_view/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219904712,"owners_count":16566553,"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":["array","c-plus-plus","library"],"created_at":"2024-10-01T14:53:52.537Z","updated_at":"2024-10-16T22:41:43.523Z","avatar_url":"https://github.com/rhysd.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"Wrapper for Reference to Array\n==========================\n[![Build Status](https://travis-ci.org/rhysd/array_view.png?branch=master)](https://travis-ci.org/rhysd/array_view)\n\nReferences to array are very common in C++ programs.  In good old C programs, references to array are represented as a pointer and its length like `void f(int const* ptr, size_t const len)`.  In C++, references to array are represented using template parameter like `template\u003csize_t N\u003e void f(int (\u0026arr)[N])`.  And C++ has many useful array classes like `std::array`, `std::vector` and so on.  `array_view` can deal all of them with safe and unified way.\n\n```cpp\n#include \u003ciostream\u003e\n#include \"array_view.hpp\"\n\nvoid show_int_array(arv::array_view\u003cint\u003e view)\n{\n    std::cout \u003c\u003c '{';\n    if (!view.empty()) {\n        auto itr = view.begin();\n        auto const end = view.end();\n        while (true) {\n            std::cout \u003c\u003c *itr;\n            if (++itr != end) {\n                std::cout \u003c\u003c \", \";\n            } else {\n                break;\n            }\n        }\n    }\n    std::cout \u003c\u003c \"}\\n\";\n}\n\nint main()\n{\n    int good_old_c_array[] = {1, 2, 3, 4};\n    std::array\u003cint, 4\u003e array = {{1, 2, 3, 4}};\n    std::vector\u003cint\u003e vector = {1, 2, 3, 4};\n\n    // access arrays with safe and unified way\n    show_int_array(good_old_c_array);\n    show_int_array(array);\n    show_int_array(vector);\n    show_int_array({1, 2, 3, 4});\n    show_int_array({\u0026good_old_c_array[0], 4});\n\n    return 0;\n}\n```\n\n## Installation\n\nCopy files in `include/` to a directory in include paths.\n\n```\n$ cp include/* path/to/include-dir/\n```\n\n## More Usage\n\nWhen you want to use `array_view` explicitly, use `make_view()`.\n\n```cpp\nstd::vector\u003cint\u003e v = {1, 2, 3};\nauto av = arv::make_view(v);\n```\n\nIf you want to output `array_view`, include `array_view_output.hpp` and just use `\u003c\u003c`.\n\n```cpp\n#include \"array_view_output.hpp\"\nstd::vector\u003cint\u003e v = {1, 2, 3, 4, 5};\nstd::cout \u003c\u003c arv::make_view(v); // \"{1, 2, 3, 4, 5}\" is output\n```\n\nYou can slice `array_view` to make new sub-array references.\n\n```cpp\nstd::vector\u003cint\u003e v = {1, 2, 3, 4, 5};\nauto av = arv::make_view(v);\nauto sub_av = av.slice(/*position*/ 2, /*length*/ 2);\nstd::cout \u003c\u003c sub_av; // {3, 4}\nauto sub_av2 = av.slice(arv::check_bound, /*position*/ 2, /*length*/ 2); // check boundary and may throw an exception\nstd::cout \u003c\u003c sub_av2; // {3, 4}\n```\n\n## Why don't you use `boost::range`?\n\nI use this library in my job.  Just try to feel what I feel.\n\n## License\n\nThis library is distributed under [NYSL](http://www.kmonos.net/nysl/index.en.html).\n\n\u003e  A. This software is \"Everyone'sWare\". It means:\n\u003e  Anybody who has this software can use it as if he/she is\n\u003e  the author.\n\u003e\n\u003e  A-1. Freeware. No fee is required.\n\u003e  A-2. You can freely redistribute this software.\n\u003e  A-3. You can freely modify this software. And the source\n\u003e      may be used in any software with no limitation.\n\u003e  A-4. When you release a modified version to public, you\n\u003e      must publish it with your name.\n\u003e\n\u003e  B. The author is not responsible for any kind of damages or loss\n\u003e  while using or misusing this software, which is distributed\n\u003e  \"AS IS\". No warranty of any kind is expressed or implied.\n\u003e  You use AT YOUR OWN RISK.\n\u003e\n\u003e  C. Copyrighted to (.......)\n\u003e\n\u003e  D. Above three clauses are applied both to source and binary\n\u003e  form of this software.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhysd%2Farray_view","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frhysd%2Farray_view","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhysd%2Farray_view/lists"}