{"id":20384268,"url":"https://github.com/scenent/cpp-bind-any-methods","last_synced_at":"2025-10-09T22:09:16.126Z","repository":{"id":222035993,"uuid":"756046727","full_name":"scenent/cpp-bind-any-methods","owner":"scenent","description":"It's the way you can bind any methods to map and call it dynamically. Implemented with TMP of C++.","archived":false,"fork":false,"pushed_at":"2024-02-11T21:00:18.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-27T18:45:24.079Z","etag":null,"topics":["cpp","cpp17","tmp"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scenent.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}},"created_at":"2024-02-11T20:25:59.000Z","updated_at":"2024-02-11T21:02:05.000Z","dependencies_parsed_at":"2024-02-11T23:31:26.793Z","dependency_job_id":null,"html_url":"https://github.com/scenent/cpp-bind-any-methods","commit_stats":null,"previous_names":["scenent/cpp-bind-any-methods"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/scenent/cpp-bind-any-methods","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scenent%2Fcpp-bind-any-methods","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scenent%2Fcpp-bind-any-methods/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scenent%2Fcpp-bind-any-methods/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scenent%2Fcpp-bind-any-methods/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scenent","download_url":"https://codeload.github.com/scenent/cpp-bind-any-methods/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scenent%2Fcpp-bind-any-methods/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279002125,"owners_count":26083307,"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-10-09T02:00:07.460Z","response_time":59,"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":["cpp","cpp17","tmp"],"created_at":"2024-11-15T02:27:03.737Z","updated_at":"2025-10-09T22:09:16.080Z","avatar_url":"https://github.com/scenent.png","language":"C++","readme":"# cpp-bind-any-methods\nThe way you can bind any methods(even class's member functions) to map and call it dynamically.\n\n## Usage\n### Code\n```cpp\n#include \"my_function_map.h\"\nstd::string add_str(std::string i, std::string j) {\n\treturn i + \" \" +  j;\n}\n\nint main() {\n  MyFunctionMap myFunctionMap;\n  myFunctionMap.bindFunction(\"add_str\", \u0026add_str);\n  std::string value = std::any_cast\u003cstd::string\u003e(myFunctionMap.getFunction(\"add_str\")-\u003ecall({ std::string(\"Hello\"), std::string(\"World\") }));\n  std::cout \u003c\u003c value \u003c\u003c \"\\n\";\n}\n```\n### Console Output\n```\nHello World\n```\n\n## How does It works?\n1. The `Function` class does not have any template factors.\n2. Only `CallableFunction` and `CallableClassFunction`, which inherit the `Function` class, have template factors.\n3. The `MyFunctionMap` class has a pointer of the `Function` class as information of the map.\n4. The `call` function of the `Function` class is declared as a virtual function.\n5. In the `call` function, the internal binded function is called through the C++'s `variadic template` and `std::apply`.\n\n## Where do I use it?\nYou can use this technique to your own dynamic language interpreter.\n\n## Warning\n- Only C++ 17+ compiler can compile this source.\n- When you call `Function::call(const std::vector\u003cstd::any\u003e\u0026 args)` function, You should pass explicit value. If type of given parameters are not the same with info of binded function, It will throw std::bad_any_cast.\n- The binded function must uses `decltype(nullptr)` instead of void at return type('Cause we can't covert void type into std::any) and return nullptr.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscenent%2Fcpp-bind-any-methods","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscenent%2Fcpp-bind-any-methods","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscenent%2Fcpp-bind-any-methods/lists"}