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:
parent
58f5fdf3f1
commit
b34a78216b
15
json.hpp
15
json.hpp
@ -272,14 +272,25 @@ namespace json {
|
|||||||
|
|
||||||
std::ostream&
|
std::ostream&
|
||||||
operator <<(std::ostream &os, const json::node &n);
|
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>
|
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>
|
template <typename T>
|
||||||
T from_json (const json::node&);
|
T from_json (const json::node &n) {
|
||||||
|
return json::io<T>::deserialise (n);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user