{"id":17281638,"url":"https://github.com/stefanofiorentino/message_traits","last_synced_at":"2026-07-02T05:31:37.807Z","repository":{"id":100244096,"uuid":"149099850","full_name":"stefanofiorentino/message_traits","owner":"stefanofiorentino","description":"Message dispatching using type traits.","archived":false,"fork":false,"pushed_at":"2019-03-19T17:00:04.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T15:28:44.368Z","etag":null,"topics":["cpp11","dispatching","tag","type-traits"],"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/stefanofiorentino.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":"2018-09-17T09:18:39.000Z","updated_at":"2019-03-19T17:00:05.000Z","dependencies_parsed_at":"2023-05-13T03:30:17.934Z","dependency_job_id":null,"html_url":"https://github.com/stefanofiorentino/message_traits","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/stefanofiorentino/message_traits","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefanofiorentino%2Fmessage_traits","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefanofiorentino%2Fmessage_traits/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefanofiorentino%2Fmessage_traits/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefanofiorentino%2Fmessage_traits/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stefanofiorentino","download_url":"https://codeload.github.com/stefanofiorentino/message_traits/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefanofiorentino%2Fmessage_traits/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35034984,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-02T02:00:06.368Z","response_time":173,"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":["cpp11","dispatching","tag","type-traits"],"created_at":"2024-10-15T09:46:24.548Z","updated_at":"2026-07-02T05:31:37.782Z","avatar_url":"https://github.com/stefanofiorentino.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Message Traits\n### Message dispatching using type traits.\nIn order to understand a cumbersome topic, you have to work yourself on transforming an idea into reality.\nThis repository is all about this: implementing a simple type_traits mechanism to better grasp the concept itself.\n\n## Target \nThe target of this technique, up to me, is just to hide the greater part of the boilerplate code to the library users,\nfreeing the application developers from expliciting the tags in the function caller code.\n\n## Target usage\nThe target code I want to have in my application code is the following:\n\n```cpp\n    MqttMessage mqttMessage;\n    mqttMessage.setMessage(\"notification by stefano over mqtt\");\n    notify(mqttMessage);\n\n    WssMessage wssMessage;\n    wssMessage.setMessage(\"notification by stefano over wss\");\n    notify(wssMessage);\n    \n    AllMessage allMessage;\n    allMessage.setMessage(\"notification by stefano over all available channels\");\n    notify(allMessage);\n```\n\nThe `notify` function could/should be implemented in a hugely easier way but, for this example, I will implement it leveraging the type_traits concept.\nThe instance, one of the several kinds of message the application can feed to the `notify` function, brings internally the information about the kind.\nDoing so the application developer (aka the library user) can call the function without any angle brackets.\n  \n## Data type declaration\nThe data type hides inside itself the message category\n```cpp\n    struct MqttMessage final : public GeneralMessage\n    {\n        typedef mqtt_message_tag message_category;\n    };\n```\nwhere `mqtt_message_tag` is just a struct tag declared as\n```cpp\n    struct mqtt_message_tag{};\n```\n\n## Notify function\nThe `notify` function is defined as follows:\n```cpp\n    template\u003cclass __Message\u003e\n    void notify(__Message const \u0026message)\n    {\n        typedef typename message_traits\u003c__Message\u003e::message_category category;\n        details::notify_dispatch(message.getMessage(), category());\n    }\n```\nwhere:\n- `notify` is a template function accepting a generic message\n- inside the function the category type is defined thanks to the message_traits utility struct\n- the namespaced, and hence potentially hidden, function `notify_dispatch` leverages the tag dispatching to select the right function to call between the various implementations\n\n## The type-trait\nThe template struct \n```cpp\n    template\u003ctypename __Message\u003e\n    struct message_traits\n    {\n        typedef typename __Message::message_category message_category;\n    };\n```\nis the piece of code that does the trick. It is a generic struct that acts as category pusher, which is in charge of exposing the message_category of the template generic parameter.\n \n## Extra\n### Building\nAlong with the repo you have a very basic Dockerfile to automatically build and just see what happens \n    \n    docker build -t message_traits .\n\n### CLion\nBeing this repo a CMake project, you can just open it with CLion and run it in debug.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefanofiorentino%2Fmessage_traits","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstefanofiorentino%2Fmessage_traits","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefanofiorentino%2Fmessage_traits/lists"}