This adds a READWRITEAS(type, obj) macro which serializes obj as if it were converted to const type& when const, and to type& when non-const. No actual cast is involved, so this only works when this conversion can be done automatically.
This makes it usable in serialization code that uses a single implementation for both serialization and deserializing, which doesn't know the constness of the object involved.
This is a redo of #12712, using a slightly different interface.