Add argument forwarding to {to,from}_json
This commit is contained in:
parent
b17f7691a1
commit
fcd3f73704
15
json.hpp
15
json.hpp
@ -274,6 +274,9 @@ namespace json {
|
|||||||
operator <<(std::ostream &os, const json::node &n);
|
operator <<(std::ostream &os, const json::node &n);
|
||||||
|
|
||||||
|
|
||||||
|
// Instantiate this template for the type you wish to output. We use a
|
||||||
|
// helper class here to avoid partial template specialisation of a
|
||||||
|
// function (eg, for templated types).
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct io {
|
struct io {
|
||||||
static std::unique_ptr<json::node> serialise (const T&);
|
static std::unique_ptr<json::node> serialise (const T&);
|
||||||
@ -282,14 +285,14 @@ namespace json {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, class ...Args>
|
||||||
json::node&& to_json (const T &t) {
|
json::node&& to_json (const T &t, Args&&... args) {
|
||||||
return json::io<T>::serialise (t);
|
return json::io<T>::serialise (t, std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, class ...Args>
|
||||||
T from_json (const json::node &n) {
|
T from_json (const json::node &n, Args&&... args) {
|
||||||
return json::io<T>::deserialise (n);
|
return json::io<T>::deserialise (n, std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user