From 0841e49b4643d727a3bbac4ba08538bcab21c922 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Thu, 14 Jul 2022 20:39:37 +0200 Subject: [PATCH] Util: Add user-defined string literal for Json::Value --- src/util/json/value.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/util/json/value.h b/src/util/json/value.h index ad0c871..602f5c7 100644 --- a/src/util/json/value.h +++ b/src/util/json/value.h @@ -7,7 +7,7 @@ #ifndef JSON_VALUE_H #define JSON_VALUE_H -#include // nullptr_t +#include // nullptr_t, size_t #include // uint32_t #include #include // istream, ostream @@ -129,4 +129,14 @@ std::ostream& operator<<(std::ostream& output, const Value& value); } // namespace Json +/** + * User-defined string literal + * + * Example usage: auto json = "[ 3.14, true, null ]"_json; + */ +inline Json::Value operator"" _json(const char* input, size_t length) +{ + return Json::Value::parse(std::string(input, length)); +} + #endif // JSON_VALUE_H