diff cpp/json_util/json_util.cpp @ 656:734ce3a26a58

json_util: upgrade to 3.5.0 and add string_view overload
author David Demelier <markand@malikania.fr>
date Mon, 21 Jan 2019 20:45:02 +0100
parents 87e1f4c7da76
children
line wrap: on
line diff
--- a/cpp/json_util/json_util.cpp	Mon Jan 21 20:39:31 2019 +0100
+++ b/cpp/json_util/json_util.cpp	Mon Jan 21 20:45:02 2019 +0100
@@ -85,6 +85,14 @@
 	return value.get<std::string>();
 }
 
+auto type_traits<std::string_view>::get(const json& value) -> std::optional<std::string_view>
+{
+	if (!value.is_string())
+		return std::nullopt;
+
+	return value.get<std::string_view>();
+}
+
 auto type_traits<std::int8_t>::get(const json& value) -> std::optional<std::int8_t>
 {
 	return clampi<std::int8_t>(value);