From b0c6b33f205f625fe6cc368a8cc10f2b9282781a Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 5 Aug 2013 20:54:19 +1000 Subject: [PATCH] Add to_json for bool, nullptr, string --- json.cpp.rl | 24 ++++++++++++++++++++++++ json.hpp | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/json.cpp.rl b/json.cpp.rl index 3f5f2bd5..b2881e04 100644 --- a/json.cpp.rl +++ b/json.cpp.rl @@ -557,3 +557,27 @@ json::null::write (std::ostream &os) const { ostream& json::operator <<(ostream &os, const json::node &n) { return n.write (os); } + + +//----------------------------------------------------------------------------- +// to_json + +namespace json { + template <> + std::unique_ptr + io::serialise (const bool &b) { + return std::unique_ptr (new boolean (b)); + } + + template <> + std::unique_ptr + io::serialise (const nullptr_t &) { + return std::unique_ptr (new null ()); + } + + template <> + std::unique_ptr + io::serialise (const std::string &s) { + return std::unique_ptr (new string (s)); + } +} diff --git a/json.hpp b/json.hpp index b86476e9..56385619 100644 --- a/json.hpp +++ b/json.hpp @@ -286,7 +286,7 @@ namespace json { template -json::node&& to_json (const T &t, Args&&... args) { +std::unique_ptr to_json (const T &t, Args&&... args) { return json::io::serialise (t, std::forward(args)...); }