Use an intermediate class for json serialisation

To avoid the no-partial-specialisation rule for functions, use a class
we can partially specialise instead.
This commit is contained in:
Danny Robson 2012-08-10 17:37:23 +10:00
parent 58f5fdf3f1
commit b34a78216b

View File

@ -272,14 +272,25 @@ namespace json {
std::ostream&
operator <<(std::ostream &os, const json::node &n);
template <typename T>
struct io {
static std::unique_ptr<json::node> serialise (const T&);
static T deserialise (const json::node&);
};
}
template <typename T>
json::node&& to_json (const T&);
json::node&& to_json (const T &t) {
return json::io<T>::serialise (t);
}
template <typename T>
T from_json (const json::node&);
T from_json (const json::node &n) {
return json::io<T>::deserialise (n);
}
#endif