{"id":16692896,"url":"https://github.com/seleznevae/smart_enum_deprecated","last_synced_at":"2025-03-13T22:43:02.980Z","repository":{"id":93769085,"uuid":"87638342","full_name":"seleznevae/smart_enum_deprecated","owner":"seleznevae","description":null,"archived":false,"fork":false,"pushed_at":"2017-04-08T14:13:09.000Z","size":898,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-24T10:44:54.742Z","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":"wtfpl","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/seleznevae.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":"2017-04-08T14:08:17.000Z","updated_at":"2017-04-08T14:08:30.000Z","dependencies_parsed_at":"2023-03-08T12:00:30.469Z","dependency_job_id":null,"html_url":"https://github.com/seleznevae/smart_enum_deprecated","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/seleznevae%2Fsmart_enum_deprecated","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seleznevae%2Fsmart_enum_deprecated/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seleznevae%2Fsmart_enum_deprecated/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seleznevae%2Fsmart_enum_deprecated/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/seleznevae","download_url":"https://codeload.github.com/seleznevae/smart_enum_deprecated/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243495490,"owners_count":20299921,"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-10-12T16:28:46.281Z","updated_at":"2025-03-13T22:43:02.961Z","avatar_url":"https://github.com/seleznevae.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Smart enum (deprecated version)\n[![Build Status](https://travis-ci.org/seleznevae/smart_enum_deprecated.svg?branch=master)](https://travis-ci.org/seleznevae/smart_enum_deprecated)\n- [Design goals](#design-goals)\n- [Examples](#examples)\n- [License](#license) \n\nSmart enum is a short test library for smart enums in C++.\nImplementation is based on materials for [SMETA](http://b.atch.se/posts/constexpr-meta-container/attachments/stateful_meta_container-poc.cpp) (stateful meta-programming library) by Filip Roséen.\n\nAuthor doesn't know if these techniques are valid according to the C++ standard and this programs are not ill-formed.\nSo **it's not recommended to use this library in your production code**. **This library is just an experiment**.\n\n## Design goals\n\nC++ doesn't have reflection. It is a common technique to use macros to add compile time information about enumeration like the following:\n\n```c++\nenum class Animal {\n  Dog = 1,\n  Cat = 1,\n  Lion = 1,\n  Horse = 1,\n};\n\nDECLARE_ENUM(Animal, Animal::Dog, Animal::Cat, Animal::Lion, Animal::Horse);\n```\nThis code violates **DRY** (don't repeat yourself) principle. The aim of **smart enum** library is to provide a user with macros that can be used in enum declaration and the user will not need to repeat enum elements.\n\n\n## Examples\n\nDeclaration of smart enum looks like this:\n```c++\n#include \"smart_enum.h\"\n\nSMART_ENUM(Animal, int) {\n    INITIALIZE_SMART_ENUM;\n\n    SM_ENUM_ELEM(Dog,    1,  \"dog\"  , \"dog_description\");\n    SM_ENUM_ELEM(Cat,    2,  \"cat\"  );\n    SM_ENUM_ELEM(Lion,   5);\n    SM_ENUM_ELEM(Horse,  10,  \"hOrse\");\n};\n```\nDefinitions of variables:\n```c++\nAnimal pet_cat   = Animal::Cat;\nAnimal pet_dog   = Animal::Dog;\nAnimal pet_lion  = Animal::Lion;\nAnimal pet_horse = Animal::Horse;\n```\n\nIt is possible to convert smart enums to strings:\n```c++\nstd::cout \u003c\u003c \"pet name: \" \u003c\u003c smart_enum::to_string(pet_cat) \u003c\u003c std::endl;\n//pet name: cat\nstd::cout \u003c\u003c \"pet name: \" \u003c\u003c smart_enum::to_string(pet_lion) \u003c\u003c std::endl;\n//pet name: Lion\n```\n\nIt is possible get descriptions for smart enum values:\n```c++\nstd::cout \u003c\u003c \"descr.: \" \u003c\u003c smart_enum::get_description(pet_dog) \u003c\u003c std::endl;\n//descr.: dog_description\nstd::cout \u003c\u003c \"descr.: \" \u003c\u003c smart_enum::get_description(pet_horse) \u003c\u003c std::endl;\n//descr.: hOrse\n```\n\nSmart enums can be used in switch statements like ordinal enums:\n```c++\nswitch (pet_cat) {\n     case Animal::Cat:\n         assert(true);\n         break;\n     case Animal::Horse:\n         assert(false);\n         break;\n     default:\n         assert(false);\n         break;\n }\n```\nIt is possible to get information about number of elements declared in smart enum:\n```c++\nstd::cout \u003c\u003c \"Elements in smart enum: \" \u003c\u003c smart_enum::enum_size\u003cAnimal\u003e() \u003c\u003c std::endl;\n//Elements in smart enum: 4\n```\n\nIt is possible to get information about number of elements declared in smart enum:\n```c++\nAnimal invalid;\n*(reinterpret_cast\u003cint*\u003e(\u0026invalid)) = 6666;\nassert(smart_enum::check(invalid) == false);\n```\n## License\nWTFPL \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseleznevae%2Fsmart_enum_deprecated","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fseleznevae%2Fsmart_enum_deprecated","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseleznevae%2Fsmart_enum_deprecated/lists"}