File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -119,20 +119,27 @@ namespace vix::json
119119 inline Json arr () { return Json::array (); }
120120
121121 /* *
122- * @brief JSON string literal helpers from nlohmann .
122+ * @brief JSON string literal helpers.
123123 *
124124 * Enables:
125125 * @code
126+ * #define VIX_JSON_ENABLE_LITERALS 1
126127 * using namespace vix::json::literals;
127128 * Json j = R"({"a": 1, "b": 2})"_json;
128129 * @endcode
130+ *
131+ * Note:
132+ * Disabled by default because it relies on parsing (can throw).
129133 */
130- #if defined(NLOHMANN_JSON_VERSION_MAJOR)
131- #if (NLOHMANN_JSON_VERSION_MAJOR > 3) || \
132- (NLOHMANN_JSON_VERSION_MAJOR == 3 && NLOHMANN_JSON_VERSION_MINOR >= 10 )
133- namespace literals = nlohmann::literals::json_literals;
134- #endif
134+ namespace literals
135+ {
136+ #if defined(VIX_JSON_ENABLE_LITERALS) && (VIX_JSON_ENABLE_LITERALS == 1)
137+ inline Json operator " " _json(const char *s, std::size_t n)
138+ {
139+ return Json::parse (std::string_view{s, n});
140+ }
135141#endif
142+ } // namespace literals
136143
137144} // namespace vix::json
138145
Original file line number Diff line number Diff line change @@ -146,7 +146,7 @@ namespace vix::json
146146 try
147147 {
148148 Json j = Json::parse (s);
149- return j ;
149+ return std::optional<Json>{ std::move (j)} ;
150150 }
151151 catch (...)
152152 {
You can’t perform that action at this time.
0 commit comments