A header-only C++ library for struct-field reflection using visitors, enabling iteration over struct members without built-in reflection.
visit_struct is a C++ library that enables struct-field reflection through the visitor pattern, allowing iteration over struct members at compile time. It solves the problem of writing repetitive code for tasks like serialization, debugging, and equality comparison by providing generic visitation mechanisms.
C++ developers working with POD types who need to reduce boilerplate for operations like serialization, logging, or generic algorithms that operate on struct fields.
It offers a simple, dependency-free alternative to heavier libraries like Boost.Hana, with better compiler support for older C++11 compilers and a cleaner syntax for struct visitation.
A miniature library for struct-field reflection in C++
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Single-header library with zero external dependencies, making integration trivial—just include visit_struct.hpp without build system changes.
Uses template-based visitors with no runtime overhead, allowing optimizations like inlining; binary visitation can match hand-rolled equality operators in assembly.
Works with older C++11 compilers like gcc-4.8 and MSVC 2013, offering better compatibility than Boost.Hana, which requires higher conformance.
Supports non-intrusive macros, intrusive macros, and Boost.Fusion/Hana compatibility, adapting to different project constraints and migration needs.
Includes binary visitation for comparisons, indexed access via get/get_name, and constexpr support for metaprogramming, as shown in test files.
Requires manual listing of struct members in macros (e.g., VISITABLE_STRUCT), which is error-prone and adds maintenance burden if fields change.
Primarily targets POD types; complex scenarios like visiting private members or nested structs require workarounds or aren't directly supported.
Constexpr support varies by compiler and C++ standard, with macros like VISIT_STRUCT_CONSTEXPR needing manual overrides on some platforms.
Has default caps on visitable members (69 for non-intrusive, 100 for intrusive), requiring source tweaks for large structs, as noted in IMPLEMENTATION_NOTES.md.