{"id":15047266,"url":"https://github.com/oktonion/cpp-fast-delegates","last_synced_at":"2025-04-10T00:50:51.035Z","repository":{"id":111305709,"uuid":"97609154","full_name":"oktonion/Cpp-fast-delegates","owner":"oktonion","description":"Header-only extension for C++ Fast Delegates of Don Clugston (C++98 compatible)","archived":false,"fork":false,"pushed_at":"2024-10-26T21:43:36.000Z","size":294,"stargazers_count":13,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T02:37:03.693Z","etag":null,"topics":["cpp","cpp03","cpp11","cpp98","crossplatform","delegate","delegates","fast","fast-delegates"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oktonion.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}},"created_at":"2017-07-18T14:36:49.000Z","updated_at":"2024-09-22T13:00:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"0decb727-f916-4688-a3bd-226b85fb7c62","html_url":"https://github.com/oktonion/Cpp-fast-delegates","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/oktonion%2FCpp-fast-delegates","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oktonion%2FCpp-fast-delegates/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oktonion%2FCpp-fast-delegates/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oktonion%2FCpp-fast-delegates/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oktonion","download_url":"https://codeload.github.com/oktonion/Cpp-fast-delegates/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248137999,"owners_count":21053775,"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","cpp03","cpp11","cpp98","crossplatform","delegate","delegates","fast","fast-delegates"],"created_at":"2024-09-24T20:55:52.377Z","updated_at":"2025-04-10T00:50:51.003Z","avatar_url":"https://github.com/oktonion.png","language":"C++","readme":"# fast delegates for C++\n\nExtended original cross platform fast delegates for C++ (C++98 compatible). \n\n[![C/C++ CI](https://github.com/oktonion/Cpp-fast-delegates/actions/workflows/c-cpp.yml/badge.svg?branch=tests)](https://github.com/oktonion/Cpp-fast-delegates/actions/workflows/c-cpp.yml)\n[![codecov](https://codecov.io/gh/oktonion/Cpp-fast-delegates/branch/tests/graph/badge.svg)](https://codecov.io/gh/oktonion/Cpp-fast-delegates)\n\nIn this delegates you could store:\n1) global function\n2) global function with class object (both const obj and non-const)\n3) static function of class (same as two above actually)\n4) member function of class with class object (both const obj and non-const)\n\nCalls to functions stored are extremely fast (like call to original function). Delegate takes minimum memory, are crossplatform and C++98, C++11, C++14 and later standart compatible.\n\n# What are we talking about?\nf.e. we have some functions (class functions, global functions, constant or not, whatever...) with same arguments and return value:\n```\nint func(std::string, size_t\u0026); // regular function\nint func(SomeClass*, std::string, size_t\u0026); // same but with class pointer\nint func(SomeOtherClass*, std::string, size_t\u0026); // same but with class pointer\nint func(const SomeClass*, std::string, size_t\u0026); // same but with class const pointer\nint func(const SomeOtherClass*, std::string, size_t\u0026); // same but with class const pointer\n\nint SomeClass::mfunc(std::string, size_t\u0026); // class member function\nint SomeClass::mcfunc(std::string, size_t\u0026) const; // class member const function\nstatic int SomeClass::sfunc(std::string, size_t\u0026); // class member static function\nstatic int SomeClass::sfunc(SomeOtherClass*, std::string, size_t\u0026); // same but with class pointer\nstatic int SomeClass::sfunc(const SomeClass*, std::string, size_t\u0026); // same but with class const pointer\n\nint SomeOtherClass::mfunc(std::string, size_t\u0026); // class member function\nint SomeOtherClass::mcfunc(std::string, size_t\u0026) const; // class member const function\nstatic int SomeOtherClass::sfunc(std::string, size_t\u0026); // class member static function\nstatic int SomeOtherClass::sfunc(SomeOtherClass*, std::string, size_t\u0026); // same but with class pointer\nstatic int SomeOtherClass::sfunc(const SomeClass*, std::string, size_t\u0026); // same but with class const pointer\n\n// any other class actually...\n```\nand there is one delegate to rule them all:\n```\n// could contain any of functions above (with class pointer if needed):\n\ndelegate\u003cint, std::string, size_t\u0026\u003e allmighty_delegate;\n\n```\n\n# How to use:\n```\n#include \"delegates\\delegate.h\"\n\n...\n\nusing namespace delegates;\n```\nthen:\n\n```\nint func(unsigned char val1, size_t \u0026val2) {/*some actual work*/ return 0;}\n\n...\n\ndelegate\u003cint, unsigned char, size_t\u0026\u003e d2(\u0026func);\n\n...\n\nsize_t val = 50;\nint t = d2(2, val); // calling 'func' by delegate\n```\nmore fun with saving class object:\n\n```\nint func(unsigned char val1, size_t \u0026val2) {/*some actual work*/ return 0;}\n\nstruct Dummy\n{\n   int mfunc(unsigned char val1, size_t \u0026val2) {/*some actual class work*/ return 0;}\n      \n   static int sfunc(unsigned char val1, size_t \u0026val2) {/*some actual static work*/ return 0;}\n};\n\nint gfunc(Dummy *pdummy, unsigned char val1, size_t \u0026val2) {/*some actual class or global work*/ return 0;}\nint const_gfunc(const Dummy *pdummy, unsigned char val1, size_t \u0026val2) {/*some actual class or global work*/ return 0;}\n\n...\n\ndelegate\u003cint, unsigned char, size_t\u0026\u003e d2(\u0026func); // same delegate\n\n...\n\nsize_t val = 50;\nint t = d2(2, val); // calling 'func' by delegate\n\nDummy dummy;\nd2.bind(\u0026dummy, \u0026Dummy::mfunc); // binding to specific object\nt = d2(2, val); // calling 'dummy-\u003emfunc' by delegate\n\nd2.bind(\u0026Dummy::sfunc); // same as just regular 'func' (first example)\nt = d2(2, val); // calling 'Dummy::sfunc' by delegate\n\nd2.bind(\u0026dummy, \u0026gfunc); // binding to specific object but global function taking 'object_type'\nt = d2(2, val); // calling 'gfunc' by delegate with pointer to 'dummy' as first argument\n\nd2.bind(\u0026dummy, \u0026const_gfunc); // binding to specific object but const global function taking 'object_type'\nt = d2(2, val); // calling 'const_gfunc' by delegate with const pointer to 'dummy' as first argument\n```\n\nalso you could use 'bind' to create delegate:\n\n```\nint func(unsigned char val1, size_t \u0026val2) {/*some actual work*/ return 0;}\n\n...\n\ndelegate\u003cint, unsigned char, size_t\u0026\u003e d2; // same delegate again\n\nd2 = bind(\u0026func);\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foktonion%2Fcpp-fast-delegates","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foktonion%2Fcpp-fast-delegates","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foktonion%2Fcpp-fast-delegates/lists"}