{"id":15068160,"url":"https://github.com/mguludag/enum_name","last_synced_at":"2025-10-10T10:13:39.093Z","repository":{"id":122039195,"uuid":"605149615","full_name":"mguludag/enum_name","owner":"mguludag","description":"Converting (scoped)enum values to string names written in C++\u003e=11.","archived":false,"fork":false,"pushed_at":"2025-09-08T01:08:58.000Z","size":3085,"stargazers_count":21,"open_issues_count":4,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-08T02:33:54.469Z","etag":null,"topics":["compile-time","cpp","cpp11","cpp14","cpp17","cpp20","enum","reflection"],"latest_commit_sha":null,"homepage":"https://mguludag.github.io/enum_name/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mguludag.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-02-22T14:53:01.000Z","updated_at":"2025-09-08T01:08:31.000Z","dependencies_parsed_at":"2024-03-11T22:24:54.026Z","dependency_job_id":"b030da80-5810-4ecd-8745-9800ee12c31c","html_url":"https://github.com/mguludag/enum_name","commit_stats":{"total_commits":100,"total_committers":1,"mean_commits":100.0,"dds":0.0,"last_synced_commit":"e073dbec7431da4d40b856745edd162fa50ea7e2"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mguludag/enum_name","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mguludag%2Fenum_name","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mguludag%2Fenum_name/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mguludag%2Fenum_name/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mguludag%2Fenum_name/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mguludag","download_url":"https://codeload.github.com/mguludag/enum_name/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mguludag%2Fenum_name/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279003486,"owners_count":26083594,"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-10T02:00:06.843Z","response_time":62,"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":["compile-time","cpp","cpp11","cpp14","cpp17","cpp20","enum","reflection"],"created_at":"2024-09-25T01:31:52.541Z","updated_at":"2025-10-10T10:13:39.073Z","avatar_url":"https://github.com/mguludag.png","language":"C++","readme":"# enum_name\n\nConverting (scoped)enum values to/from string names written in C++\u003e=11.\n\n## Supported Compilers\n\n- Clang \u003e 5\n- GCC \u003e 8\n- MSVC \u003e 2015\n\n## Features\n\n- Supports `enum` and `enum class`\n- Supports enums in namespaces, classes or structs even templated or not\n- Supports full compile-time with C++20 and later\n- Changing enum range with template parameter \u003csub\u003e(default range: `[0, 256)`)\u003c/sub\u003e on each call or with your special function for types or adding specialized `enum_range\u003cEnum\u003e` struct\n- Supports and automatically overloaded `operator\u003c\u003c` and add `std::formatter` specialization for Enum types to direct using with ostream objects and `std::format` (If `fmtlib` is available, simply adding the specialization like this [`template \u003c\u003e struct fmt::formatter\u003cYourEnumType\u003e : ostream_formatter {};`] is enough.)\n- Supports custom enum name(s) input/output by explicit specialization of `template \u003c\u003e struct mgutility::custom_enum\u003cEnum\u003e` with `static constexpr mgutility::flat_map\u003cEnum\u003e map{{Enum, const char*},...}` variable.\n- Supports bitmasked enums and auto detect them\n- Supports iterate over enum (names and values) with `mgutility::enum_for_each\u003cT\u003e()` class and it is compatible with standard ranges and views\n\n## Limitations\n\n- Compiler versions\n- Wider range can increase compile time so user responsible to adjusting for enum's range\n\n## Fetch library with CMake\n\n```CMake\ninclude(FetchContent)\n\nFetchContent_Declare(\n  enum_name\n  GIT_REPOSITORY https://github.com/mguludag/enum_name.git\n  GIT_TAG main # or the specific tag or branch you want to use\n)\n\nFetchContent_MakeAvailable(enum_name)\n\n#...\n\ntarget_link_libraries(${PROJECT_NAME} PRIVATE mgutility::enum_name)\n```\n\n## Example usage ([try it!](https://godbolt.org/z/1nqrj78vb))\n\n```C++\n#include \u003ciostream\u003e\n\n#include \"mgutility/reflection/enum_name.hpp\"\n\n#if defined(__cpp_lib_print)\n#include \u003cprint\u003e\n#include \u003cranges\u003e\n#endif\n\nenum class Position {\n  Top = 1 \u003c\u003c 0,\n  Right = 1 \u003c\u003c 1,\n  Bottom = 1 \u003c\u003c 2,\n  Left = 1 \u003c\u003c 3\n};\n\n// Define bitwise OR operator for Position\nauto constexpr operator|(Position lhs, Position rhs) -\u003e Position {\n  return static_cast\u003cPosition\u003e(mgutility::enum_to_underlying(lhs) |\n                               mgutility::enum_to_underlying(rhs));\n}\n\n// Define bitwise AND operator for Position\nauto constexpr operator\u0026(Position lhs, Position rhs) -\u003e Position {\n  return static_cast\u003cPosition\u003e(mgutility::enum_to_underlying(lhs) \u0026\n                               mgutility::enum_to_underlying(rhs));\n}\n\n// Define the range for Position enum values (Option 1)\ntemplate \u003c\u003e\nstruct mgutility::enum_range\u003cPosition\u003e {\n  static constexpr auto min = 0;  // Minimum value\n  static constexpr auto max = 16; // Maximum value\n};\n\n// Specialize individual or all enum names\ntemplate \u003c\u003e\nstruct mgutility::custom_enum\u003cPosition\u003e {\n  static constexpr mgutility::flat_map\u003cPosition\u003e map{\n      {Position::Top, \"TOP\"},\n      {Position::Right, \"RIGHT\"},\n      {Position::Bottom, \"BOTTOM\"},\n      {Position::Left, \"LEFT\"},\n      {Position::Top | Position::Right | Position::Bottom | Position::Left,\n       \"CENTER\"}};\n};\n\nint main() {\n\n  // Specify enum range when call enum_name function (Option 2)\n  // Lambda function to get enum name\n  auto enum_name = [](Position c) { return mgutility::enum_name\u003c0, 16\u003e(c); };\n\n  auto x = Position::Left;\n  auto y = mgutility::to_enum\u003cPosition\u003e(\"CENTER\"); // Convert string to enum\n\n#if defined(__cpp_lib_constexpr_string)\n  static_assert(mgutility::enum_name(Position::Top | Position::Right) ==\n                \"TOP|RIGHT\"); // Compile-time check\n  static_assert(mgutility::to_enum\u003cPosition\u003e(\"BOTTOM|LEFT\") ==\n                (Position::Bottom | Position::Left)); // Compile-time check\n#endif\n\n#if defined(__cpp_lib_print)\n\n  // Print each Position and its underlying value using ranges\n  auto positions =\n      mgutility::enum_for_each\u003cPosition\u003e() |\n      std::ranges::views::filter([](auto \u0026\u0026pair) {\n        return !pair.second.empty() \u0026\u0026\n               pair.second.find('|') == mgutility::string_view::npos;\n      });\n\n  std::ranges::for_each(positions, [](auto \u0026\u0026pos) {\n    std::println(\"{} \\t: {}\", mgutility::enum_to_underlying(pos.first),\n                 pos.second);\n  });\n\n#else\n\n  // Print each Position and its underlying value using a for loop\n  for (auto \u0026\u0026e : mgutility::enum_for_each\u003cPosition\u003e()) {\n    if (!e.second.empty() \u0026\u0026\n        e.second.find('|') == mgutility::string_view::npos) {\n      std::cout \u003c\u003c mgutility::enum_to_underlying(e.first) \u003c\u003c \" \\t: \" \u003c\u003c e.second\n                \u003c\u003c '\\n';\n    }\n  }\n#endif\n\n  // Print the value of x\n  std::cout \u003c\u003c '\\n' \u003c\u003c x \u003c\u003c '\\n';\n\n  // Print the name of y or \"TOP\" if y is not valid\n  std::cout \u003c\u003c y.value_or(Position::Top) \u003c\u003c '\\n';\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmguludag%2Fenum_name","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmguludag%2Fenum_name","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmguludag%2Fenum_name/lists"}