I'm in the process of updating a project from version 2.1.1 to the version 3.x series.
I have the following two functions defined to handle enum classes:
template <typename JSON, typename Enum>
void to_json(JSON & j, Enum e) {
j = ToString(e);
}
template <typename JSON, typename Enum>
void from_json(const JSON & j, Enum & e) {
if (!FromString(e, j)) {
throw std::invalid_argument("Badness...");
}
}
There are definitions of ToString and FromString for all the enumerations of interest. I'm not using SFINAE to restrict Enum to enumerations, because it's not currently needed. With version 2.1.1, everything is working fine.
With the update to 3.x, these functions are no longer found by the lookup. If I comment out the new enum to_json and from_json inside the library, the errors disappear, and all is well again.
How can I make my functions work? Do I need a more specific signature? I don't want to define a function for every enumeration, if I can get away with it.
I'm in the process of updating a project from version 2.1.1 to the version 3.x series.
I have the following two functions defined to handle enum classes:
There are definitions of
ToStringandFromStringfor all the enumerations of interest. I'm not using SFINAE to restrictEnumto enumerations, because it's not currently needed. With version 2.1.1, everything is working fine.With the update to 3.x, these functions are no longer found by the lookup. If I comment out the new enum
to_jsonandfrom_jsoninside the library, the errors disappear, and all is well again.How can I make my functions work? Do I need a more specific signature? I don't want to define a function for every enumeration, if I can get away with it.