{"id":18404570,"url":"https://github.com/avakar/destructure","last_synced_at":"2025-04-07T08:32:04.461Z","repository":{"id":137929256,"uuid":"225240227","full_name":"avakar/destructure","owner":"avakar","description":"Structure to Tuple Conversions in C++17","archived":false,"fork":false,"pushed_at":"2019-12-06T18:52:42.000Z","size":6,"stargazers_count":25,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-22T15:02:21.524Z","etag":null,"topics":["cpp","cpp17"],"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/avakar.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":"2019-12-01T22:26:57.000Z","updated_at":"2024-04-29T12:17:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"b47b1e3a-5c1f-43f6-a23d-4244417386f7","html_url":"https://github.com/avakar/destructure","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/avakar%2Fdestructure","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avakar%2Fdestructure/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avakar%2Fdestructure/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avakar%2Fdestructure/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/avakar","download_url":"https://codeload.github.com/avakar/destructure/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247620158,"owners_count":20968137,"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":["cpp","cpp17"],"created_at":"2024-11-06T02:53:17.489Z","updated_at":"2025-04-07T08:32:04.437Z","avatar_url":"https://github.com/avakar.png","language":"C++","readme":"# Structure to Tuple Conversions in C++17\n\nThis single-header library provides the following pair of functions.\n\n    template \u003ctypename T\u003e\n    auto destructure(T \u0026 val)\n    {\n        auto \u0026\u0026 [an...] = std::forward\u003cT\u003e(val);\n        return std::tie(an...);\n    }\n\n    template \u003ctypename T\u003e\n    auto destructure(T \u0026\u0026 val)\n    {\n        auto \u0026\u0026 [an...] = std::forward\u003cT\u003e(val);\n        return std::tuple(std::move(an)...);\n    }\n\nUnfortunately, there are no variadic structured bindings in C++17,\nso the implementation is a bit more involved.\n\n## Getting Started\n\nEither use the CMakeFile in the repo or simply copy `destructure.h`\nto your project. Then include it.\n\n    #include \u003cavakar/destructure.h\u003e\n    using avakar::destructure;\n\nNow, consider the following structure.\n\n    struct X\n    {\n        int a;\n        std::string b;\n    };\n\nThe `destructure` function will turn an object of type `X` into a tuple\nof `int` and `std::string`.\n\n    X x;\n    auto tied = destructure(x);\n    static_assert(std::is_same_v\u003cdecltype(tied), std::tuple\u003cint \u0026, std::string \u0026\u003e\u003e);\n\nNotice that for an l-value, destructuring results in a tuple\nof references. You can modify the object `x` via the tuple.\n\n    std::get\u003c0\u003e(tied) = 1;\n    assert(x.a == 1);\n\nFor an r-value, `destructure` returns a tuple of values.\n\n    auto tup = destructure(X{1, \"test\"});\n    static_assert(std::is_same_v\u003cdecltype(tied), std::tuple\u003cint, std::string\u003e\u003e);\n\n## Limitations\n\nThe library only supports structures of up to 64 members by default,\nalthough you can generate your own version of the header with\nthe following command.\n\n    ./src/generate.py -n 100\n\nThis will output a new header file containing the function\nin the `destructure_100` namespace. Use `--inline` to make the namespace\ninline.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favakar%2Fdestructure","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Favakar%2Fdestructure","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favakar%2Fdestructure/lists"}