{"id":20132503,"url":"https://github.com/aherrmann/rubber_types","last_synced_at":"2025-04-09T16:53:31.368Z","repository":{"id":22097951,"uuid":"25427844","full_name":"aherrmann/rubber_types","owner":"aherrmann","description":"Type-Erasure with merged concepts","archived":false,"fork":false,"pushed_at":"2014-10-19T18:39:03.000Z","size":128,"stargazers_count":18,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-23T19:04:11.536Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/aherrmann.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}},"created_at":"2014-10-19T13:30:44.000Z","updated_at":"2022-04-27T18:52:17.000Z","dependencies_parsed_at":"2022-08-19T07:32:13.928Z","dependency_job_id":null,"html_url":"https://github.com/aherrmann/rubber_types","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/aherrmann%2Frubber_types","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aherrmann%2Frubber_types/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aherrmann%2Frubber_types/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aherrmann%2Frubber_types/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aherrmann","download_url":"https://codeload.github.com/aherrmann/rubber_types/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248073713,"owners_count":21043474,"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":[],"created_at":"2024-11-13T20:53:51.756Z","updated_at":"2025-04-09T16:53:31.351Z","avatar_url":"https://github.com/aherrmann.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rubber-Types — Type-Erasure with merged concepts\n\nSpecify your interface (concept). Generate a type-erasure from it. Merge\nexisting concepts, or type-erasures.\n\nThis library allows you write the following code:\n\n``` cpp\nusing ConceptA = TypeErasure\u003cConceptASpec\u003e;\nusing ConceptB = TypeErasure\u003cConceptBSpec\u003e;\nusing Merged = MergeConcepts\u003cConceptA, ConceptB\u003e;\n\nvoid func(Merged m) {\n    m.func_a();  // Using concept A\n    m.func_b();  // Using concept B\n}\n```\n\nYou define `ConceptASpec`, and `ConceptBSpec` yourself. And, you get the\nmerged concept for free.\n\n\n## Dependencies\n\n * C++11\n * Standard-library\n\n\n## Installation\n\nSimply copy and include the header file `rubber_types.hpp`.\n\n\n## Usage Instructions\n\nInclude the header\n``` cpp\n#include \"rubber_types.hpp\"\n```\n\nDefine your interface.\n``` cpp\nstruct MySpec {\n    struct Concept {  // abstract base class for model.\n        virtual ~Concept() = default;\n        // Your (internal) interface goes here.\n        virtual int method() const = 0\n        virtual void free_func_() const = 0;\n    };\n    template \u003cclass Holder\u003e\n    struct Model : public Holder, public virtual Concept {\n        using Holder::Holder;\n        // Pass through to encapsulated value.\n        virtual int method() const override {\n            return rubber_types::model_get(this).method();\n        }\n        virtual void free_func_() const override {\n            free_func(rubber_types::model_get(this));\n        }\n    };\n    template \u003cclass Container\u003e\n    struct ExternalInterface : public Container {\n        using Container::Container;\n        // Define the external interface. Should match encapsulated type.\n        int method() const {\n            return rubber_types::interface_get(this).method();\n        }\n        friend void free_func(const ExternalInterface \u0026e) {\n            rubber_types::interface_get(e).free_func_();\n        }\n    };\n};\n```\n\nGenerate the type-erasure class.\n``` cpp\nusing MyConcept = rubber_types::TypeErasure\u003cMySpec\u003e;\nusing MyMerge1 = rubber_types::TypeErasure\u003cMySpec1, MySpec2, ...\u003e;\nusing MyMerge2 = rubber_types::MergeConcepts\u003cMyConcept1, MyConcept2, ...\u003e;\n```\n\nAnd se it with anything that fulfills the interface. Just like duck-typing.\n``` cpp\nint call_method(const MyConcept \u0026obj) {\n    return obj.method();\n}\n```\n\n\n## Examples\n\nHave a look at the `examples` folder, or read my [blog\npost](http://aherrmann.github.io/programming/2014/10/19/type-erasure-with-merged-concepts/)\nfor more behind the scenes information.\n\n\n## License\n\n[MIT](http://opensource.org/licenses/MIT)\n\nI cannot stress the *no warranty* bit enough. This code has not been tested in\nany production setting. Consider it a proof of concept at this stage.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faherrmann%2Frubber_types","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faherrmann%2Frubber_types","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faherrmann%2Frubber_types/lists"}