Add to_json for bool, nullptr, string

This commit is contained in:
Danny Robson 2013-08-05 20:54:19 +10:00
parent e4da68ffe7
commit b0c6b33f20
2 changed files with 25 additions and 1 deletions

View File

@ -557,3 +557,27 @@ json::null::write (std::ostream &os) const {
ostream& ostream&
json::operator <<(ostream &os, const json::node &n) json::operator <<(ostream &os, const json::node &n)
{ return n.write (os); } { return n.write (os); }
//-----------------------------------------------------------------------------
// to_json
namespace json {
template <>
std::unique_ptr<node>
io<bool>::serialise (const bool &b) {
return std::unique_ptr<node> (new boolean (b));
}
template <>
std::unique_ptr<node>
io<nullptr_t>::serialise (const nullptr_t &) {
return std::unique_ptr<node> (new null ());
}
template <>
std::unique_ptr<node>
io<std::string>::serialise (const std::string &s) {
return std::unique_ptr<node> (new string (s));
}
}

View File

@ -286,7 +286,7 @@ namespace json {
template <typename T, class ...Args> template <typename T, class ...Args>
json::node&& to_json (const T &t, Args&&... args) { std::unique_ptr<json::node> to_json (const T &t, Args&&... args) {
return json::io<T>::serialise (t, std::forward<Args>(args)...); return json::io<T>::serialise (t, std::forward<Args>(args)...);
} }