{"id":18898358,"url":"https://github.com/brainstone/cppcompiletimearraygenerator","last_synced_at":"2025-10-13T14:39:55.398Z","repository":{"id":69186073,"uuid":"282318042","full_name":"BrainStone/CppCompiletimeArrayGenerator","owner":"BrainStone","description":"A tiny header only C++11 (and above) library to generate arrays with a generator function at compile time!","archived":false,"fork":false,"pushed_at":"2020-07-27T07:44:15.000Z","size":6,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-31T08:45:39.218Z","etag":null,"topics":["constexpr","cpp","cpp11","cpp14","cpp17","cpp20","header-only"],"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/BrainStone.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":"2020-07-24T21:20:28.000Z","updated_at":"2021-04-23T07:35:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"2b10b1cb-f9bc-4e39-9456-5a021b8d5ac8","html_url":"https://github.com/BrainStone/CppCompiletimeArrayGenerator","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrainStone%2FCppCompiletimeArrayGenerator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrainStone%2FCppCompiletimeArrayGenerator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrainStone%2FCppCompiletimeArrayGenerator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrainStone%2FCppCompiletimeArrayGenerator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BrainStone","download_url":"https://codeload.github.com/BrainStone/CppCompiletimeArrayGenerator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239879317,"owners_count":19712176,"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":["constexpr","cpp","cpp11","cpp14","cpp17","cpp20","header-only"],"created_at":"2024-11-08T08:42:11.894Z","updated_at":"2025-10-13T14:39:50.343Z","avatar_url":"https://github.com/BrainStone.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CppCompiletimeArrayGenerator\n\nA tiny header only C++11 (and above) library to generate arrays with a generator function at compile time!\n\n## Motivation\n\nDidn't you at some point come across a situation where you had an array that had all its values generated by a function and those values were constant. So\nessentially the array will always be initialized to the same values...  \nThen you thought to yourself: \"My generation function is simple enough for it to be `constexpr`, so I could just have the compiler generate the array for me at\ncompile time, couldn't I?\" only to be disappointed that there's no good way to do that (up until C++17 anyways)...  \n**That** is exactly what happened to me. And I came across a bunch of bad solutions. None really satisfied me until I stumbled across this\n[gem](https://stackoverflow.com/a/19019432/1996022)! While the example given is really simple and just creates an array with increasing numbers (and even makes\nthe array one element too large) I decided to turn this into a fully fledged compile time array generator!\n\n## Usage\n\nUsing this library is really simple. Just include the header and access the array like this:\n\n```cpp\nGenerator\u003cnumElements, type, generatorFunction\u003e::value\n```\n\nNotes:\n- Sadly you need to specify the `type`. No way to implement this in a way so the compiler can deduct the type.\n- `generatorFunction` needs to be `constexpr`.\n\nHere's a full example:\n\n```cpp\n#include \u003ciostream\u003e\n\n#include \"Generator.hpp\"\n\nconstexpr int pow(size_t index) { return index * index; }\n\nint main() {\n  for (int val : Generator\u003c123, int, pow\u003e::value) {\n    std::cout \u003c\u003c val \u003c\u003c '\\n';\n  }\n}\n```\n\n## TODO\n\nWell, while there's not too much left to do here's a list of what I'd like to add over time:\n\n- [ ] Doxygen documentation/comments\n- [ ] Compilable examples\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrainstone%2Fcppcompiletimearraygenerator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrainstone%2Fcppcompiletimearraygenerator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrainstone%2Fcppcompiletimearraygenerator/lists"}