-
Notifications
You must be signed in to change notification settings - Fork 909
Description
In my application, I use MSGPACK_DEFINE
to pack custom classes into the array format. The format is known on both ends and they are both C++ (for now).
I'd like to introduce a limited form of "dynamic typing" to the message. I want it include a heterogeneous array, where each element may either be Foo
or Bar
.
Internally I have this implemented using std::vector<boost::variant<Foo, Bar> >
, and I am hacking into the message a format basically equivalent to msgpack-cli's known-subtype polymorphism. I use typeid(T).name()
as the type indicator, which is of course unportable. And the custom (un)pack is verbose and specific to variant<Foo, Bar>
.
I wonder if there is a more robust way to do this with templates, and if so, is it worth implementing into the library?
Of course the map format doesn't have this issue because everything is dynamically typed. And I know it's already possible to convert objects to generic recursive variant
s. But the compact and static array format suits my application better.