{"id":21883089,"url":"https://github.com/fantasy-peak/yaml_cpp_struct","last_synced_at":"2025-10-16T14:02:20.633Z","repository":{"id":129485723,"uuid":"489334064","full_name":"fantasy-peak/yaml_cpp_struct","owner":"fantasy-peak","description":"It's easy to mapping yaml to cpp's struct","archived":false,"fork":false,"pushed_at":"2024-04-29T07:33:32.000Z","size":31,"stargazers_count":28,"open_issues_count":1,"forks_count":6,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-15T06:08:23.543Z","etag":null,"topics":["cpp","cpp11","cpp17","header-only","mapping","yaml"],"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/fantasy-peak.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":"2022-05-06T11:48:32.000Z","updated_at":"2025-01-31T03:34:38.000Z","dependencies_parsed_at":"2024-04-29T08:39:52.305Z","dependency_job_id":null,"html_url":"https://github.com/fantasy-peak/yaml_cpp_struct","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fantasy-peak%2Fyaml_cpp_struct","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fantasy-peak%2Fyaml_cpp_struct/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fantasy-peak%2Fyaml_cpp_struct/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fantasy-peak%2Fyaml_cpp_struct/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fantasy-peak","download_url":"https://codeload.github.com/fantasy-peak/yaml_cpp_struct/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249016627,"owners_count":21198833,"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","cpp11","cpp17","header-only","mapping","yaml"],"created_at":"2024-11-28T09:39:13.894Z","updated_at":"2025-10-16T14:02:15.592Z","avatar_url":"https://github.com/fantasy-peak.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# yaml_cpp_struct\n\n[![](https://github.com/fantasy-peak/yaml_cpp_struct/workflows/test/badge.svg)](https://github.com/fantasy-peak/yaml_cpp_struct/actions)\n\n## function\n\nIt's a wrapper, It's easy to mapping yaml to cpp's struct\n\n## note\n\nmain branch need \u003e= c++17, if you need to use c++11, please use cpp11 branch. cpp11 branch not support std::variant.\nPlease refer to example for cpp11 branch\n\n## use examples\n```\n// It relies on two other three open source libraries(yaml-cpp, visit_struct, magic_enum), Please refer to CMakeLists.txt of example\ngit clone https://github.com/fantasy-peak/yaml_cpp_struct.git\ncd ./yaml_cpp_struct/example\nmkdir build \u0026\u0026 cd build\ncmake ..\nmake -j 9\n./example ../config.yaml\n// use xmake\ncd ./yaml_cpp_struct/example\nxmake build -v\nxmake run example ../../../../config.yaml\n```\n\n\n[Example](./example/main.cpp)\n```yaml\n---\nch: 'A'\nprice: 100.05\ncount: 254\ncontent: \"i'm fantasy-peak\"\nmap: { \"fantasy\": \"good\", \"peak\": \"good\" }\naccount_info:\n  flag: false\n  name: \"fantasy-peak\"\n  address: { \"127.0.0.1\": 8888, \"127.0.0.2\": 9999 }\n  msec: 100\n  tuple: [\"fantasy-peak\", 89]\n  map_tuple: {\"fantasy-peak\": [\"map_tuple\", 254]}\n\nvec: [\"fantasy-001\", \"fantasy-002\"]\nset_vec: [9, 5, 7]\naccount_type: \"Personal\"\nips: [\"127.0.0.1\"]\n```\n\n```cpp\n#include \u003ciostream\u003e\n\n#include \u003cspdlog/spdlog.h\u003e\n#include \u003cyaml_cpp_struct.hpp\u003e\n\nenum class AccountType : uint8_t {\n    Personal = 1,\n    Company = 2,\n};\nYCS_ADD_ENUM(AccountType, Personal, Company)\n\nstd::string to_string(const AccountType\u0026 type) {\n    if (type == AccountType::Personal)\n        return \"Personal\";\n    if (type == AccountType::Company)\n        return \"Company\";\n    throw std::bad_cast();\n}\n\nstruct AccountInfo {\n    bool flag;\n    std::string name;\n    std::unordered_map\u003cstd::string, int\u003e address;\n    std::optional\u003cstd::string\u003e num;\n    std::chrono::milliseconds msec{100};\n    std::tuple\u003cstd::string, uint8_t\u003e tuple;\n    std::unordered_map\u003cstd::string, std::tuple\u003cstd::string, int32_t\u003e\u003e map_tuple;\n    std::string default_str{\"hello default\"};\n    std::vector\u003cstd::string\u003e ips;\n};\nYCS_ADD_STRUCT(AccountInfo, flag, name, address, num, msec, tuple, map_tuple, default_str, ips)\n\nint main(int, char** argv) {\n    auto [cfg, error] = yaml_cpp_struct::from_yaml\u003cConfig\u003e(argv[1]);\n    auto [str, e] = yaml_cpp_struct::to_yaml(cfg.value());\n    // Load values from environment variables\n    // export YCS_ENV_IPS=[\"Google\",\"Runoob\",\"Taobao\"]\n    // auto [cfg, error] = yaml_cpp_struct::from_yaml_env\u003cConfig\u003e(argv[1], \"YCS_ENV_\");\n    return 0;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffantasy-peak%2Fyaml_cpp_struct","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffantasy-peak%2Fyaml_cpp_struct","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffantasy-peak%2Fyaml_cpp_struct/lists"}