ITADN

Marking a class as always-skipped

#2539Closedlithiumfluorine 创建于 2026-05-02
L
lithiumfluorinecommented
My code has classes I would like to serialise which contain several empty structs that are only there to serve as markers for other reflection to act upon. When serialising these, they show up as empty sub-object in the output. From what I can find in the documentation, one can use `glz::hide` to prevent this, but it only works when individually marking _fields_ of some type inside their containing classes. I instead wish to mark _the class itself_ as always hidden/never serialised. Is there a mechanism for this? I attempted various things along the likes of `constexpr static auto value = glz::hidden{}`, `using mimic = std::nullptr_t; value = nullptr`, and similar, to no avail. There appears to be a `glz::always_skipped` concept that does exactly this, but there seems to be no way to intentionally opt-in for an entire class. Simplified example of what I'm trying to do: ```cpp #include <glaze/glaze.hpp> #include <glaze/toml.hpp> #include <print> // Marker class used for metaprogramming stuff template<int SecretSauce> struct Marker { constexpr static inline auto SecretSauce = SecretSauce; // No actual values }; template<int N> struct glz::meta<Marker<N>> { // Would love to do this, in some way... constexpr static inline auto value = glz::hide{}; }; struct Settings { Marker<99> things_marker{}; bool enable_things{true}; int number_of_things{42}; Marker<200> stuff_marker{}; float stuff_multiplier{13.37f}; }; /* // Use-case for the markers is similar to this: void draw_menu(Settings& s) { for_each_field(s, [] { if constexpr (field is Marker) { menu.setFormat(field::SecretSauce); } else { menu.edit(field); } }) } */ int main() { auto result = glz::write_toml(Settings{}); std::println("{}", result.value()); } ``` **Desired output:** ```toml enable_things = true number_of_things = 42 stuff_multiplier = 13.37 ``` **Actual output:** ```toml enable_things = true number_of_things = 42 stuff_multiplier = 13.37 [things_marker] [stuff_marker] ```
关闭于 2026-05-09 4 条评论