{"id":30068595,"url":"https://github.com/lux-qaq/type-vision-cpp","last_synced_at":"2025-08-08T10:45:47.487Z","repository":{"id":308850223,"uuid":"1034316532","full_name":"lux-QAQ/Type-Vision-Cpp","owner":"lux-QAQ","description":"C++20 type visualization header-only library","archived":false,"fork":false,"pushed_at":"2025-08-08T09:18:36.000Z","size":94,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-08T09:24:12.214Z","etag":null,"topics":["c-plus-plus","cpp","cpp20","header-only","reflection","struct","visualization"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lux-QAQ.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-08T07:40:03.000Z","updated_at":"2025-08-08T09:19:45.000Z","dependencies_parsed_at":"2025-08-08T09:36:49.341Z","dependency_job_id":null,"html_url":"https://github.com/lux-QAQ/Type-Vision-Cpp","commit_stats":null,"previous_names":["lux-qaq/type_vision"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/lux-QAQ/Type-Vision-Cpp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lux-QAQ%2FType-Vision-Cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lux-QAQ%2FType-Vision-Cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lux-QAQ%2FType-Vision-Cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lux-QAQ%2FType-Vision-Cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lux-QAQ","download_url":"https://codeload.github.com/lux-QAQ/Type-Vision-Cpp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lux-QAQ%2FType-Vision-Cpp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269410047,"owners_count":24412147,"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","status":"online","status_checked_at":"2025-08-08T02:00:09.200Z","response_time":72,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","cpp","cpp20","header-only","reflection","struct","visualization"],"created_at":"2025-08-08T10:45:46.795Z","updated_at":"2025-08-08T10:45:47.470Z","avatar_url":"https://github.com/lux-QAQ.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Type Vision\n\n简体中文 | [English](README.en.md)\n\n\n这是一个使用`C++20`编写的类型解析器，旨在提供对`C++`类型的树状可视化 ,受[16bit-ykiko/magic-cpp](https://github.com/16bit-ykiko/magic-cpp)的启发,使用**类型特化**和反射库[yalantinglibs](https://github.com/alibaba/yalantinglibs)来实现类型解析。这使得代码量相比[16bit-ykiko/magic-cpp](https://github.com/16bit-ykiko/magic-cpp)大大减少。\n\n## 功能\n当前的功能特别简单 ,只是用于解析类型并打印出类型的树状结构。\n例如对于\n```cpp\n#include \"parser.hpp\"\n\nint main()\n{\n    using T = int (*(*(*)(int*))[4])(int*); // 复杂的C风格函数指针类型 ,能看懂这个那算是谭浩强受害者了\n    type_vision::static_parse::Parser\u003cT\u003e::type::print();\n    return 0;\n}\n```\n### 输出:\n![C-choro](public/image-2.png)\n\n或者你可能遇到`std::function`天才代码\n```cpp\n#include \"parser.hpp\"\n\nint main()\n{\n    using T = std::function\u003cint(const std::vector\u003cint\u003e\u0026, std::tuple\u003cint, int, int\u003e)\u003e; // hard to understand\n    type_vision::static_parse::Parser\u003cT\u003e::type::print();\n    return 0;\n}\n```\n### 输出:\n![func](public/image.png)\n## 反射带来高级特性\n由于使用了编译器宏和反射库`yalantinglibs` ,所以可以解析出更复杂的类型。\n#### 1. 枚举类型\n\n```cpp\n#include \"parser.hpp\"\n\n\nenum class Color\n{\n    Red=1,\n    Green,\n    Blue,\n    Yellow,\n    Purple\n};\n\nint main()\n{\n    using T = Color;\n    type_vision::static_parse::Parser\u003cT\u003e::type::print();\n    return 0;\n}\n```\n### 输出:\n![enum](public/image-1.png)\n\n\n\n#### 2. 类对象\n\u003e 满足聚合体的类对象可以被解析\n```cpp\n#include \"parser.hpp\"\n#include \u003cstring\u003e\n\n\nenum class Color\n{\n    Red=1,\n    Green,\n    Blue,\n    Yellow,\n    Purple\n};\n\nclass Person\n{\npublic:\n    std::string name;\n    int age;\n    int id;\n    Color favorite_color;\npublic:\n    void setName(const std::string\u0026 name) { this-\u003ename = name; }\n    void setAge(int age) { this-\u003eage = age; }\n    void setId(int id) { this-\u003eid = id; }\n    void setFavoriteColor(Color color) { this-\u003efavorite_color = color; }\n    std::string getName() const { return name; }\n    int getAge() const { return age; }\n    int getId() const { return id; }\n\n};\nint main()\n{\n    using T = Person;\n    type_vision::static_parse::Parser\u003cT\u003e::type::print();\n    return 0;\n}\n```\n\n\n### 输出:\n![alt text](public/image-4.png)\n聚合类对象的要求:\n*   **没有用户声明的构造函数。**\n*   **没有私有或受保护的非静态数据成员。**\n*   没有虚函数。\n*   没有虚、私有或受保护的基类。\n\n### 3. NTTP的解析\n```cpp\n#include \"parser.hpp\"\n#include \u003cstring\u003e\ntemplate \u003cint N\u003e\nstruct Array {\n    int data[N];\n};\nint main() {\n    using T = Array\u003c5\u003e; // 数组类型\n    type_vision::static_parse::Parser\u003cT\u003e::type::print();\n    return 0;\n}\n```\n### 输出:\n![nttp](public/image-5.png)\n\n\n\n## 可能的功能列表\n- [x] 支持类型树的可视化\n- [ ] 支持`lambda`表达式的解析\n- [ ] 支持不同类型树的`diff`\n- [ ] 类型树序列化为`json`或者`yaml`\n- [ ] 实现从类型树构造为合法且易懂的C++代码\n- [ ] 使用C++26反射实现更复杂的类解析\n\n\n## License\n\nThis project is licensed under the Creative Commons Attribution-NonCommercial 4.0 International License. You can view the full license [here](LICENSE).\n根据该License严禁将该项目用于任何商用目的。\n![CC BY-NC License](https://licensebuttons.net/l/by-nc/4.0/88x31.png)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flux-qaq%2Ftype-vision-cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flux-qaq%2Ftype-vision-cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flux-qaq%2Ftype-vision-cpp/lists"}