{"id":13494051,"url":"https://github.com/Neargye/nameof","last_synced_at":"2025-03-28T13:31:55.040Z","repository":{"id":39578553,"uuid":"125595170","full_name":"Neargye/nameof","owner":"Neargye","description":"Nameof operator for modern C++, simply obtain the name of a variable, type, function, macro, and enum","archived":false,"fork":false,"pushed_at":"2024-10-14T12:38:48.000Z","size":701,"stargazers_count":2169,"open_issues_count":2,"forks_count":114,"subscribers_count":35,"default_branch":"master","last_synced_at":"2025-03-27T15:08:26.243Z","etag":null,"topics":["c-plus-plus","c-plus-plus-17","cplusplus","cplusplus-17","cpp","cpp17","enum-to-string","header-only","metaprogramming","nameof","nameof-operator","no-dependencies","reflection","serialization","single-file"],"latest_commit_sha":null,"homepage":"","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/Neargye.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},"funding":{"custom":["paypal.me/Neargye","btc.com/btc/address/bc1qzevldln8tqz5xf4lyufu9msgl7t97xstth9zq8","etherscan.io/address/0xbb42fdef9204fa6f3d535d202b088dee35fcbd31"],"liberapay":"neargye"}},"created_at":"2018-03-17T03:59:41.000Z","updated_at":"2025-03-27T01:32:53.000Z","dependencies_parsed_at":"2023-11-22T22:26:39.300Z","dependency_job_id":"ea063d52-5f51-439a-8ec5-b515fb44f67d","html_url":"https://github.com/Neargye/nameof","commit_stats":{"total_commits":549,"total_committers":12,"mean_commits":45.75,"dds":0.08561020036429867,"last_synced_commit":"6c8e87da57a22939b412f11dcf1acbde898ecf46"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neargye%2Fnameof","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neargye%2Fnameof/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neargye%2Fnameof/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neargye%2Fnameof/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Neargye","download_url":"https://codeload.github.com/Neargye/nameof/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246037422,"owners_count":20713417,"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":["c-plus-plus","c-plus-plus-17","cplusplus","cplusplus-17","cpp","cpp17","enum-to-string","header-only","metaprogramming","nameof","nameof-operator","no-dependencies","reflection","serialization","single-file"],"created_at":"2024-07-31T19:01:21.285Z","updated_at":"2025-03-28T13:31:55.016Z","avatar_url":"https://github.com/Neargye.png","language":"C++","readme":"[![Github releases](https://img.shields.io/github/release/Neargye/nameof.svg)](https://github.com/Neargye/nameof/releases)\n[![Conan package](https://img.shields.io/badge/Conan-package-blueviolet)](https://conan.io/center/recipes/nameof)\n[![Vcpkg package](https://img.shields.io/badge/Vcpkg-package-blueviolet)](https://github.com/microsoft/vcpkg/tree/master/ports/nameof)\n[![License](https://img.shields.io/github/license/Neargye/nameof.svg)](LICENSE)\n[![Compiler explorer](https://img.shields.io/badge/compiler_explorer-online-blue.svg)](https://godbolt.org/z/s_ecko)\n[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://stand-with-ukraine.pp.ua)\n\n# Nameof C++\n\nHeader-only C++17 library provides nameof macros and functions to simply obtain the name of a variable, type, function, macro, and enum.\n\nIf you like this project, please consider donating to one of the funds that help victims of the war in Ukraine: https://u24.gov.ua.\n\n## Documentation\n\n* [Reference](doc/reference.md)\n* [Limitations](doc/limitations.md)\n* [Integration](#Integration)\n\n## [Features \u0026 Examples](example/example.cpp)\n\n* Nameof\n\n  ```cpp\n  // Name of variable.\n  NAMEOF(somevar) -\u003e \"somevar\"\n\n  // Name of member variable.\n  NAMEOF(person.address.zip_code) -\u003e \"zip_code\"\n\n  // Name of function.\n  NAMEOF(foo\u003cint, float\u003e()) -\u003e \"foo\"\n\n  // Name of member function.\n  NAMEOF(somevar.some_method()) -\u003e \"some_method\"\n  NAMEOF(somevar.some_method\u003cint\u003e()) -\u003e \"some_method\"\n\n  // Name of macro.\n  NAMEOF(__LINE__) -\u003e \"__LINE__\"\n  NAMEOF(NAMEOF(structvar)) -\u003e \"NAMEOF\"\n\n  // Obtains full name of variable, function, macro.\n  NAMEOF_FULL(somevar.some_method\u003cint\u003e()) -\u003e \"some_method\u003cint\u003e\"\n\n  // Obtains raw name of variable, function, macro.\n  NAMEOF_RAW(somevar.some_method\u003cint\u003e()) -\u003e \"somevar.some_method\u003cint\u003e()\"\n  ```\n\n* Nameof enum\n\n  ```cpp\n  enum class Color { RED = 1, BLUE = 2, GREEN = 4 };\n\n  auto color = Color::RED;\n  // Name of enum variable.\n  NAMEOF_ENUM(color) -\u003e \"RED\"\n  nameof::nameof_enum(color) -\u003e \"RED\"\n\n  // Static storage enum variable to string.\n  // This version is much lighter on the compile times and is not restricted to the enum_range limitation.\n  NAMEOF_ENUM_CONST(Color::GREEN) -\u003e \"GREEN\"\n  nameof::nameof_enum\u003cColor::GREEN\u003e() -\u003e \"GREEN\"\n\n  // Enum flags variable to string.\n  NAMEOF_ENUM_FLAG(Color::GREEN | Color::BLUE) -\u003e \"GREEN|BLUE\"\n  nameof::nameof_enum_flag\u003cColor::GREEN | Color::BLUE\u003e() -\u003e \"GREEN|BLUE\"\n\n  // Obtains name of enum variable or default value if enum variable out of range.\n  NAMEOF_ENUM_OR(Color::GREEN) -\u003e \"GREEN\"\n  NAMEOF_ENUM_OR((Color)0, \"none\") -\u003e \"none\"\n  ```\n\n* Nameof type\n\n  ```cpp\n  const my::detail::SomeClass\u003cint\u003e\u0026 var_ref = var;\n  // Name of variable type.\n  NAMEOF_TYPE_EXPR(var_ref) -\u003e \"my::detail::SomeClass\u003cint\u003e\"\n  nameof::nameof_type\u003cdecltype(var_ref)\u003e() -\u003e \"my::detail::SomeClass\u003cint\u003e\"\n  NAMEOF_FULL_TYPE_EXPR(var_ref) -\u003e \"const my::detail::SomeClass\u003cint\u003e\u0026\"\n  nameof::nameof_full_type\u003cdecltype(var_ref)\u003e() -\u003e \"const my::detail::SomeClass\u003cint\u003e\u0026\"\n  NAMEOF_SHORT_TYPE_EXPR(var_ref) -\u003e \"SomeClass\"\n  nameof::nameof_short_type\u003cdecltype(var_ref)\u003e() -\u003e \"SomeClass\"\n\n  using T = const my::detail::SomeClass\u003cint\u003e\u0026;\n  // Name of type.\n  NAMEOF_TYPE(T) -\u003e\"my::detail::SomeClass\u003cint\u003e\"\n  nameof::nameof_type\u003cT\u003e() -\u003e \"my::detail::SomeClass\u003cint\u003e\"\n  NAMEOF_FULL_TYPE(T) -\u003e \"const my::detail::SomeClass\u003cint\u003e\u0026\"\n  nameof::nameof_full_type\u003cT\u003e() -\u003e \"const my::detail::SomeClass\u003cint\u003e\u0026\"\n  NAMEOF_SHORT_TYPE(T) -\u003e \"SomeClass\"\n  nameof::nameof_short_type\u003cT\u003e() -\u003e \"SomeClass\"\n\n  my::detail::Base* ptr = new my::detail::Derived();\n  // Name of type, using rtti.\n  NAMEOF_TYPE_RTTI(*ptr) -\u003e \"my::detail::Derived\"\n  NAMEOF_FULL_TYPE_RTTI(*ptr) -\u003e \"volatile const my::detail::Derived\u0026\"\n  NAMEOF_SHORT_TYPE_RTTI(*ptr) -\u003e \"Derived\"\n\n  struct A {\n    int this_is_the_name;\n  };\n  // Obtains name of member.\n  NAMEOF_MEMBER(\u0026A::this_is_the_name) -\u003e \"this_is_the_name\"\n  nameof::nameof_member(\u0026A::this_is_the_name) -\u003e \"this_is_the_name\"\n\n  int someglobalvariable = 0;\n  // Obtains name of a function, a global or class static variable.\n  NAMEOF_POINTER(\u0026someglobalconstvariable) == \"someglobalconstvariable\"\n  nameof::nameof_pointer(\u0026someglobalconstvariable) == \"someglobalconstvariable\"\n\n  constexpr auto global_ptr = \u0026someglobalvariable;\n  NAMEOF_POINTER(global_ptr) == \"someglobalconstvariable\"\n  nameof::nameof_pointer(global_ptr) == \"someglobalconstvariable\"\n  ```\n\n## Remarks\n\n* Before use, read the [limitations](doc/limitations.md) of functionality.\n\n## Integration\n\nYou should add required file [nameof.hpp](include/nameof.hpp).\n\nIf you are using [vcpkg](https://github.com/Microsoft/vcpkg/) on your project for external dependencies, then you can use the [nameof package](https://github.com/microsoft/vcpkg/tree/master/ports/nameof).\n\nIf you are using [Conan](https://www.conan.io/) to manage your dependencies, merely add `nameof/x.y.z` to your conan's requires, where `x.y.z` is the release version you want to use.\n\nArchlinux users can install `nameof` by package manager AUR, using the following command: `yay -S nameof`.\n\nAlternatively, you can use something like [CPM](https://github.com/TheLartians/CPM) which is based on CMake's `Fetch_Content` module.\n\n```cmake\nCPMAddPackage(\n    NAME nameof\n    GITHUB_REPOSITORY Neargye/nameof\n    GIT_TAG x.y.z # Where `x.y.z` is the release version you want to use.\n)\n```\n\n## Compiler compatibility\n\nCheck in the [reference](doc/reference.md) for each features.\n\n## Licensed under the [MIT License](LICENSE)\n","funding_links":["paypal.me/Neargye","btc.com/btc/address/bc1qzevldln8tqz5xf4lyufu9msgl7t97xstth9zq8","etherscan.io/address/0xbb42fdef9204fa6f3d535d202b088dee35fcbd31","https://liberapay.com/neargye"],"categories":["Reflection","Libraries","C++","Coding","映射"],"sub_categories":["C++","c++","物理学","Misc"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNeargye%2Fnameof","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNeargye%2Fnameof","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNeargye%2Fnameof/lists"}