Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. C/C++
  3. Nameof

Nameof

MITC++v0.10.6

A header-only C++17 library providing macros and functions to obtain the names of variables, types, functions, macros, and enums at compile-time.

GitHubGitHub
2.3k stars127 forks0 contributors

What is Nameof?

Nameof is a header-only C++17 library that provides compile-time reflection capabilities to obtain string names of C++ entities such as variables, types, functions, macros, and enums. It solves the problem of manually hardcoding identifier names in debugging, logging, or serialization code, reducing errors and improving maintainability.

Target Audience

C++ developers working on projects that require logging, debugging, serialization, or runtime type information without heavy reflection overhead, particularly those using C++17 or later.

Value Proposition

Developers choose Nameof for its simplicity, zero runtime overhead, and ease of integration as a single-header library, offering a lightweight alternative to complex reflection systems while supporting modern C++ features.

Overview

Nameof operator for modern C++, simply obtain the name of a variable, type, function, macro, and enum

Use Cases

Best For

  • Adding descriptive logging with variable and function names
  • Serializing C++ objects with type names included
  • Implementing enum-to-string conversion for debugging
  • Creating error messages that include identifier names
  • Building reflection-based utilities without RTTI overhead
  • Generating code or documentation from C++ source structures

Not Ideal For

  • Projects targeting C++ standards older than C++17, as the library requires C++17 features.
  • Applications needing full runtime reflection for dynamic type inspection or method invocation, beyond simple name extraction.
  • Codebases with strict policies against macro usage, due to Nameof's heavy reliance on macros for its API.
  • Systems where cross-compiler support is critical without extensive testing, as compiler compatibility varies per feature (see limitations.md).

Pros & Cons

Pros

Compile-Time Zero Overhead

Most operations, like NAMEOF and NAMEOF_ENUM, are evaluated at compile-time, ensuring no runtime cost, which is ideal for performance-sensitive logging and serialization.

Wide Entity Coverage

Supports variables, member expressions, functions, macros, enums, and types with dedicated macros like NAMEOF_FULL for full names and NAMEOF_SHORT for simplified names.

Easy Package Integration

Header-only library with seamless support for vcpkg, Conan, and AUR, simplifying dependency management in various build systems.

Advanced Enum Handling

Provides enum-to-string conversion with NAMEOF_ENUM, support for enum flags via NAMEOF_ENUM_FLAG, and fallbacks for out-of-range values, reducing manual error-prone code.

Cons

Limited Reflection Scope

Only extracts string names and does not support deeper reflection like accessing member values or invoking methods, which restricts its use in complex serialization or introspection tasks.

Macro-Based Design Drawbacks

Heavy use of macros can lead to naming conflicts, obscure error messages, and challenges in debugging, contrasting with modern C++ constexpr approaches.

Compiler Dependency

Functionality is compiler-specific; the reference documentation notes varying support across compilers, requiring additional validation for cross-platform projects.

Frequently Asked Questions

Quick Stats

Stars2,342
Forks127
Contributors0
Open Issues0
Last commit1 day ago
CreatedSince 2018

Tags

#type-reflection#debugging-tools#metaprogramming#cplusplus-17#cpp17#c-plus-plus#logging#header-only-library#cplusplus#serialization#compile-time-reflection#c-plus-plus-17#cpp

Built With

C
C++17

Included in

C/C++70.6kGame Engine Development1.3k
Auto-fetched 17 hours ago

Related Projects

imguiimgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies

Stars74,986
Forks11,931
Last commit1 day ago
C/C++C/C++

A curated list of awesome C++ (or C) frameworks, libraries, resources, and shiny things. Inspired by awesome-... stuff.

Stars72,398
Forks8,320
Last commit5 days ago
ProtoBufProtoBuf

Protocol Buffers - Google's data interchange format

Stars71,621
Forks16,200
Last commit15 hours ago
JSON for Modern C++JSON for Modern C++

JSON for Modern C++

Stars50,198
Forks7,437
Last commit1 day ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub