I think P2996 lacks an important feature, that is, customized metadata for reflection. As we all know, we can serialize and deserialize struct automatically through static reflection, but sometimes, for some fields (maybe private), we want to skip it. It is a common demand, But unfortunately, there is no way to allow users to attach metadata to fields in P2996 currently.
In other languages, customized metadata is widely used. For example, we can mark a field
[JsonIgnore] in
C# and
#[serde(skip_deserializing)] in
Rust to skip fields for serialization. Besides, although C++ does not have reflection now, some frameworks implement reflection on their own through code generation. They all support customized metadata. For example,
UPROPERTY in UE and
Q_PROPERTY in QT. Clang and GCC also support an attribute to expose metadata in AST, which is [[clang::annotate("")]]; some code generation tools use it to customize metadata.
So, in my opinion, we cannot write a serialization library based on P2996 that is as convenient as those in other languages without a way to allow users to customize metadata. I suggest adding a new attribute
[[annotate(constant-expression, ...)]] to allow users to attach metadata to some entries. And, we can use reflection to get the annotations of entries.
This topic may be related to the proposal
Attributes Introspection. And the idea is at an early stage, any suggestion is welcome.
ykiko.
--