-
Notifications
You must be signed in to change notification settings - Fork 803
Type traits for load_minimal use incorrect archive when looking up save_minimal return type #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Right now since enums are still getting pulled in by default you'd have to write something like this: namespace cereal
{
template <class T> inline
typename std::enable_if<common_detail::is_enum<T>::value, std::string>::type
save_minimal( JSONOutputArchive const &, T const & t )
{
// somehow convert t to a string
}
template <class T> inline
typename std::enable_if<common_detail::is_enum<T>::value, void>::type
load_minimal( JSONInputArchive const &, T && t, std::string const & value )
{
// somehow convert value into t
}
} Unfortunately you have to specialize explicitly for each archive type because the generic version of the enum serialization takes the archive as a template parameter, so you need to come up with an overload that has higher precedence (and writing another template with some This is the general game you play with all serialization functions - there can only be one highest priority valid overload for each archive-type pairing. You also need to put this in the cereal namespace so that the compiler can find it properly. |
I cannot/dontwanto do it globally (i.e. for all enums), so defined the following:
UNFORTUNATELY, I get a compiler error - which I think is NOT CORRECT. |
There's a bug in our type traits that look up the return type of |
Added a set of trait classes that can be used to get an input archive from an output archive. Requires specializing a struct for each direction or alternatively using the new macro CEREAL_SETUP_ARCHIVE_TRAITS(InArchive, OutArchive). This has already been added for all built in archive types. This is currently only used for minimal serialization. load_minimal type traits now correctly use the output archive to check the existence of a corresponding save_minimal and get its return type, using the new get_input_from_output type class. Added a test for this case into the minimal structs test. Sandbox_vs needed the new macro to become compliant.
Should be good to go now. |
I still think that the following is relevant for others besides me
I want to serialize enums to strings for text archives, while for binary I want to use standard serialization as an int.
(For my own classes, I want to define a standard serialization, but as soon as I define a string serialization, I want it to be applied for all text archives, while for binary the standard is applied.)
After trying for 2h, I gave up.
Could you come up with a convenient way to do this?
The text was updated successfully, but these errors were encountered: