JSON for Modern C++  3.7.0
json.hpp
1 /*
2  __ _____ _____ _____
3  __| | __| | | | JSON for Modern C++
4 | | |__ | | | | | | version 3.7.0
5 |_____|_____|_____|_|___| https://github.com/nlohmann/json
6 
7 Licensed under the MIT License <http://opensource.org/licenses/MIT>.
8 SPDX-License-Identifier: MIT
9 Copyright (c) 2013-2019 Niels Lohmann <http://nlohmann.me>.
10 
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is
16 furnished to do so, subject to the following conditions:
17 
18 The above copyright notice and this permission notice shall be included in all
19 copies or substantial portions of the Software.
20 
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 SOFTWARE.
28 */
29 
30 #ifndef INCLUDE_NLOHMANN_JSON_HPP_
31 #define INCLUDE_NLOHMANN_JSON_HPP_
32 
33 #define NLOHMANN_JSON_VERSION_MAJOR 3
34 #define NLOHMANN_JSON_VERSION_MINOR 7
35 #define NLOHMANN_JSON_VERSION_PATCH 0
36 
37 #include <algorithm> // all_of, find, for_each
38 #include <cassert> // assert
39 #include <ciso646> // and, not, or
40 #include <cstddef> // nullptr_t, ptrdiff_t, size_t
41 #include <functional> // hash, less
42 #include <initializer_list> // initializer_list
43 #include <iosfwd> // istream, ostream
44 #include <iterator> // random_access_iterator_tag
45 #include <memory> // unique_ptr
46 #include <numeric> // accumulate
47 #include <string> // string, stoi, to_string
48 #include <utility> // declval, forward, move, pair, swap
49 #include <vector> // vector
50 
51 // #include <nlohmann/adl_serializer.hpp>
52 
53 
54 #include <utility>
55 
56 // #include <nlohmann/detail/conversions/from_json.hpp>
57 
58 
59 #include <algorithm> // transform
60 #include <array> // array
61 #include <ciso646> // and, not
62 #include <forward_list> // forward_list
63 #include <iterator> // inserter, front_inserter, end
64 #include <map> // map
65 #include <string> // string
66 #include <tuple> // tuple, make_tuple
67 #include <type_traits> // is_arithmetic, is_same, is_enum, underlying_type, is_convertible
68 #include <unordered_map> // unordered_map
69 #include <utility> // pair, declval
70 #include <valarray> // valarray
71 
72 // #include <nlohmann/detail/exceptions.hpp>
73 
74 
75 #include <exception> // exception
76 #include <stdexcept> // runtime_error
77 #include <string> // to_string
78 
79 // #include <nlohmann/detail/input/position_t.hpp>
80 
81 
82 #include <cstddef> // size_t
83 
84 namespace nlohmann
85 {
86 namespace detail
87 {
88 /// struct to capture the start position of the current token
89 struct position_t
90 {
91  /// the total number of characters read
92  std::size_t chars_read_total = 0;
93  /// the number of characters read in the current line
94  std::size_t chars_read_current_line = 0;
95  /// the number of lines read
96  std::size_t lines_read = 0;
97 
98  /// conversion to size_t to preserve SAX interface
99  constexpr operator size_t() const
100  {
101  return chars_read_total;
102  }
103 };
104 
105 } // namespace detail
106 } // namespace nlohmann
107 
108 // #include <nlohmann/detail/macro_scope.hpp>
109 
110 
111 #include <utility> // pair
112 // #include <nlohmann/thirdparty/hedley/hedley.hpp>
113 /* Hedley - https://nemequ.github.io/hedley
114  * Created by Evan Nemerson <evan@nemerson.com>
115  *
116  * To the extent possible under law, the author(s) have dedicated all
117  * copyright and related and neighboring rights to this software to
118  * the public domain worldwide. This software is distributed without
119  * any warranty.
120  *
121  * For details, see <http://creativecommons.org/publicdomain/zero/1.0/>.
122  * SPDX-License-Identifier: CC0-1.0
123  */
124 
125 #if !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < 9)
126 #if defined(JSON_HEDLEY_VERSION)
127  #undef JSON_HEDLEY_VERSION
128 #endif
129 #define JSON_HEDLEY_VERSION 9
130 
131 #if defined(JSON_HEDLEY_STRINGIFY_EX)
132  #undef JSON_HEDLEY_STRINGIFY_EX
133 #endif
134 #define JSON_HEDLEY_STRINGIFY_EX(x) #x
135 
136 #if defined(JSON_HEDLEY_STRINGIFY)
137  #undef JSON_HEDLEY_STRINGIFY
138 #endif
139 #define JSON_HEDLEY_STRINGIFY(x) JSON_HEDLEY_STRINGIFY_EX(x)
140 
141 #if defined(JSON_HEDLEY_CONCAT_EX)
142  #undef JSON_HEDLEY_CONCAT_EX
143 #endif
144 #define JSON_HEDLEY_CONCAT_EX(a,b) a##b
145 
146 #if defined(JSON_HEDLEY_CONCAT)
147  #undef JSON_HEDLEY_CONCAT
148 #endif
149 #define JSON_HEDLEY_CONCAT(a,b) JSON_HEDLEY_CONCAT_EX(a,b)
150 
151 #if defined(JSON_HEDLEY_VERSION_ENCODE)
152  #undef JSON_HEDLEY_VERSION_ENCODE
153 #endif
154 #define JSON_HEDLEY_VERSION_ENCODE(major,minor,revision) (((major) * 1000000) + ((minor) * 1000) + (revision))
155 
156 #if defined(JSON_HEDLEY_VERSION_DECODE_MAJOR)
157  #undef JSON_HEDLEY_VERSION_DECODE_MAJOR
158 #endif
159 #define JSON_HEDLEY_VERSION_DECODE_MAJOR(version) ((version) / 1000000)
160 
161 #if defined(JSON_HEDLEY_VERSION_DECODE_MINOR)
162  #undef JSON_HEDLEY_VERSION_DECODE_MINOR
163 #endif
164 #define JSON_HEDLEY_VERSION_DECODE_MINOR(version) (((version) % 1000000) / 1000)
165 
166 #if defined(JSON_HEDLEY_VERSION_DECODE_REVISION)
167  #undef JSON_HEDLEY_VERSION_DECODE_REVISION
168 #endif
169 #define JSON_HEDLEY_VERSION_DECODE_REVISION(version) ((version) % 1000)
170 
171 #if defined(JSON_HEDLEY_GNUC_VERSION)
172  #undef JSON_HEDLEY_GNUC_VERSION
173 #endif
174 #if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__)
175  #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
176 #elif defined(__GNUC__)
177  #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, 0)
178 #endif
179 
180 #if defined(JSON_HEDLEY_GNUC_VERSION_CHECK)
181  #undef JSON_HEDLEY_GNUC_VERSION_CHECK
182 #endif
183 #if defined(JSON_HEDLEY_GNUC_VERSION)
184  #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GNUC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
185 #else
186  #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (0)
187 #endif
188 
189 #if defined(JSON_HEDLEY_MSVC_VERSION)
190  #undef JSON_HEDLEY_MSVC_VERSION
191 #endif
192 #if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000)
193  #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 10000000, (_MSC_FULL_VER % 10000000) / 100000, (_MSC_FULL_VER % 100000) / 100)
194 #elif defined(_MSC_FULL_VER)
195  #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 1000000, (_MSC_FULL_VER % 1000000) / 10000, (_MSC_FULL_VER % 10000) / 10)
196 #elif defined(_MSC_VER)
197  #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_VER / 100, _MSC_VER % 100, 0)
198 #endif
199 
200 #if defined(JSON_HEDLEY_MSVC_VERSION_CHECK)
201  #undef JSON_HEDLEY_MSVC_VERSION_CHECK
202 #endif
203 #if !defined(_MSC_VER)
204  #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (0)
205 #elif defined(_MSC_VER) && (_MSC_VER >= 1400)
206  #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch)))
207 #elif defined(_MSC_VER) && (_MSC_VER >= 1200)
208  #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch)))
209 #else
210  #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_VER >= ((major * 100) + (minor)))
211 #endif
212 
213 #if defined(JSON_HEDLEY_INTEL_VERSION)
214  #undef JSON_HEDLEY_INTEL_VERSION
215 #endif
216 #if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE)
217  #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE)
218 #elif defined(__INTEL_COMPILER)
219  #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0)
220 #endif
221 
222 #if defined(JSON_HEDLEY_INTEL_VERSION_CHECK)
223  #undef JSON_HEDLEY_INTEL_VERSION_CHECK
224 #endif
225 #if defined(JSON_HEDLEY_INTEL_VERSION)
226  #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
227 #else
228  #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (0)
229 #endif
230 
231 #if defined(JSON_HEDLEY_PGI_VERSION)
232  #undef JSON_HEDLEY_PGI_VERSION
233 #endif
234 #if defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__)
235  #define JSON_HEDLEY_PGI_VERSION JSON_HEDLEY_VERSION_ENCODE(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__)
236 #endif
237 
238 #if defined(JSON_HEDLEY_PGI_VERSION_CHECK)
239  #undef JSON_HEDLEY_PGI_VERSION_CHECK
240 #endif
241 #if defined(JSON_HEDLEY_PGI_VERSION)
242  #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PGI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
243 #else
244  #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (0)
245 #endif
246 
247 #if defined(JSON_HEDLEY_SUNPRO_VERSION)
248  #undef JSON_HEDLEY_SUNPRO_VERSION
249 #endif
250 #if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000)
251  #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_C >> 16) & 0xf) * 10) + ((__SUNPRO_C >> 12) & 0xf), (((__SUNPRO_C >> 8) & 0xf) * 10) + ((__SUNPRO_C >> 4) & 0xf), (__SUNPRO_C & 0xf) * 10)
252 #elif defined(__SUNPRO_C)
253  #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_C >> 8) & 0xf, (__SUNPRO_C >> 4) & 0xf, (__SUNPRO_C) & 0xf)
254 #elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000)
255  #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_CC >> 16) & 0xf) * 10) + ((__SUNPRO_CC >> 12) & 0xf), (((__SUNPRO_CC >> 8) & 0xf) * 10) + ((__SUNPRO_CC >> 4) & 0xf), (__SUNPRO_CC & 0xf) * 10)
256 #elif defined(__SUNPRO_CC)
257  #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_CC >> 8) & 0xf, (__SUNPRO_CC >> 4) & 0xf, (__SUNPRO_CC) & 0xf)
258 #endif
259 
260 #if defined(JSON_HEDLEY_SUNPRO_VERSION_CHECK)
261  #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
262 #endif
263 #if defined(JSON_HEDLEY_SUNPRO_VERSION)
264  #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_SUNPRO_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
265 #else
266  #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (0)
267 #endif
268 
269 #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
270  #undef JSON_HEDLEY_EMSCRIPTEN_VERSION
271 #endif
272 #if defined(__EMSCRIPTEN__)
273  #define JSON_HEDLEY_EMSCRIPTEN_VERSION JSON_HEDLEY_VERSION_ENCODE(__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__)
274 #endif
275 
276 #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK)
277  #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
278 #endif
279 #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
280  #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_EMSCRIPTEN_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
281 #else
282  #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (0)
283 #endif
284 
285 #if defined(JSON_HEDLEY_ARM_VERSION)
286  #undef JSON_HEDLEY_ARM_VERSION
287 #endif
288 #if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION)
289  #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCOMPILER_VERSION / 1000000, (__ARMCOMPILER_VERSION % 1000000) / 10000, (__ARMCOMPILER_VERSION % 10000) / 100)
290 #elif defined(__CC_ARM) && defined(__ARMCC_VERSION)
291  #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCC_VERSION / 1000000, (__ARMCC_VERSION % 1000000) / 10000, (__ARMCC_VERSION % 10000) / 100)
292 #endif
293 
294 #if defined(JSON_HEDLEY_ARM_VERSION_CHECK)
295  #undef JSON_HEDLEY_ARM_VERSION_CHECK
296 #endif
297 #if defined(JSON_HEDLEY_ARM_VERSION)
298  #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_ARM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
299 #else
300  #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (0)
301 #endif
302 
303 #if defined(JSON_HEDLEY_IBM_VERSION)
304  #undef JSON_HEDLEY_IBM_VERSION
305 #endif
306 #if defined(__ibmxl__)
307  #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ibmxl_version__, __ibmxl_release__, __ibmxl_modification__)
308 #elif defined(__xlC__) && defined(__xlC_ver__)
309  #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, (__xlC_ver__ >> 8) & 0xff)
310 #elif defined(__xlC__)
311  #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, 0)
312 #endif
313 
314 #if defined(JSON_HEDLEY_IBM_VERSION_CHECK)
315  #undef JSON_HEDLEY_IBM_VERSION_CHECK
316 #endif
317 #if defined(JSON_HEDLEY_IBM_VERSION)
318  #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IBM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
319 #else
320  #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (0)
321 #endif
322 
323 #if defined(JSON_HEDLEY_TI_VERSION)
324  #undef JSON_HEDLEY_TI_VERSION
325 #endif
326 #if defined(__TI_COMPILER_VERSION__)
327  #define JSON_HEDLEY_TI_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
328 #endif
329 
330 #if defined(JSON_HEDLEY_TI_VERSION_CHECK)
331  #undef JSON_HEDLEY_TI_VERSION_CHECK
332 #endif
333 #if defined(JSON_HEDLEY_TI_VERSION)
334  #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
335 #else
336  #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (0)
337 #endif
338 
339 #if defined(JSON_HEDLEY_CRAY_VERSION)
340  #undef JSON_HEDLEY_CRAY_VERSION
341 #endif
342 #if defined(_CRAYC)
343  #if defined(_RELEASE_PATCHLEVEL)
344  #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, _RELEASE_PATCHLEVEL)
345  #else
346  #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, 0)
347  #endif
348 #endif
349 
350 #if defined(JSON_HEDLEY_CRAY_VERSION_CHECK)
351  #undef JSON_HEDLEY_CRAY_VERSION_CHECK
352 #endif
353 #if defined(JSON_HEDLEY_CRAY_VERSION)
354  #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_CRAY_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
355 #else
356  #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (0)
357 #endif
358 
359 #if defined(JSON_HEDLEY_IAR_VERSION)
360  #undef JSON_HEDLEY_IAR_VERSION
361 #endif
362 #if defined(__IAR_SYSTEMS_ICC__)
363  #if __VER__ > 1000
364  #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE((__VER__ / 1000000), ((__VER__ / 1000) % 1000), (__VER__ % 1000))
365  #else
366  #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE(VER / 100, __VER__ % 100, 0)
367  #endif
368 #endif
369 
370 #if defined(JSON_HEDLEY_IAR_VERSION_CHECK)
371  #undef JSON_HEDLEY_IAR_VERSION_CHECK
372 #endif
373 #if defined(JSON_HEDLEY_IAR_VERSION)
374  #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IAR_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
375 #else
376  #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (0)
377 #endif
378 
379 #if defined(JSON_HEDLEY_TINYC_VERSION)
380  #undef JSON_HEDLEY_TINYC_VERSION
381 #endif
382 #if defined(__TINYC__)
383  #define JSON_HEDLEY_TINYC_VERSION JSON_HEDLEY_VERSION_ENCODE(__TINYC__ / 1000, (__TINYC__ / 100) % 10, __TINYC__ % 100)
384 #endif
385 
386 #if defined(JSON_HEDLEY_TINYC_VERSION_CHECK)
387  #undef JSON_HEDLEY_TINYC_VERSION_CHECK
388 #endif
389 #if defined(JSON_HEDLEY_TINYC_VERSION)
390  #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TINYC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
391 #else
392  #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (0)
393 #endif
394 
395 #if defined(JSON_HEDLEY_DMC_VERSION)
396  #undef JSON_HEDLEY_DMC_VERSION
397 #endif
398 #if defined(__DMC__)
399  #define JSON_HEDLEY_DMC_VERSION JSON_HEDLEY_VERSION_ENCODE(__DMC__ >> 8, (__DMC__ >> 4) & 0xf, __DMC__ & 0xf)
400 #endif
401 
402 #if defined(JSON_HEDLEY_DMC_VERSION_CHECK)
403  #undef JSON_HEDLEY_DMC_VERSION_CHECK
404 #endif
405 #if defined(JSON_HEDLEY_DMC_VERSION)
406  #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_DMC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
407 #else
408  #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (0)
409 #endif
410 
411 #if defined(JSON_HEDLEY_COMPCERT_VERSION)
412  #undef JSON_HEDLEY_COMPCERT_VERSION
413 #endif
414 #if defined(__COMPCERT_VERSION__)
415  #define JSON_HEDLEY_COMPCERT_VERSION JSON_HEDLEY_VERSION_ENCODE(__COMPCERT_VERSION__ / 10000, (__COMPCERT_VERSION__ / 100) % 100, __COMPCERT_VERSION__ % 100)
416 #endif
417 
418 #if defined(JSON_HEDLEY_COMPCERT_VERSION_CHECK)
419  #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
420 #endif
421 #if defined(JSON_HEDLEY_COMPCERT_VERSION)
422  #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_COMPCERT_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
423 #else
424  #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (0)
425 #endif
426 
427 #if defined(JSON_HEDLEY_PELLES_VERSION)
428  #undef JSON_HEDLEY_PELLES_VERSION
429 #endif
430 #if defined(__POCC__)
431  #define JSON_HEDLEY_PELLES_VERSION JSON_HEDLEY_VERSION_ENCODE(__POCC__ / 100, __POCC__ % 100, 0)
432 #endif
433 
434 #if defined(JSON_HEDLEY_PELLES_VERSION_CHECK)
435  #undef JSON_HEDLEY_PELLES_VERSION_CHECK
436 #endif
437 #if defined(JSON_HEDLEY_PELLES_VERSION)
438  #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PELLES_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
439 #else
440  #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (0)
441 #endif
442 
443 #if defined(JSON_HEDLEY_GCC_VERSION)
444  #undef JSON_HEDLEY_GCC_VERSION
445 #endif
446 #if
447  defined(JSON_HEDLEY_GNUC_VERSION) &&
448  !defined(__clang__) &&
449  !defined(JSON_HEDLEY_INTEL_VERSION) &&
450  !defined(JSON_HEDLEY_PGI_VERSION) &&
451  !defined(JSON_HEDLEY_ARM_VERSION) &&
452  !defined(JSON_HEDLEY_TI_VERSION) &&
453  !defined(__COMPCERT__)
454  #define JSON_HEDLEY_GCC_VERSION JSON_HEDLEY_GNUC_VERSION
455 #endif
456 
457 #if defined(JSON_HEDLEY_GCC_VERSION_CHECK)
458  #undef JSON_HEDLEY_GCC_VERSION_CHECK
459 #endif
460 #if defined(JSON_HEDLEY_GCC_VERSION)
461  #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
462 #else
463  #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (0)
464 #endif
465 
466 #if defined(JSON_HEDLEY_HAS_ATTRIBUTE)
467  #undef JSON_HEDLEY_HAS_ATTRIBUTE
468 #endif
469 #if defined(__has_attribute)
470  #define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute)
471 #else
472  #define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0)
473 #endif
474 
475 #if defined(JSON_HEDLEY_GNUC_HAS_ATTRIBUTE)
476  #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
477 #endif
478 #if defined(__has_attribute)
479  #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) __has_attribute(attribute)
480 #else
481  #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
482 #endif
483 
484 #if defined(JSON_HEDLEY_GCC_HAS_ATTRIBUTE)
485  #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
486 #endif
487 #if defined(__has_attribute)
488  #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) __has_attribute(attribute)
489 #else
490  #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
491 #endif
492 
493 #if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE)
494  #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
495 #endif
496 #if defined(__has_cpp_attribute) && defined(__cplusplus)
497  #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribute)
498 #else
499  #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) (0)
500 #endif
501 
502 #if defined(JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE)
503  #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
504 #endif
505 #if defined(__has_cpp_attribute) && defined(__cplusplus)
506  #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)
507 #else
508  #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
509 #endif
510 
511 #if defined(JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE)
512  #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
513 #endif
514 #if defined(__has_cpp_attribute) && defined(__cplusplus)
515  #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)
516 #else
517  #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
518 #endif
519 
520 #if defined(JSON_HEDLEY_HAS_BUILTIN)
521  #undef JSON_HEDLEY_HAS_BUILTIN
522 #endif
523 #if defined(__has_builtin)
524  #define JSON_HEDLEY_HAS_BUILTIN(builtin) __has_builtin(builtin)
525 #else
526  #define JSON_HEDLEY_HAS_BUILTIN(builtin) (0)
527 #endif
528 
529 #if defined(JSON_HEDLEY_GNUC_HAS_BUILTIN)
530  #undef JSON_HEDLEY_GNUC_HAS_BUILTIN
531 #endif
532 #if defined(__has_builtin)
533  #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)
534 #else
535  #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
536 #endif
537 
538 #if defined(JSON_HEDLEY_GCC_HAS_BUILTIN)
539  #undef JSON_HEDLEY_GCC_HAS_BUILTIN
540 #endif
541 #if defined(__has_builtin)
542  #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)
543 #else
544  #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
545 #endif
546 
547 #if defined(JSON_HEDLEY_HAS_FEATURE)
548  #undef JSON_HEDLEY_HAS_FEATURE
549 #endif
550 #if defined(__has_feature)
551  #define JSON_HEDLEY_HAS_FEATURE(feature) __has_feature(feature)
552 #else
553  #define JSON_HEDLEY_HAS_FEATURE(feature) (0)
554 #endif
555 
556 #if defined(JSON_HEDLEY_GNUC_HAS_FEATURE)
557  #undef JSON_HEDLEY_GNUC_HAS_FEATURE
558 #endif
559 #if defined(__has_feature)
560  #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)
561 #else
562  #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
563 #endif
564 
565 #if defined(JSON_HEDLEY_GCC_HAS_FEATURE)
566  #undef JSON_HEDLEY_GCC_HAS_FEATURE
567 #endif
568 #if defined(__has_feature)
569  #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)
570 #else
571  #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
572 #endif
573 
574 #if defined(JSON_HEDLEY_HAS_EXTENSION)
575  #undef JSON_HEDLEY_HAS_EXTENSION
576 #endif
577 #if defined(__has_extension)
578  #define JSON_HEDLEY_HAS_EXTENSION(extension) __has_extension(extension)
579 #else
580  #define JSON_HEDLEY_HAS_EXTENSION(extension) (0)
581 #endif
582 
583 #if defined(JSON_HEDLEY_GNUC_HAS_EXTENSION)
584  #undef JSON_HEDLEY_GNUC_HAS_EXTENSION
585 #endif
586 #if defined(__has_extension)
587  #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)
588 #else
589  #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
590 #endif
591 
592 #if defined(JSON_HEDLEY_GCC_HAS_EXTENSION)
593  #undef JSON_HEDLEY_GCC_HAS_EXTENSION
594 #endif
595 #if defined(__has_extension)
596  #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)
597 #else
598  #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
599 #endif
600 
601 #if defined(JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE)
602  #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
603 #endif
604 #if defined(__has_declspec_attribute)
605  #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) __has_declspec_attribute(attribute)
606 #else
607  #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) (0)
608 #endif
609 
610 #if defined(JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE)
611  #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
612 #endif
613 #if defined(__has_declspec_attribute)
614  #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)
615 #else
616  #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
617 #endif
618 
619 #if defined(JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE)
620  #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
621 #endif
622 #if defined(__has_declspec_attribute)
623  #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)
624 #else
625  #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
626 #endif
627 
628 #if defined(JSON_HEDLEY_HAS_WARNING)
629  #undef JSON_HEDLEY_HAS_WARNING
630 #endif
631 #if defined(__has_warning)
632  #define JSON_HEDLEY_HAS_WARNING(warning) __has_warning(warning)
633 #else
634  #define JSON_HEDLEY_HAS_WARNING(warning) (0)
635 #endif
636 
637 #if defined(JSON_HEDLEY_GNUC_HAS_WARNING)
638  #undef JSON_HEDLEY_GNUC_HAS_WARNING
639 #endif
640 #if defined(__has_warning)
641  #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)
642 #else
643  #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
644 #endif
645 
646 #if defined(JSON_HEDLEY_GCC_HAS_WARNING)
647  #undef JSON_HEDLEY_GCC_HAS_WARNING
648 #endif
649 #if defined(__has_warning)
650  #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)
651 #else
652  #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
653 #endif
654 
655 #if
656  (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) ||
657  defined(__clang__) ||
667  (JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) && defined(__C99_PRAGMA_OPERATOR))
668  #define JSON_HEDLEY_PRAGMA(value) _Pragma(#value)
669 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
670  #define JSON_HEDLEY_PRAGMA(value) __pragma(value)
671 #else
672  #define JSON_HEDLEY_PRAGMA(value)
673 #endif
674 
675 #if defined(JSON_HEDLEY_DIAGNOSTIC_PUSH)
676  #undef JSON_HEDLEY_DIAGNOSTIC_PUSH
677 #endif
678 #if defined(JSON_HEDLEY_DIAGNOSTIC_POP)
679  #undef JSON_HEDLEY_DIAGNOSTIC_POP
680 #endif
681 #if defined(__clang__)
682  #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
683  #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
684 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
685  #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
686  #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
687 #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
688  #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
689  #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
690 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
691  #define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push))
692  #define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop))
693 #elif JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0)
694  #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push")
695  #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop")
696 #elif JSON_HEDLEY_TI_VERSION_CHECK(8,1,0)
697  #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("diag_push")
698  #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("diag_pop")
699 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
700  #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
701  #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
702 #else
703  #define JSON_HEDLEY_DIAGNOSTIC_PUSH
704  #define JSON_HEDLEY_DIAGNOSTIC_POP
705 #endif
706 
707 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED)
708  #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
709 #endif
710 #if JSON_HEDLEY_HAS_WARNING("-Wdeprecated-declarations")
711  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
712 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
713  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warning(disable:1478 1786)")
714 #elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
715  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
716 #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
717  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
718 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
719  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:4996))
720 #elif JSON_HEDLEY_TI_VERSION_CHECK(8,0,0)
721  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1291,1718")
722 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && !defined(__cplusplus)
723  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,E_DEPRECATED_ATT,E_DEPRECATED_ATT_MESS)")
724 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && defined(__cplusplus)
725  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,symdeprecated,symdeprecated2)")
726 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
727  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress=Pe1444,Pe1215")
728 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
729  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warn(disable:2241)")
730 #else
731  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
732 #endif
733 
734 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS)
735  #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
736 #endif
737 #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
738  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"")
739 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
740  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("warning(disable:161)")
741 #elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
742  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 1675")
743 #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
744  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"")
745 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
746  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:4068))
747 #elif JSON_HEDLEY_TI_VERSION_CHECK(8,0,0)
748  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
749 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
750  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress=Pe161")
751 #else
752  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
753 #endif
754 
755 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL)
756  #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
757 #endif
758 #if JSON_HEDLEY_HAS_WARNING("-Wcast-qual")
759  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("clang diagnostic ignored \"-Wcast-qual\"")
760 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
761  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("warning(disable:2203 2331)")
762 #elif JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0)
763  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("GCC diagnostic ignored \"-Wcast-qual\"")
764 #else
765  #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
766 #endif
767 
768 #if defined(JSON_HEDLEY_DEPRECATED)
769  #undef JSON_HEDLEY_DEPRECATED
770 #endif
771 #if defined(JSON_HEDLEY_DEPRECATED_FOR)
772  #undef JSON_HEDLEY_DEPRECATED_FOR
773 #endif
774 #if defined(__cplusplus) && (__cplusplus >= 201402L)
775  #define JSON_HEDLEY_DEPRECATED(since) [[deprecated("Since " #since)]]
776  #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) [[deprecated("Since " #since "; use " #replacement)]]
777 #elif
778  JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) ||
785  #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__("Since " #since)))
786  #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement)))
787 #elif
788  JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) ||
789  JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) ||
790  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) ||
791  JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) ||
792  (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__))
793  #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__))
794  #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__))
795 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0)
796  #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " # since))
797  #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement))
798 #elif
799  JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) ||
800  JSON_HEDLEY_PELLES_VERSION_CHECK(6,50,0)
801  #define JSON_HEDLEY_DEPRECATED(since) _declspec(deprecated)
802  #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated)
803 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
804  #define JSON_HEDLEY_DEPRECATED(since) _Pragma("deprecated")
805  #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) _Pragma("deprecated")
806 #else
807  #define JSON_HEDLEY_DEPRECATED(since)
808  #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement)
809 #endif
810 
811 #if defined(JSON_HEDLEY_UNAVAILABLE)
812  #undef JSON_HEDLEY_UNAVAILABLE
813 #endif
814 #if
815  JSON_HEDLEY_HAS_ATTRIBUTE(warning) ||
818  #define JSON_HEDLEY_UNAVAILABLE(available_since) __attribute__((__warning__("Not available until " #available_since)))
819 #else
820  #define JSON_HEDLEY_UNAVAILABLE(available_since)
821 #endif
822 
823 #if defined()
824  #undef
825 #endif
826 #if defined(__cplusplus) && (__cplusplus >= 201703L)
827  #define [[nodiscard]]
828 #elif
829  JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) ||
833  (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) ||
834  (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) ||
836  #define __attribute__((__warn_unused_result__))
837 #elif defined(_Check_return_) /* SAL */
838  #define _Check_return_
839 #else
840  #define
841 #endif
842 
843 #if defined(JSON_HEDLEY_SENTINEL)
844  #undef JSON_HEDLEY_SENTINEL
845 #endif
846 #if
847  JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) ||
851  #define JSON_HEDLEY_SENTINEL(position) __attribute__((__sentinel__(position)))
852 #else
853  #define JSON_HEDLEY_SENTINEL(position)
854 #endif
855 
856 #if defined(JSON_HEDLEY_NO_RETURN)
857  #undef JSON_HEDLEY_NO_RETURN
858 #endif
860  #define JSON_HEDLEY_NO_RETURN __noreturn
862  #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
863 #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
864  #define JSON_HEDLEY_NO_RETURN _Noreturn
865 #elif defined(__cplusplus) && (__cplusplus >= 201103L)
866  #define JSON_HEDLEY_NO_RETURN [[noreturn]]
867 #elif
868  JSON_HEDLEY_HAS_ATTRIBUTE(noreturn) ||
869  JSON_HEDLEY_GCC_VERSION_CHECK(3,2,0) ||
870  JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) ||
871  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) ||
872  JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) ||
873  JSON_HEDLEY_TI_VERSION_CHECK(18,0,0) ||
874  (JSON_HEDLEY_TI_VERSION_CHECK(17,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__))
875  #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
876 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0)
877  #define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
878 #elif JSON_HEDLEY_TI_VERSION_CHECK(6,0,0) && defined(__cplusplus)
879  #define JSON_HEDLEY_NO_RETURN _Pragma("FUNC_NEVER_RETURNS;")
880 #elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
881  #define JSON_HEDLEY_NO_RETURN __attribute((noreturn))
882 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
883  #define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
884 #else
885  #define JSON_HEDLEY_NO_RETURN
886 #endif
887 
888 #if defined(JSON_HEDLEY_UNREACHABLE)
889  #undef JSON_HEDLEY_UNREACHABLE
890 #endif
891 #if defined(JSON_HEDLEY_UNREACHABLE_RETURN)
892  #undef JSON_HEDLEY_UNREACHABLE_RETURN
893 #endif
894 #if
895  (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && (!defined(JSON_HEDLEY_ARM_VERSION))) ||
899  #define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable()
900 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0)
901  #define JSON_HEDLEY_UNREACHABLE() __assume(0)
902 #elif JSON_HEDLEY_TI_VERSION_CHECK(6,0,0)
903  #if defined(__cplusplus)
904  #define JSON_HEDLEY_UNREACHABLE() std::_nassert(0)
905  #else
906  #define JSON_HEDLEY_UNREACHABLE() _nassert(0)
907  #endif
908  #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return value
909 #elif defined(EXIT_FAILURE)
910  #define JSON_HEDLEY_UNREACHABLE() abort()
911 #else
912  #define JSON_HEDLEY_UNREACHABLE()
913  #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return value
914 #endif
915 #if !defined(JSON_HEDLEY_UNREACHABLE_RETURN)
916  #define JSON_HEDLEY_UNREACHABLE_RETURN(value) JSON_HEDLEY_UNREACHABLE()
917 #endif
918 
919 #if defined(JSON_HEDLEY_ASSUME)
920  #undef JSON_HEDLEY_ASSUME
921 #endif
922 #if
925  #define JSON_HEDLEY_ASSUME(expr) __assume(expr)
926 #elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume)
927  #define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr)
928 #elif JSON_HEDLEY_TI_VERSION_CHECK(6,0,0)
929  #if defined(__cplusplus)
930  #define JSON_HEDLEY_ASSUME(expr) std::_nassert(expr)
931  #else
932  #define JSON_HEDLEY_ASSUME(expr) _nassert(expr)
933  #endif
934 #elif
935  (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && !defined(JSON_HEDLEY_ARM_VERSION)) ||
936  JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) ||
937  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) ||
938  JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5)
939  #define JSON_HEDLEY_ASSUME(expr) ((void) ((expr) ? 1 : (__builtin_unreachable(), 1)))
940 #else
941  #define JSON_HEDLEY_ASSUME(expr) ((void) (expr))
942 #endif
943 
944 
946 #if
947  JSON_HEDLEY_HAS_WARNING("-Wvariadic-macros") ||
949  #if defined(__clang__)
950  #pragma clang diagnostic ignored "-Wvariadic-macros"
951  #elif defined(JSON_HEDLEY_GCC_VERSION)
952  #pragma GCC diagnostic ignored "-Wvariadic-macros"
953  #endif
954 #endif
955 #if defined(JSON_HEDLEY_NON_NULL)
956  #undef JSON_HEDLEY_NON_NULL
957 #endif
958 #if
959  JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) ||
963  #define JSON_HEDLEY_NON_NULL(...) __attribute__((__nonnull__(__VA_ARGS__)))
964 #else
965  #define JSON_HEDLEY_NON_NULL(...)
966 #endif
968 
969 #if defined(JSON_HEDLEY_PRINTF_FORMAT)
970  #undef JSON_HEDLEY_PRINTF_FORMAT
971 #endif
972 #if defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && !defined(__USE_MINGW_ANSI_STDIO)
973  #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(ms_printf, string_idx, first_to_check)))
974 #elif defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && defined(__USE_MINGW_ANSI_STDIO)
975  #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(gnu_printf, string_idx, first_to_check)))
976 #elif
977  JSON_HEDLEY_HAS_ATTRIBUTE(format) ||
983  (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__))
984  #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(__printf__, string_idx, first_to_check)))
985 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(6,0,0)
986  #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __declspec(vaformat(printf,string_idx,first_to_check))
987 #else
988  #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check)
989 #endif
990 
991 #if defined(JSON_HEDLEY_CONSTEXPR)
992  #undef JSON_HEDLEY_CONSTEXPR
993 #endif
994 #if defined(__cplusplus)
995  #if __cplusplus >= 201103L
996  #define JSON_HEDLEY_CONSTEXPR constexpr
997  #endif
998 #endif
999 #if !defined(JSON_HEDLEY_CONSTEXPR)
1000  #define JSON_HEDLEY_CONSTEXPR
1001 #endif
1002 
1003 #if defined(JSON_HEDLEY_PREDICT)
1004  #undef JSON_HEDLEY_PREDICT
1005 #endif
1006 #if defined(JSON_HEDLEY_LIKELY)
1007  #undef JSON_HEDLEY_LIKELY
1008 #endif
1009 #if defined(JSON_HEDLEY_UNLIKELY)
1010  #undef JSON_HEDLEY_UNLIKELY
1011 #endif
1012 #if defined(JSON_HEDLEY_UNPREDICTABLE)
1013  #undef JSON_HEDLEY_UNPREDICTABLE
1014 #endif
1015 #if JSON_HEDLEY_HAS_BUILTIN(__builtin_unpredictable)
1016  #define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable(!!(expr))
1017 #endif
1018 #if
1019  JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) ||
1021 # define JSON_HEDLEY_PREDICT(expr, value, probability) __builtin_expect_with_probability(expr, value, probability)
1022 # define JSON_HEDLEY_PREDICT_TRUE(expr, probability) __builtin_expect_with_probability(!!(expr), 1, probability)
1023 # define JSON_HEDLEY_PREDICT_FALSE(expr, probability) __builtin_expect_with_probability(!!(expr), 0, probability)
1024 # define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1)
1025 # define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
1026 #if !defined(JSON_HEDLEY_BUILTIN_UNPREDICTABLE)
1027  #define JSON_HEDLEY_BUILTIN_UNPREDICTABLE(expr) __builtin_expect_with_probability(!!(expr), 1, 0.5)
1028 #endif
1029 #elif
1030  JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) ||
1033  (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) ||
1038 # define JSON_HEDLEY_PREDICT(expr, expected, probability)
1039  (((probability) >= 0.9) ? __builtin_expect(!!(expr), (expected)) : (((void) (expected)), !!(expr)))
1040 # define JSON_HEDLEY_PREDICT_TRUE(expr, probability)
1041  (__extension__ ({
1042  JSON_HEDLEY_CONSTEXPR double hedley_probability_ = (probability);
1043  ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 1) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 0) : !!(expr)));
1044  }))
1045 # define JSON_HEDLEY_PREDICT_FALSE(expr, probability)
1046  (__extension__ ({
1047  JSON_HEDLEY_CONSTEXPR double hedley_probability_ = (probability);
1048  ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 0) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 1) : !!(expr)));
1049  }))
1050 # define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1)
1051 # define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
1052 #else
1053 # define JSON_HEDLEY_PREDICT(expr, expected, probability) (((void) (expected)), !!(expr))
1054 # define JSON_HEDLEY_PREDICT_TRUE(expr, probability) (!!(expr))
1055 # define JSON_HEDLEY_PREDICT_FALSE(expr, probability) (!!(expr))
1056 # define JSON_HEDLEY_LIKELY(expr) (!!(expr))
1057 # define JSON_HEDLEY_UNLIKELY(expr) (!!(expr))
1058 #endif
1059 #if !defined(JSON_HEDLEY_UNPREDICTABLE)
1060  #define JSON_HEDLEY_UNPREDICTABLE(expr) JSON_HEDLEY_PREDICT(expr, 1, 0.5)
1061 #endif
1062 
1063 #if defined(JSON_HEDLEY_MALLOC)
1064  #undef JSON_HEDLEY_MALLOC
1065 #endif
1066 #if
1067  JSON_HEDLEY_HAS_ATTRIBUTE(malloc) ||
1074  (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__))
1075  #define JSON_HEDLEY_MALLOC __attribute__((__malloc__))
1076 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(14, 0, 0)
1077  #define JSON_HEDLEY_MALLOC __declspec(restrict)
1078 #else
1079  #define JSON_HEDLEY_MALLOC
1080 #endif
1081 
1082 #if defined(JSON_HEDLEY_PURE)
1083  #undef JSON_HEDLEY_PURE
1084 #endif
1085 #if
1086  JSON_HEDLEY_HAS_ATTRIBUTE(pure) ||
1093  (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) ||
1095  #define JSON_HEDLEY_PURE __attribute__((__pure__))
1096 #elif JSON_HEDLEY_TI_VERSION_CHECK(6,0,0) && defined(__cplusplus)
1097  #define JSON_HEDLEY_PURE _Pragma("FUNC_IS_PURE;")
1098 #else
1099  #define JSON_HEDLEY_PURE
1100 #endif
1101 
1102 #if defined(JSON_HEDLEY_CONST)
1103  #undef JSON_HEDLEY_CONST
1104 #endif
1105 #if
1106  JSON_HEDLEY_HAS_ATTRIBUTE(const) ||
1113  (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) ||
1115  #define JSON_HEDLEY_CONST __attribute__((__const__))
1116 #else
1117  #define JSON_HEDLEY_CONST JSON_HEDLEY_PURE
1118 #endif
1119 
1120 #if defined(JSON_HEDLEY_RESTRICT)
1121  #undef JSON_HEDLEY_RESTRICT
1122 #endif
1123 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus)
1124  #define JSON_HEDLEY_RESTRICT restrict
1125 #elif
1131  JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) ||
1133  (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)) ||
1135  defined(__clang__)
1136  #define JSON_HEDLEY_RESTRICT __restrict
1137 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,3,0) && !defined(__cplusplus)
1138  #define JSON_HEDLEY_RESTRICT _Restrict
1139 #else
1140  #define JSON_HEDLEY_RESTRICT
1141 #endif
1142 
1143 #if defined(JSON_HEDLEY_INLINE)
1144  #undef JSON_HEDLEY_INLINE
1145 #endif
1146 #if
1147  (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) ||
1148  (defined(__cplusplus) && (__cplusplus >= 199711L))
1149  #define JSON_HEDLEY_INLINE inline
1150 #elif
1151  defined(JSON_HEDLEY_GCC_VERSION) ||
1152  JSON_HEDLEY_ARM_VERSION_CHECK(6,2,0)
1153  #define JSON_HEDLEY_INLINE __inline__
1154 #elif
1155  JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) ||
1156  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) ||
1157  JSON_HEDLEY_TI_VERSION_CHECK(8,0,0)
1158  #define JSON_HEDLEY_INLINE __inline
1159 #else
1160  #define JSON_HEDLEY_INLINE
1161 #endif
1162 
1163 #if defined(JSON_HEDLEY_ALWAYS_INLINE)
1164  #undef JSON_HEDLEY_ALWAYS_INLINE
1165 #endif
1166 #if
1167  JSON_HEDLEY_HAS_ATTRIBUTE(always_inline) ||
1174  (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__))
1175  #define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE
1176 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0)
1177  #define JSON_HEDLEY_ALWAYS_INLINE __forceinline
1178 #elif JSON_HEDLEY_TI_VERSION_CHECK(7,0,0) && defined(__cplusplus)
1179  #define JSON_HEDLEY_ALWAYS_INLINE _Pragma("FUNC_ALWAYS_INLINE;")
1180 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1181  #define JSON_HEDLEY_ALWAYS_INLINE _Pragma("inline=forced")
1182 #else
1183  #define JSON_HEDLEY_ALWAYS_INLINE JSON_HEDLEY_INLINE
1184 #endif
1185 
1186 #if defined(JSON_HEDLEY_NEVER_INLINE)
1187  #undef JSON_HEDLEY_NEVER_INLINE
1188 #endif
1189 #if
1190  JSON_HEDLEY_HAS_ATTRIBUTE(noinline) ||
1197  (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__))
1198  #define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__))
1199 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0)
1200  #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
1201 #elif JSON_HEDLEY_PGI_VERSION_CHECK(10,2,0)
1202  #define JSON_HEDLEY_NEVER_INLINE _Pragma("noinline")
1203 #elif JSON_HEDLEY_TI_VERSION_CHECK(6,0,0) && defined(__cplusplus)
1204  #define JSON_HEDLEY_NEVER_INLINE _Pragma("FUNC_CANNOT_INLINE;")
1205 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1206  #define JSON_HEDLEY_NEVER_INLINE _Pragma("inline=never")
1207 #elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
1208  #define JSON_HEDLEY_NEVER_INLINE __attribute((noinline))
1209 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
1210  #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
1211 #else
1212  #define JSON_HEDLEY_NEVER_INLINE
1213 #endif
1214 
1215 #if defined(JSON_HEDLEY_PRIVATE)
1216  #undef JSON_HEDLEY_PRIVATE
1217 #endif
1218 #if defined(JSON_HEDLEY_PUBLIC)
1219  #undef JSON_HEDLEY_PUBLIC
1220 #endif
1221 #if defined(JSON_HEDLEY_IMPORT)
1222  #undef JSON_HEDLEY_IMPORT
1223 #endif
1224 #if defined(_WIN32) || defined(__CYGWIN__)
1225  #define JSON_HEDLEY_PRIVATE
1226  #define JSON_HEDLEY_PUBLIC __declspec(dllexport)
1227  #define JSON_HEDLEY_IMPORT __declspec(dllimport)
1228 #else
1229  #if
1230  JSON_HEDLEY_HAS_ATTRIBUTE(visibility) ||
1237  (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_EABI__) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__))
1238  #define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden")))
1239  #define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default")))
1240  #else
1241  #define JSON_HEDLEY_PRIVATE
1242  #define JSON_HEDLEY_PUBLIC
1243  #endif
1244  #define JSON_HEDLEY_IMPORT extern
1245 #endif
1246 
1247 #if defined(JSON_HEDLEY_NO_THROW)
1248  #undef JSON_HEDLEY_NO_THROW
1249 #endif
1250 #if
1251  JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) ||
1254  #define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__))
1255 #elif
1256  JSON_HEDLEY_MSVC_VERSION_CHECK(13,1,0) ||
1257  JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
1258  #define JSON_HEDLEY_NO_THROW __declspec(nothrow)
1259 #else
1260  #define JSON_HEDLEY_NO_THROW
1261 #endif
1262 
1263 #if defined(JSON_HEDLEY_FALL_THROUGH)
1264  #undef JSON_HEDLEY_FALL_THROUGH
1265 #endif
1266 #if
1267  defined(__cplusplus) &&
1268  (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) &&
1269  !defined(JSON_HEDLEY_PGI_VERSION)
1270  #if
1271  (__cplusplus >= 201703L) ||
1272  ((__cplusplus >= 201103L) && JSON_HEDLEY_HAS_CPP_ATTRIBUTE(fallthrough))
1273  #define JSON_HEDLEY_FALL_THROUGH [[fallthrough]]
1274  #elif (__cplusplus >= 201103L) && JSON_HEDLEY_HAS_CPP_ATTRIBUTE(clang::fallthrough)
1275  #define JSON_HEDLEY_FALL_THROUGH [[clang::fallthrough]]
1276  #elif (__cplusplus >= 201103L) && JSON_HEDLEY_GCC_VERSION_CHECK(7,0,0)
1277  #define JSON_HEDLEY_FALL_THROUGH [[gnu::fallthrough]]
1278  #endif
1279 #endif
1280 #if !defined(JSON_HEDLEY_FALL_THROUGH)
1281  #if JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(fallthrough,7,0,0) && !defined(JSON_HEDLEY_PGI_VERSION)
1282  #define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__))
1283  #elif defined(__fallthrough) /* SAL */
1284  #define JSON_HEDLEY_FALL_THROUGH __fallthrough
1285  #else
1286  #define JSON_HEDLEY_FALL_THROUGH
1287  #endif
1288 #endif
1289 
1290 #if defined()
1291  #undef
1292 #endif
1293 #if
1294  JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) ||
1296  #define __attribute__((__returns_nonnull__))
1297 #elif defined(_Ret_notnull_) /* SAL */
1298  #define _Ret_notnull_
1299 #else
1300  #define
1301 #endif
1302 
1303 #if defined(JSON_HEDLEY_ARRAY_PARAM)
1304  #undef JSON_HEDLEY_ARRAY_PARAM
1305 #endif
1306 #if
1307  defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) &&
1308  !defined(__STDC_NO_VLA__) &&
1309  !defined(__cplusplus) &&
1310  !defined(JSON_HEDLEY_PGI_VERSION) &&
1311  !defined(JSON_HEDLEY_TINYC_VERSION)
1312  #define JSON_HEDLEY_ARRAY_PARAM(name) (name)
1313 #else
1314  #define JSON_HEDLEY_ARRAY_PARAM(name)
1315 #endif
1316 
1317 #if defined(JSON_HEDLEY_IS_CONSTANT)
1318  #undef JSON_HEDLEY_IS_CONSTANT
1319 #endif
1320 #if defined(JSON_HEDLEY_REQUIRE_CONSTEXPR)
1321  #undef JSON_HEDLEY_REQUIRE_CONSTEXPR
1322 #endif
1323 /* Note the double-underscore. For internal use only; no API
1324  * guarantees! */
1325 #if defined(JSON_HEDLEY__IS_CONSTEXPR)
1326  #undef JSON_HEDLEY__IS_CONSTEXPR
1327 #endif
1328 
1329 #if
1330  JSON_HEDLEY_HAS_BUILTIN(__builtin_constant_p) ||
1339  #define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr)
1340 #endif
1341 #if !defined(__cplusplus)
1342 # if
1343  JSON_HEDLEY_HAS_BUILTIN(__builtin_types_compatible_p) ||
1344  JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) ||
1345  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) ||
1346  JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) ||
1347  JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) ||
1348  JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) ||
1349  JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,24)
1350 #if defined(__INTPTR_TYPE__)
1351  #define JSON_HEDLEY__IS_CONSTEXPR(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0)), int*)
1352 #else
1353  #include <stdint.h>
1354  #define JSON_HEDLEY__IS_CONSTEXPR(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((intptr_t) ((expr) * 0)) : (int*) 0)), int*)
1355 #endif
1356 # elif
1357  (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && !defined(JSON_HEDLEY_SUNPRO_VERSION) && !defined(JSON_HEDLEY_PGI_VERSION)) ||
1358  JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) ||
1359  JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) ||
1360  JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) ||
1361  JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) ||
1362  JSON_HEDLEY_ARM_VERSION_CHECK(5,3,0)
1363 #if defined(__INTPTR_TYPE__)
1364  #define JSON_HEDLEY__IS_CONSTEXPR(expr) _Generic((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0), int*: 1, void*: 0)
1365 #else
1366  #include <stdint.h>
1367  #define JSON_HEDLEY__IS_CONSTEXPR(expr) _Generic((1 ? (void*) ((intptr_t) * 0) : (int*) 0), int*: 1, void*: 0)
1368 #endif
1369 # elif
1370  defined(JSON_HEDLEY_GCC_VERSION) ||
1371  defined(JSON_HEDLEY_INTEL_VERSION) ||
1372  defined(JSON_HEDLEY_TINYC_VERSION) ||
1373  defined(JSON_HEDLEY_TI_VERSION) ||
1374  defined(__clang__)
1375 # define JSON_HEDLEY__IS_CONSTEXPR(expr) (
1376  sizeof(void) !=
1377  sizeof(*(
1378  1 ?
1379  ((void*) ((expr) * 0L) ) : \
1380 ((struct{ char v[sizeof(void) * 2]; } *) 1)
1381  )
1382  )
1383  )
1384 # endif
1385 #endif
1386 #if defined(JSON_HEDLEY__IS_CONSTEXPR)
1387  #if !defined(JSON_HEDLEY_IS_CONSTANT)
1388  #define JSON_HEDLEY_IS_CONSTANT(expr) JSON_HEDLEY__IS_CONSTEXPR(expr)
1389  #endif
1390  #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (JSON_HEDLEY__IS_CONSTEXPR(expr) ? (expr) : (-1))
1391 #else
1392  #if !defined(JSON_HEDLEY_IS_CONSTANT)
1393  #define JSON_HEDLEY_IS_CONSTANT(expr) (0)
1394  #endif
1395  #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (expr)
1396 #endif
1397 
1398 #if defined(JSON_HEDLEY_BEGIN_C_DECLS)
1399  #undef JSON_HEDLEY_BEGIN_C_DECLS
1400 #endif
1401 #if defined(JSON_HEDLEY_END_C_DECLS)
1402  #undef JSON_HEDLEY_END_C_DECLS
1403 #endif
1404 #if defined(JSON_HEDLEY_C_DECL)
1405  #undef JSON_HEDLEY_C_DECL
1406 #endif
1407 #if defined(__cplusplus)
1408  #define JSON_HEDLEY_BEGIN_C_DECLS extern "C" {
1409  #define JSON_HEDLEY_END_C_DECLS }
1410  #define JSON_HEDLEY_C_DECL extern "C"
1411 #else
1412  #define JSON_HEDLEY_BEGIN_C_DECLS
1413  #define JSON_HEDLEY_END_C_DECLS
1414  #define JSON_HEDLEY_C_DECL
1415 #endif
1416 
1417 #if defined(JSON_HEDLEY_STATIC_ASSERT)
1418  #undef JSON_HEDLEY_STATIC_ASSERT
1419 #endif
1420 #if
1421  !defined(__cplusplus) && (
1422  (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) ||
1423  JSON_HEDLEY_HAS_FEATURE(c_static_assert) ||
1426  defined(_Static_assert)
1427  )
1428 # define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message)
1429 #elif
1430  (defined(__cplusplus) && (__cplusplus >= 201703L)) ||
1432  (defined(__cplusplus) && JSON_HEDLEY_TI_VERSION_CHECK(8,3,0))
1433 # define JSON_HEDLEY_STATIC_ASSERT(expr, message) static_assert(expr, message)
1434 #elif defined(__cplusplus) && (__cplusplus >= 201103L)
1435 # define JSON_HEDLEY_STATIC_ASSERT(expr, message) static_assert(expr)
1436 #else
1437 # define JSON_HEDLEY_STATIC_ASSERT(expr, message)
1438 #endif
1439 
1440 #if defined(JSON_HEDLEY_CONST_CAST)
1441  #undef JSON_HEDLEY_CONST_CAST
1442 #endif
1443 #if defined(__cplusplus)
1444 # define JSON_HEDLEY_CONST_CAST(T, expr) (const_cast<T>(expr))
1445 #elif
1446  JSON_HEDLEY_HAS_WARNING("-Wcast-qual") ||
1447  JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) ||
1448  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1449 # define JSON_HEDLEY_CONST_CAST(T, expr) (__extension__ ({
1450  JSON_HEDLEY_DIAGNOSTIC_PUSH
1451  JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
1452  ((T) (expr));
1453  JSON_HEDLEY_DIAGNOSTIC_POP
1454  }))
1455 #else
1456 # define JSON_HEDLEY_CONST_CAST(T, expr) ((T) (expr))
1457 #endif
1458 
1459 #if defined(JSON_HEDLEY_REINTERPRET_CAST)
1460  #undef JSON_HEDLEY_REINTERPRET_CAST
1461 #endif
1462 #if defined(__cplusplus)
1463  #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (reinterpret_cast<T>(expr))
1464 #else
1465  #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (*((T*) &(expr)))
1466 #endif
1467 
1468 #if defined(JSON_HEDLEY_STATIC_CAST)
1469  #undef JSON_HEDLEY_STATIC_CAST
1470 #endif
1471 #if defined(__cplusplus)
1472  #define JSON_HEDLEY_STATIC_CAST(T, expr) (static_cast<T>(expr))
1473 #else
1474  #define JSON_HEDLEY_STATIC_CAST(T, expr) ((T) (expr))
1475 #endif
1476 
1477 #if defined(JSON_HEDLEY_CPP_CAST)
1478  #undef JSON_HEDLEY_CPP_CAST
1479 #endif
1480 #if defined(__cplusplus)
1481  #define JSON_HEDLEY_CPP_CAST(T, expr) static_cast<T>(expr)
1482 #else
1483  #define JSON_HEDLEY_CPP_CAST(T, expr) (expr)
1484 #endif
1485 
1486 #if defined(JSON_HEDLEY_MESSAGE)
1487  #undef JSON_HEDLEY_MESSAGE
1488 #endif
1489 #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
1490 # define JSON_HEDLEY_MESSAGE(msg)
1491  JSON_HEDLEY_DIAGNOSTIC_PUSH
1492  JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
1493  JSON_HEDLEY_PRAGMA(message msg)
1494  JSON_HEDLEY_DIAGNOSTIC_POP
1495 #elif
1496  JSON_HEDLEY_GCC_VERSION_CHECK(4,4,0) ||
1497  JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1498 # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message msg)
1499 #elif JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0)
1500 # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(_CRI message msg)
1501 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1502 # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
1503 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,0,0)
1504 # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
1505 #else
1506 # define JSON_HEDLEY_MESSAGE(msg)
1507 #endif
1508 
1509 #if defined(JSON_HEDLEY_WARNING)
1510  #undef JSON_HEDLEY_WARNING
1511 #endif
1512 #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
1513 # define JSON_HEDLEY_WARNING(msg)
1514  JSON_HEDLEY_DIAGNOSTIC_PUSH
1515  JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
1516  JSON_HEDLEY_PRAGMA(clang warning msg)
1517  JSON_HEDLEY_DIAGNOSTIC_POP
1518 #elif
1519  JSON_HEDLEY_GCC_VERSION_CHECK(4,8,0) ||
1520  JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0)
1521 # define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg)
1522 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
1523 # define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg))
1524 #else
1525 # define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_MESSAGE(msg)
1526 #endif
1527 
1528 #if defined(JSON_HEDLEY_REQUIRE_MSG)
1529  #undef JSON_HEDLEY_REQUIRE_MSG
1530 #endif
1531 #if JSON_HEDLEY_HAS_ATTRIBUTE(diagnose_if)
1532 # if JSON_HEDLEY_HAS_WARNING("-Wgcc-compat")
1533 # define JSON_HEDLEY_REQUIRE_MSG(expr, msg)
1534  JSON_HEDLEY_DIAGNOSTIC_PUSH
1535  _Pragma("clang diagnostic ignored \"-Wgcc-compat\"")
1536  __attribute__((__diagnose_if__(!(expr), msg, "error")))
1537  JSON_HEDLEY_DIAGNOSTIC_POP
1538 # else
1539 # define JSON_HEDLEY_REQUIRE_MSG(expr, msg) __attribute__((__diagnose_if__(!(expr), msg, "error")))
1540 # endif
1541 #else
1542 # define JSON_HEDLEY_REQUIRE_MSG(expr, msg)
1543 #endif
1544 
1545 #if defined(JSON_HEDLEY_REQUIRE)
1546  #undef JSON_HEDLEY_REQUIRE
1547 #endif
1548 #define JSON_HEDLEY_REQUIRE(expr) JSON_HEDLEY_REQUIRE_MSG(expr, #expr)
1549 
1550 #if defined(JSON_HEDLEY_FLAGS)
1551  #undef JSON_HEDLEY_FLAGS
1552 #endif
1553 #if JSON_HEDLEY_HAS_ATTRIBUTE(flag_enum)
1554  #define JSON_HEDLEY_FLAGS __attribute__((__flag_enum__))
1555 #endif
1556 
1557 #if defined(JSON_HEDLEY_FLAGS_CAST)
1558  #undef JSON_HEDLEY_FLAGS_CAST
1559 #endif
1561 # define JSON_HEDLEY_FLAGS_CAST(T, expr) (__extension__ ({
1562  JSON_HEDLEY_DIAGNOSTIC_PUSH
1563  _Pragma("warning(disable:188)")
1564  ((T) (expr));
1565  JSON_HEDLEY_DIAGNOSTIC_POP
1566  }))
1567 #else
1568 # define JSON_HEDLEY_FLAGS_CAST(T, expr) JSON_HEDLEY_STATIC_CAST(T, expr)
1569 #endif
1570 
1571 /* Remaining macros are deprecated. */
1572 
1573 #if defined(JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK)
1574  #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
1575 #endif
1576 #if defined(__clang__)
1577  #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) (0)
1578 #else
1579  #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
1580 #endif
1581 
1582 #if defined(JSON_HEDLEY_CLANG_HAS_ATTRIBUTE)
1583  #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
1584 #endif
1585 #define JSON_HEDLEY_CLANG_HAS_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
1586 
1587 #if defined(JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE)
1588  #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
1589 #endif
1590 #define JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute)
1591 
1592 #if defined(JSON_HEDLEY_CLANG_HAS_BUILTIN)
1593  #undef JSON_HEDLEY_CLANG_HAS_BUILTIN
1594 #endif
1595 #define JSON_HEDLEY_CLANG_HAS_BUILTIN(builtin) JSON_HEDLEY_HAS_BUILTIN(builtin)
1596 
1597 #if defined(JSON_HEDLEY_CLANG_HAS_FEATURE)
1598  #undef JSON_HEDLEY_CLANG_HAS_FEATURE
1599 #endif
1600 #define JSON_HEDLEY_CLANG_HAS_FEATURE(feature) JSON_HEDLEY_HAS_FEATURE(feature)
1601 
1602 #if defined(JSON_HEDLEY_CLANG_HAS_EXTENSION)
1603  #undef JSON_HEDLEY_CLANG_HAS_EXTENSION
1604 #endif
1605 #define JSON_HEDLEY_CLANG_HAS_EXTENSION(extension) JSON_HEDLEY_HAS_EXTENSION(extension)
1606 
1607 #if defined(JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE)
1608  #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
1609 #endif
1610 #define JSON_HEDLEY_CLANG_HAS_DECLSPEC_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute)
1611 
1612 #if defined(JSON_HEDLEY_CLANG_HAS_WARNING)
1613  #undef JSON_HEDLEY_CLANG_HAS_WARNING
1614 #endif
1615 #define JSON_HEDLEY_CLANG_HAS_WARNING(warning) JSON_HEDLEY_HAS_WARNING(warning)
1616 
1617 #endif /* !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < X) */
1618 
1619 
1620 // This file contains all internal macro definitions
1621 // You MUST include macro_unscope.hpp at the end of json.hpp to undef all of them
1622 
1623 // exclude unsupported compilers
1624 #if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK)
1625  #if defined(__clang__)
1626  #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400
1627  #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers"
1628  #endif
1629  #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER))
1630  #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800
1631  #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers"
1632  #endif
1633  #endif
1634 #endif
1635 
1636 // C++ language standard detection
1637 #if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464
1638  #define JSON_HAS_CPP_17
1639  #define JSON_HAS_CPP_14
1640 #elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
1641  #define JSON_HAS_CPP_14
1642 #endif
1643 
1644 // disable float-equal warnings on GCC/clang
1645 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
1646  #pragma GCC diagnostic push
1647  #pragma GCC diagnostic ignored "-Wfloat-equal"
1648 #endif
1649 
1650 // disable documentation warnings on clang
1651 #if defined(__clang__)
1652  #pragma GCC diagnostic push
1653  #pragma GCC diagnostic ignored "-Wdocumentation"
1654 #endif
1655 
1656 // allow to disable exceptions
1657 #if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
1658  #define JSON_THROW(exception) throw exception
1659  #define JSON_TRY try
1660  #define JSON_CATCH(exception) catch(exception)
1661  #define JSON_INTERNAL_CATCH(exception) catch(exception)
1662 #else
1663  #include <cstdlib>
1664  #define JSON_THROW(exception) std::abort()
1665  #define JSON_TRY if(true)
1666  #define JSON_CATCH(exception) if(false)
1667  #define JSON_INTERNAL_CATCH(exception) if(false)
1668 #endif
1669 
1670 // override exception macros
1671 #if defined(JSON_THROW_USER)
1672  #undef JSON_THROW
1673  #define JSON_THROW JSON_THROW_USER
1674 #endif
1675 #if defined(JSON_TRY_USER)
1676  #undef JSON_TRY
1677  #define JSON_TRY JSON_TRY_USER
1678 #endif
1679 #if defined(JSON_CATCH_USER)
1680  #undef JSON_CATCH
1681  #define JSON_CATCH JSON_CATCH_USER
1682  #undef JSON_INTERNAL_CATCH
1683  #define JSON_INTERNAL_CATCH JSON_CATCH_USER
1684 #endif
1685 #if defined(JSON_INTERNAL_CATCH_USER)
1686  #undef JSON_INTERNAL_CATCH
1687  #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER
1688 #endif
1689 
1690 /*!
1691 @brief macro to briefly define a mapping between an enum and JSON
1692 @def NLOHMANN_JSON_SERIALIZE_ENUM
1693 @since version 3.4.0
1694 */
1695 #define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...)
1696  template<typename BasicJsonType>
1697  inline void to_json(BasicJsonType& j, const ENUM_TYPE& e)
1698  {
1699  static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!");
1700  static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__;
1701  auto it = std::find_if(std::begin(m), std::end(m),
1702  [e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool
1703  {
1704  return ej_pair.first == e;
1705  });
1706  j = ((it != std::end(m)) ? it : std::begin(m))->second;
1707  }
1708  template<typename BasicJsonType>
1709  inline void from_json(const BasicJsonType& j, ENUM_TYPE& e)
1710  {
1711  static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!");
1712  static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__;
1713  auto it = std::find_if(std::begin(m), std::end(m),
1714  [j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool
1715  {
1716  return ej_pair.second == j;
1717  });
1718  e = ((it != std::end(m)) ? it : std::begin(m))->first;
1719  }
1720 
1721 // Ugly macros to avoid uglier copy-paste when specializing basic_json. They
1722 // may be removed in the future once the class is split.
1723 
1724 #define NLOHMANN_BASIC_JSON_TPL_DECLARATION
1725  template<template<typename, typename, typename...> class ObjectType,
1726  template<typename, typename...> class ArrayType,
1727  class StringType, class BooleanType, class NumberIntegerType,
1728  class NumberUnsignedType, class NumberFloatType,
1729  template<typename> class AllocatorType,
1730  template<typename, typename = void> class JSONSerializer>
1731 
1732 #define NLOHMANN_BASIC_JSON_TPL
1733  basic_json<ObjectType, ArrayType, StringType, BooleanType,
1734  NumberIntegerType, NumberUnsignedType, NumberFloatType,
1735  AllocatorType, JSONSerializer>
1736 
1737 
1738 namespace nlohmann
1739 {
1740 namespace detail
1741 {
1742 ////////////////
1743 // exceptions //
1744 ////////////////
1745 
1746 /*!
1747 @brief general exception of the @ref basic_json class
1748 
1749 This class is an extension of `std::exception` objects with a member @a id for
1750 exception ids. It is used as the base class for all exceptions thrown by the
1751 @ref basic_json class. This class can hence be used as "wildcard" to catch
1752 exceptions.
1753 
1754 Subclasses:
1755 - @ref parse_error for exceptions indicating a parse error
1756 - @ref invalid_iterator for exceptions indicating errors with iterators
1757 - @ref type_error for exceptions indicating executing a member function with
1758  a wrong type
1759 - @ref out_of_range for exceptions indicating access out of the defined range
1760 - @ref other_error for exceptions indicating other library errors
1761 
1762 @internal
1763 @note To have nothrow-copy-constructible exceptions, we internally use
1764  `std::runtime_error` which can cope with arbitrary-length error messages.
1765  Intermediate strings are built with static functions and then passed to
1766  the actual constructor.
1767 @endinternal
1768 
1769 @liveexample{The following code shows how arbitrary library exceptions can be
1770 caught.,exception}
1771 
1772 @since version 3.0.0
1773 */
1774 class exception : public std::exception
1775 {
1776  public:
1777  /// returns the explanatory string
1778 
1779  const char* what() const noexcept override
1780  {
1781  return m.what();
1782  }
1783 
1784  /// the id of the exception
1785  const int id;
1786 
1787  protected:
1789  exception(int id_, const char* what_arg) : id(id_), m(what_arg) {}
1790 
1791  static std::string name(const std::string& ename, int id_)
1792  {
1793  return "[json.exception." + ename + "." + std::to_string(id_) + "] ";
1794  }
1795 
1796  private:
1797  /// an exception object as storage for error messages
1798  std::runtime_error m;
1799 };
1800 
1801 /*!
1802 @brief exception indicating a parse error
1803 
1804 This exception is thrown by the library when a parse error occurs. Parse errors
1805 can occur during the deserialization of JSON text, CBOR, MessagePack, as well
1806 as when using JSON Patch.
1807 
1808 Member @a byte holds the byte index of the last read character in the input
1809 file.
1810 
1811 Exceptions have ids 1xx.
1812 
1813 name / id | example message | description
1814 ------------------------------ | --------------- | -------------------------
1815 json.exception.parse_error.101 | parse error at 2: unexpected end of input; expected string literal | This error indicates a syntax error while deserializing a JSON text. The error message describes that an unexpected token (character) was encountered, and the member @a byte indicates the error position.
1816 json.exception.parse_error.102 | parse error at 14: missing or wrong low surrogate | JSON uses the `\uxxxx` format to describe Unicode characters. Code points above above 0xFFFF are split into two `\uxxxx` entries ("surrogate pairs"). This error indicates that the surrogate pair is incomplete or contains an invalid code point.
1817 json.exception.parse_error.103 | parse error: code points above 0x10FFFF are invalid | Unicode supports code points up to 0x10FFFF. Code points above 0x10FFFF are invalid.
1818 json.exception.parse_error.104 | parse error: JSON patch must be an array of objects | [RFC 6902](https://tools.ietf.org/html/rfc6902) requires a JSON Patch document to be a JSON document that represents an array of objects.
1819 json.exception.parse_error.105 | parse error: operation must have string member 'op' | An operation of a JSON Patch document must contain exactly one "op" member, whose value indicates the operation to perform. Its value must be one of "add", "remove", "replace", "move", "copy", or "test"; other values are errors.
1820 json.exception.parse_error.106 | parse error: array index '01' must not begin with '0' | An array index in a JSON Pointer ([RFC 6901](https://tools.ietf.org/html/rfc6901)) may be `0` or any number without a leading `0`.
1821 json.exception.parse_error.107 | parse error: JSON pointer must be empty or begin with '/' - was: 'foo' | A JSON Pointer must be a Unicode string containing a sequence of zero or more reference tokens, each prefixed by a `/` character.
1822 json.exception.parse_error.108 | parse error: escape character '~' must be followed with '0' or '1' | In a JSON Pointer, only `~0` and `~1` are valid escape sequences.
1823 json.exception.parse_error.109 | parse error: array index 'one' is not a number | A JSON Pointer array index must be a number.
1824 json.exception.parse_error.110 | parse error at 1: cannot read 2 bytes from vector | When parsing CBOR or MessagePack, the byte vector ends before the complete value has been read.
1825 json.exception.parse_error.112 | parse error at 1: error reading CBOR; last byte: 0xF8 | Not all types of CBOR or MessagePack are supported. This exception occurs if an unsupported byte was read.
1826 json.exception.parse_error.113 | parse error at 2: expected a CBOR string; last byte: 0x98 | While parsing a map key, a value that is not a string has been read.
1827 json.exception.parse_error.114 | parse error: Unsupported BSON record type 0x0F | The parsing of the corresponding BSON record type is not implemented (yet).
1828 
1829 @note For an input with n bytes, 1 is the index of the first character and n+1
1830  is the index of the terminating null byte or the end of file. This also
1831  holds true when reading a byte vector (CBOR or MessagePack).
1832 
1833 @liveexample{The following code shows how a `parse_error` exception can be
1834 caught.,parse_error}
1835 
1836 @sa - @ref exception for the base class of the library exceptions
1837 @sa - @ref invalid_iterator for exceptions indicating errors with iterators
1838 @sa - @ref type_error for exceptions indicating executing a member function with
1839  a wrong type
1840 @sa - @ref out_of_range for exceptions indicating access out of the defined range
1841 @sa - @ref other_error for exceptions indicating other library errors
1842 
1843 @since version 3.0.0
1844 */
1845 class parse_error : public exception
1846 {
1847  public:
1848  /*!
1849  @brief create a parse error exception
1850  @param[in] id_ the id of the exception
1851  @param[in] pos the position where the error occurred (or with
1852  chars_read_total=0 if the position cannot be
1853  determined)
1854  @param[in] what_arg the explanatory string
1855  @return parse_error object
1856  */
1857  static parse_error create(int id_, const position_t& pos, const std::string& what_arg)
1858  {
1859  std::string w = exception::name("parse_error", id_) + "parse error" +
1860  position_string(pos) + ": " + what_arg;
1861  return parse_error(id_, pos.chars_read_total, w.c_str());
1862  }
1863 
1864  static parse_error create(int id_, std::size_t byte_, const std::string& what_arg)
1865  {
1866  std::string w = exception::name("parse_error", id_) + "parse error" +
1867  (byte_ != 0 ? (" at byte " + std::to_string(byte_)) : "") +
1868  ": " + what_arg;
1869  return parse_error(id_, byte_, w.c_str());
1870  }
1871 
1872  /*!
1873  @brief byte index of the parse error
1874 
1875  The byte index of the last read character in the input file.
1876 
1877  @note For an input with n bytes, 1 is the index of the first character and
1878  n+1 is the index of the terminating null byte or the end of file.
1879  This also holds true when reading a byte vector (CBOR or MessagePack).
1880  */
1881  const std::size_t byte;
1882 
1883  private:
1884  parse_error(int id_, std::size_t byte_, const char* what_arg)
1885  : exception(id_, what_arg), byte(byte_) {}
1886 
1887  static std::string position_string(const position_t& pos)
1888  {
1889  return " at line " + std::to_string(pos.lines_read + 1) +
1890  ", column " + std::to_string(pos.chars_read_current_line);
1891  }
1892 };
1893 
1894 /*!
1895 @brief exception indicating errors with iterators
1896 
1897 This exception is thrown if iterators passed to a library function do not match
1898 the expected semantics.
1899 
1900 Exceptions have ids 2xx.
1901 
1902 name / id | example message | description
1903 ----------------------------------- | --------------- | -------------------------
1904 json.exception.invalid_iterator.201 | iterators are not compatible | The iterators passed to constructor @ref basic_json(InputIT first, InputIT last) are not compatible, meaning they do not belong to the same container. Therefore, the range (@a first, @a last) is invalid.
1905 json.exception.invalid_iterator.202 | iterator does not fit current value | In an erase or insert function, the passed iterator @a pos does not belong to the JSON value for which the function was called. It hence does not define a valid position for the deletion/insertion.
1906 json.exception.invalid_iterator.203 | iterators do not fit current value | Either iterator passed to function @ref erase(IteratorType first, IteratorType last) does not belong to the JSON value from which values shall be erased. It hence does not define a valid range to delete values from.
1907 json.exception.invalid_iterator.204 | iterators out of range | When an iterator range for a primitive type (number, boolean, or string) is passed to a constructor or an erase function, this range has to be exactly (@ref begin(), @ref end()), because this is the only way the single stored value is expressed. All other ranges are invalid.
1908 json.exception.invalid_iterator.205 | iterator out of range | When an iterator for a primitive type (number, boolean, or string) is passed to an erase function, the iterator has to be the @ref begin() iterator, because it is the only way to address the stored value. All other iterators are invalid.
1909 json.exception.invalid_iterator.206 | cannot construct with iterators from null | The iterators passed to constructor @ref basic_json(InputIT first, InputIT last) belong to a JSON null value and hence to not define a valid range.
1910 json.exception.invalid_iterator.207 | cannot use key() for non-object iterators | The key() member function can only be used on iterators belonging to a JSON object, because other types do not have a concept of a key.
1911 json.exception.invalid_iterator.208 | cannot use operator[] for object iterators | The operator[] to specify a concrete offset cannot be used on iterators belonging to a JSON object, because JSON objects are unordered.
1912 json.exception.invalid_iterator.209 | cannot use offsets with object iterators | The offset operators (+, -, +=, -=) cannot be used on iterators belonging to a JSON object, because JSON objects are unordered.
1913 json.exception.invalid_iterator.210 | iterators do not fit | The iterator range passed to the insert function are not compatible, meaning they do not belong to the same container. Therefore, the range (@a first, @a last) is invalid.
1914 json.exception.invalid_iterator.211 | passed iterators may not belong to container | The iterator range passed to the insert function must not be a subrange of the container to insert to.
1915 json.exception.invalid_iterator.212 | cannot compare iterators of different containers | When two iterators are compared, they must belong to the same container.
1916 json.exception.invalid_iterator.213 | cannot compare order of object iterators | The order of object iterators cannot be compared, because JSON objects are unordered.
1917 json.exception.invalid_iterator.214 | cannot get value | Cannot get value for iterator: Either the iterator belongs to a null value or it is an iterator to a primitive type (number, boolean, or string), but the iterator is different to @ref begin().
1918 
1919 @liveexample{The following code shows how an `invalid_iterator` exception can be
1920 caught.,invalid_iterator}
1921 
1922 @sa - @ref exception for the base class of the library exceptions
1923 @sa - @ref parse_error for exceptions indicating a parse error
1924 @sa - @ref type_error for exceptions indicating executing a member function with
1925  a wrong type
1926 @sa - @ref out_of_range for exceptions indicating access out of the defined range
1927 @sa - @ref other_error for exceptions indicating other library errors
1928 
1929 @since version 3.0.0
1930 */
1931 class invalid_iterator : public exception
1932 {
1933  public:
1934  static invalid_iterator create(int id_, const std::string& what_arg)
1935  {
1936  std::string w = exception::name("invalid_iterator", id_) + what_arg;
1937  return invalid_iterator(id_, w.c_str());
1938  }
1939 
1940  private:
1942  invalid_iterator(int id_, const char* what_arg)
1943  : exception(id_, what_arg) {}
1944 };
1945 
1946 /*!
1947 @brief exception indicating executing a member function with a wrong type
1948 
1949 This exception is thrown in case of a type error; that is, a library function is
1950 executed on a JSON value whose type does not match the expected semantics.
1951 
1952 Exceptions have ids 3xx.
1953 
1954 name / id | example message | description
1955 ----------------------------- | --------------- | -------------------------
1956 json.exception.type_error.301 | cannot create object from initializer list | To create an object from an initializer list, the initializer list must consist only of a list of pairs whose first element is a string. When this constraint is violated, an array is created instead.
1957 json.exception.type_error.302 | type must be object, but is array | During implicit or explicit value conversion, the JSON type must be compatible to the target type. For instance, a JSON string can only be converted into string types, but not into numbers or boolean types.
1958 json.exception.type_error.303 | incompatible ReferenceType for get_ref, actual type is object | To retrieve a reference to a value stored in a @ref basic_json object with @ref get_ref, the type of the reference must match the value type. For instance, for a JSON array, the @a ReferenceType must be @ref array_t &.
1959 json.exception.type_error.304 | cannot use at() with string | The @ref at() member functions can only be executed for certain JSON types.
1960 json.exception.type_error.305 | cannot use operator[] with string | The @ref operator[] member functions can only be executed for certain JSON types.
1961 json.exception.type_error.306 | cannot use value() with string | The @ref value() member functions can only be executed for certain JSON types.
1962 json.exception.type_error.307 | cannot use erase() with string | The @ref erase() member functions can only be executed for certain JSON types.
1963 json.exception.type_error.308 | cannot use push_back() with string | The @ref push_back() and @ref operator+= member functions can only be executed for certain JSON types.
1964 json.exception.type_error.309 | cannot use insert() with | The @ref insert() member functions can only be executed for certain JSON types.
1965 json.exception.type_error.310 | cannot use swap() with number | The @ref swap() member functions can only be executed for certain JSON types.
1966 json.exception.type_error.311 | cannot use emplace_back() with string | The @ref emplace_back() member function can only be executed for certain JSON types.
1967 json.exception.type_error.312 | cannot use update() with string | The @ref update() member functions can only be executed for certain JSON types.
1968 json.exception.type_error.313 | invalid value to unflatten | The @ref unflatten function converts an object whose keys are JSON Pointers back into an arbitrary nested JSON value. The JSON Pointers must not overlap, because then the resulting value would not be well defined.
1969 json.exception.type_error.314 | only objects can be unflattened | The @ref unflatten function only works for an object whose keys are JSON Pointers.
1970 json.exception.type_error.315 | values in object must be primitive | The @ref unflatten function only works for an object whose keys are JSON Pointers and whose values are primitive.
1971 json.exception.type_error.316 | invalid UTF-8 byte at index 10: 0x7E | The @ref dump function only works with UTF-8 encoded strings; that is, if you assign a `std::string` to a JSON value, make sure it is UTF-8 encoded. |
1972 json.exception.type_error.317 | JSON value cannot be serialized to requested format | The dynamic type of the object cannot be represented in the requested serialization format (e.g. a raw `true` or `null` JSON object cannot be serialized to BSON) |
1973 
1974 @liveexample{The following code shows how a `type_error` exception can be
1975 caught.,type_error}
1976 
1977 @sa - @ref exception for the base class of the library exceptions
1978 @sa - @ref parse_error for exceptions indicating a parse error
1979 @sa - @ref invalid_iterator for exceptions indicating errors with iterators
1980 @sa - @ref out_of_range for exceptions indicating access out of the defined range
1981 @sa - @ref other_error for exceptions indicating other library errors
1982 
1983 @since version 3.0.0
1984 */
1985 class type_error : public exception
1986 {
1987  public:
1988  static type_error create(int id_, const std::string& what_arg)
1989  {
1990  std::string w = exception::name("type_error", id_) + what_arg;
1991  return type_error(id_, w.c_str());
1992  }
1993 
1994  private:
1996  type_error(int id_, const char* what_arg) : exception(id_, what_arg) {}
1997 };
1998 
1999 /*!
2000 @brief exception indicating access out of the defined range
2001 
2002 This exception is thrown in case a library function is called on an input
2003 parameter that exceeds the expected range, for instance in case of array
2004 indices or nonexisting object keys.
2005 
2006 Exceptions have ids 4xx.
2007 
2008 name / id | example message | description
2009 ------------------------------- | --------------- | -------------------------
2010 json.exception.out_of_range.401 | array index 3 is out of range | The provided array index @a i is larger than @a size-1.
2011 json.exception.out_of_range.402 | array index '-' (3) is out of range | The special array index `-` in a JSON Pointer never describes a valid element of the array, but the index past the end. That is, it can only be used to add elements at this position, but not to read it.
2012 json.exception.out_of_range.403 | key 'foo' not found | The provided key was not found in the JSON object.
2013 json.exception.out_of_range.404 | unresolved reference token 'foo' | A reference token in a JSON Pointer could not be resolved.
2014 json.exception.out_of_range.405 | JSON pointer has no parent | The JSON Patch operations 'remove' and 'add' can not be applied to the root element of the JSON value.
2015 json.exception.out_of_range.406 | number overflow parsing '10E1000' | A parsed number could not be stored as without changing it to NaN or INF.
2016 json.exception.out_of_range.407 | number overflow serializing '9223372036854775808' | UBJSON and BSON only support integer numbers up to 9223372036854775807. |
2017 json.exception.out_of_range.408 | excessive array size: 8658170730974374167 | The size (following `#`) of an UBJSON array or object exceeds the maximal capacity. |
2018 json.exception.out_of_range.409 | BSON key cannot contain code point U+0000 (at byte 2) | Key identifiers to be serialized to BSON cannot contain code point U+0000, since the key is stored as zero-terminated c-string |
2019 
2020 @liveexample{The following code shows how an `out_of_range` exception can be
2021 caught.,out_of_range}
2022 
2023 @sa - @ref exception for the base class of the library exceptions
2024 @sa - @ref parse_error for exceptions indicating a parse error
2025 @sa - @ref invalid_iterator for exceptions indicating errors with iterators
2026 @sa - @ref type_error for exceptions indicating executing a member function with
2027  a wrong type
2028 @sa - @ref other_error for exceptions indicating other library errors
2029 
2030 @since version 3.0.0
2031 */
2032 class out_of_range : public exception
2033 {
2034  public:
2035  static out_of_range create(int id_, const std::string& what_arg)
2036  {
2037  std::string w = exception::name("out_of_range", id_) + what_arg;
2038  return out_of_range(id_, w.c_str());
2039  }
2040 
2041  private:
2043  out_of_range(int id_, const char* what_arg) : exception(id_, what_arg) {}
2044 };
2045 
2046 /*!
2047 @brief exception indicating other library errors
2048 
2049 This exception is thrown in case of errors that cannot be classified with the
2050 other exception types.
2051 
2052 Exceptions have ids 5xx.
2053 
2054 name / id | example message | description
2055 ------------------------------ | --------------- | -------------------------
2056 json.exception.other_error.501 | unsuccessful: {"op":"test","path":"/baz", "value":"bar"} | A JSON Patch operation 'test' failed. The unsuccessful operation is also printed.
2057 
2058 @sa - @ref exception for the base class of the library exceptions
2059 @sa - @ref parse_error for exceptions indicating a parse error
2060 @sa - @ref invalid_iterator for exceptions indicating errors with iterators
2061 @sa - @ref type_error for exceptions indicating executing a member function with
2062  a wrong type
2063 @sa - @ref out_of_range for exceptions indicating access out of the defined range
2064 
2065 @liveexample{The following code shows how an `other_error` exception can be
2066 caught.,other_error}
2067 
2068 @since version 3.0.0
2069 */
2070 class other_error : public exception
2071 {
2072  public:
2073  static other_error create(int id_, const std::string& what_arg)
2074  {
2075  std::string w = exception::name("other_error", id_) + what_arg;
2076  return other_error(id_, w.c_str());
2077  }
2078 
2079  private:
2081  other_error(int id_, const char* what_arg) : exception(id_, what_arg) {}
2082 };
2083 } // namespace detail
2084 } // namespace nlohmann
2085 
2086 // #include <nlohmann/detail/macro_scope.hpp>
2087 
2088 // #include <nlohmann/detail/meta/cpp_future.hpp>
2089 
2090 
2091 #include <ciso646> // not
2092 #include <cstddef> // size_t
2093 #include <type_traits> // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type
2094 
2095 namespace nlohmann
2096 {
2097 namespace detail
2098 {
2099 // alias templates to reduce boilerplate
2100 template<bool B, typename T = void>
2101 using enable_if_t = typename std::enable_if<B, T>::type;
2102 
2103 template<typename T>
2104 using uncvref_t = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
2105 
2106 // implementation of C++14 index_sequence and affiliates
2107 // source: https://stackoverflow.com/a/32223343
2108 template<std::size_t... Ints>
2109 struct index_sequence
2110 {
2111  using type = index_sequence;
2112  using value_type = std::size_t;
2113  static constexpr std::size_t size() noexcept
2114  {
2115  return sizeof...(Ints);
2116  }
2117 };
2118 
2119 template<class Sequence1, class Sequence2>
2120 struct merge_and_renumber;
2121 
2122 template<std::size_t... I1, std::size_t... I2>
2123 struct merge_and_renumber<index_sequence<I1...>, index_sequence<I2...>>
2124  : index_sequence < I1..., (sizeof...(I1) + I2)... > {};
2125 
2126 template<std::size_t N>
2127 struct make_index_sequence
2128  : merge_and_renumber < typename make_index_sequence < N / 2 >::type,
2129  typename make_index_sequence < N - N / 2 >::type > {};
2130 
2131 template<> struct make_index_sequence<0> : index_sequence<> {};
2132 template<> struct make_index_sequence<1> : index_sequence<0> {};
2133 
2134 template<typename... Ts>
2135 using index_sequence_for = make_index_sequence<sizeof...(Ts)>;
2136 
2137 // dispatch utility (taken from ranges-v3)
2138 template<unsigned N> struct priority_tag : priority_tag < N - 1 > {};
2139 template<> struct priority_tag<0> {};
2140 
2141 // taken from ranges-v3
2142 template<typename T>
2143 struct static_const
2144 {
2145  static constexpr T value{};
2146 };
2147 
2148 template<typename T>
2149 constexpr T static_const<T>::value;
2150 } // namespace detail
2151 } // namespace nlohmann
2152 
2153 // #include <nlohmann/detail/meta/type_traits.hpp>
2154 
2155 
2156 #include <ciso646> // not
2157 #include <limits> // numeric_limits
2158 #include <type_traits> // false_type, is_constructible, is_integral, is_same, true_type
2159 #include <utility> // declval
2160 
2161 // #include <nlohmann/detail/iterators/iterator_traits.hpp>
2162 
2163 
2164 #include <iterator> // random_access_iterator_tag
2165 
2166 // #include <nlohmann/detail/meta/void_t.hpp>
2167 
2168 
2169 namespace nlohmann
2170 {
2171 namespace detail
2172 {
2173 template <typename ...Ts> struct make_void
2174 {
2175  using type = void;
2176 };
2177 template <typename ...Ts> using void_t = typename make_void<Ts...>::type;
2178 } // namespace detail
2179 } // namespace nlohmann
2180 
2181 // #include <nlohmann/detail/meta/cpp_future.hpp>
2182 
2183 
2184 namespace nlohmann
2185 {
2186 namespace detail
2187 {
2188 template <typename It, typename = void>
2189 struct iterator_types {};
2190 
2191 template <typename It>
2192 struct iterator_types <
2193  It,
2194  void_t<typename It::difference_type, typename It::value_type, typename It::pointer,
2195  typename It::reference, typename It::iterator_category >>
2196 {
2197  using difference_type = typename It::difference_type;
2198  using value_type = typename It::value_type;
2199  using pointer = typename It::pointer;
2200  using reference = typename It::reference;
2201  using iterator_category = typename It::iterator_category;
2202 };
2203 
2204 // This is required as some compilers implement std::iterator_traits in a way that
2205 // doesn't work with SFINAE. See https://github.com/nlohmann/json/issues/1341.
2206 template <typename T, typename = void>
2207 struct iterator_traits
2208 {
2209 };
2210 
2211 template <typename T>
2212 struct iterator_traits < T, enable_if_t < !std::is_pointer<T>::value >>
2213  : iterator_types<T>
2214 {
2215 };
2216 
2217 template <typename T>
2218 struct iterator_traits<T*, enable_if_t<std::is_object<T>::value>>
2219 {
2220  using iterator_category = std::random_access_iterator_tag;
2221  using value_type = T;
2222  using difference_type = ptrdiff_t;
2223  using pointer = T*;
2224  using reference = T&;
2225 };
2226 } // namespace detail
2227 } // namespace nlohmann
2228 
2229 // #include <nlohmann/detail/macro_scope.hpp>
2230 
2231 // #include <nlohmann/detail/meta/cpp_future.hpp>
2232 
2233 // #include <nlohmann/detail/meta/detected.hpp>
2234 
2235 
2236 #include <type_traits>
2237 
2238 // #include <nlohmann/detail/meta/void_t.hpp>
2239 
2240 
2241 // http://en.cppreference.com/w/cpp/experimental/is_detected
2242 namespace nlohmann
2243 {
2244 namespace detail
2245 {
2246 struct nonesuch
2247 {
2248  nonesuch() = delete;
2249  ~nonesuch() = delete;
2250  nonesuch(nonesuch const&) = delete;
2251  nonesuch(nonesuch const&&) = delete;
2252  void operator=(nonesuch const&) = delete;
2253  void operator=(nonesuch&&) = delete;
2254 };
2255 
2256 template <class Default,
2257  class AlwaysVoid,
2258  template <class...> class Op,
2259  class... Args>
2260 struct detector
2261 {
2262  using value_t = std::false_type;
2263  using type = Default;
2264 };
2265 
2266 template <class Default, template <class...> class Op, class... Args>
2267 struct detector<Default, void_t<Op<Args...>>, Op, Args...>
2268 {
2269  using value_t = std::true_type;
2270  using type = Op<Args...>;
2271 };
2272 
2273 template <template <class...> class Op, class... Args>
2274 using is_detected = typename detector<nonesuch, void, Op, Args...>::value_t;
2275 
2276 template <template <class...> class Op, class... Args>
2277 using detected_t = typename detector<nonesuch, void, Op, Args...>::type;
2278 
2279 template <class Default, template <class...> class Op, class... Args>
2280 using detected_or = detector<Default, void, Op, Args...>;
2281 
2282 template <class Default, template <class...> class Op, class... Args>
2283 using detected_or_t = typename detected_or<Default, Op, Args...>::type;
2284 
2285 template <class Expected, template <class...> class Op, class... Args>
2286 using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>;
2287 
2288 template <class To, template <class...> class Op, class... Args>
2289 using is_detected_convertible =
2290  std::is_convertible<detected_t<Op, Args...>, To>;
2291 } // namespace detail
2292 } // namespace nlohmann
2293 
2294 // #include <nlohmann/json_fwd.hpp>
2295 #ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_
2296 #define INCLUDE_NLOHMANN_JSON_FWD_HPP_
2297 
2298 #include <cstdint> // int64_t, uint64_t
2299 #include <map> // map
2300 #include <memory> // allocator
2301 #include <string> // string
2302 #include <vector> // vector
2303 
2304 /*!
2305 @brief namespace for Niels Lohmann
2306 @see https://github.com/nlohmann
2307 @since version 1.0.0
2308 */
2309 namespace nlohmann
2310 {
2311 /*!
2312 @brief default JSONSerializer template argument
2313 
2314 This serializer ignores the template arguments and uses ADL
2315 ([argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl))
2316 for serialization.
2317 */
2318 template<typename T = void, typename SFINAE = void>
2319 struct adl_serializer;
2320 
2321 template<template<typename U, typename V, typename... Args> class ObjectType =
2322  std::map,
2323  template<typename U, typename... Args> class ArrayType = std::vector,
2324  class StringType = std::string, class BooleanType = bool,
2325  class NumberIntegerType = std::int64_t,
2326  class NumberUnsignedType = std::uint64_t,
2327  class NumberFloatType = double,
2328  template<typename U> class AllocatorType = std::allocator,
2329  template<typename T, typename SFINAE = void> class JSONSerializer =
2332 
2333 /*!
2334 @brief JSON Pointer
2335 
2336 A JSON pointer defines a string syntax for identifying a specific value
2337 within a JSON document. It can be used with functions `at` and
2338 `operator[]`. Furthermore, JSON pointers are the base for JSON patches.
2339 
2340 @sa [RFC 6901](https://tools.ietf.org/html/rfc6901)
2341 
2342 @since version 2.0.0
2343 */
2344 template<typename BasicJsonType>
2346 
2347 /*!
2348 @brief default JSON class
2349 
2350 This type is the default specialization of the @ref basic_json class which
2351 uses the standard template types.
2352 
2353 @since version 1.0.0
2354 */
2355 using json = basic_json<>;
2356 } // namespace nlohmann
2357 
2358 #endif // INCLUDE_NLOHMANN_JSON_FWD_HPP_
2359 
2360 
2361 namespace nlohmann
2362 {
2363 /*!
2364 @brief detail namespace with internal helper functions
2365 
2366 This namespace collects functions that should not be exposed,
2367 implementations of some @ref basic_json methods, and meta-programming helpers.
2368 
2369 @since version 2.1.0
2370 */
2371 namespace detail
2372 {
2373 /////////////
2374 // helpers //
2375 /////////////
2376 
2377 // Note to maintainers:
2378 //
2379 // Every trait in this file expects a non CV-qualified type.
2380 // The only exceptions are in the 'aliases for detected' section
2381 // (i.e. those of the form: decltype(T::member_function(std::declval<T>())))
2382 //
2383 // In this case, T has to be properly CV-qualified to constraint the function arguments
2384 // (e.g. to_json(BasicJsonType&, const T&))
2385 
2386 template<typename> struct is_basic_json : std::false_type {};
2387 
2389 struct is_basic_json<NLOHMANN_BASIC_JSON_TPL> : std::true_type {};
2390 
2391 //////////////////////////
2392 // aliases for detected //
2393 //////////////////////////
2394 
2395 template <typename T>
2396 using mapped_type_t = typename T::mapped_type;
2397 
2398 template <typename T>
2399 using key_type_t = typename T::key_type;
2400 
2401 template <typename T>
2402 using value_type_t = typename T::value_type;
2403 
2404 template <typename T>
2405 using difference_type_t = typename T::difference_type;
2406 
2407 template <typename T>
2408 using pointer_t = typename T::pointer;
2409 
2410 template <typename T>
2411 using reference_t = typename T::reference;
2412 
2413 template <typename T>
2414 using iterator_category_t = typename T::iterator_category;
2415 
2416 template <typename T>
2417 using iterator_t = typename T::iterator;
2418 
2419 template <typename T, typename... Args>
2420 using to_json_function = decltype(T::to_json(std::declval<Args>()...));
2421 
2422 template <typename T, typename... Args>
2423 using from_json_function = decltype(T::from_json(std::declval<Args>()...));
2424 
2425 template <typename T, typename U>
2426 using get_template_function = decltype(std::declval<T>().template get<U>());
2427 
2428 // trait checking if JSONSerializer<T>::from_json(json const&, udt&) exists
2429 template <typename BasicJsonType, typename T, typename = void>
2430 struct has_from_json : std::false_type {};
2431 
2432 template <typename BasicJsonType, typename T>
2433 struct has_from_json<BasicJsonType, T,
2434  enable_if_t<not is_basic_json<T>::value>>
2435 {
2436  using serializer = typename BasicJsonType::template json_serializer<T, void>;
2437 
2438  static constexpr bool value =
2439  is_detected_exact<void, from_json_function, serializer,
2440  const BasicJsonType&, T&>::value;
2441 };
2442 
2443 // This trait checks if JSONSerializer<T>::from_json(json const&) exists
2444 // this overload is used for non-default-constructible user-defined-types
2445 template <typename BasicJsonType, typename T, typename = void>
2446 struct has_non_default_from_json : std::false_type {};
2447 
2448 template<typename BasicJsonType, typename T>
2449 struct has_non_default_from_json<BasicJsonType, T, enable_if_t<not is_basic_json<T>::value>>
2450 {
2451  using serializer = typename BasicJsonType::template json_serializer<T, void>;
2452 
2453  static constexpr bool value =
2454  is_detected_exact<T, from_json_function, serializer,
2455  const BasicJsonType&>::value;
2456 };
2457 
2458 // This trait checks if BasicJsonType::json_serializer<T>::to_json exists
2459 // Do not evaluate the trait when T is a basic_json type, to avoid template instantiation infinite recursion.
2460 template <typename BasicJsonType, typename T, typename = void>
2461 struct has_to_json : std::false_type {};
2462 
2463 template <typename BasicJsonType, typename T>
2464 struct has_to_json<BasicJsonType, T, enable_if_t<not is_basic_json<T>::value>>
2465 {
2466  using serializer = typename BasicJsonType::template json_serializer<T, void>;
2467 
2468  static constexpr bool value =
2469  is_detected_exact<void, to_json_function, serializer, BasicJsonType&,
2470  T>::value;
2471 };
2472 
2473 
2474 ///////////////////
2475 // is_ functions //
2476 ///////////////////
2477 
2478 template <typename T, typename = void>
2479 struct is_iterator_traits : std::false_type {};
2480 
2481 template <typename T>
2482 struct is_iterator_traits<iterator_traits<T>>
2483 {
2484  private:
2485  using traits = iterator_traits<T>;
2486 
2487  public:
2488  static constexpr auto value =
2489  is_detected<value_type_t, traits>::value &&
2490  is_detected<difference_type_t, traits>::value &&
2491  is_detected<pointer_t, traits>::value &&
2492  is_detected<iterator_category_t, traits>::value &&
2493  is_detected<reference_t, traits>::value;
2494 };
2495 
2496 // source: https://stackoverflow.com/a/37193089/4116453
2497 
2498 template <typename T, typename = void>
2499 struct is_complete_type : std::false_type {};
2500 
2501 template <typename T>
2502 struct is_complete_type<T, decltype(void(sizeof(T)))> : std::true_type {};
2503 
2504 template <typename BasicJsonType, typename CompatibleObjectType,
2505  typename = void>
2506 struct is_compatible_object_type_impl : std::false_type {};
2507 
2508 template <typename BasicJsonType, typename CompatibleObjectType>
2509 struct is_compatible_object_type_impl <
2510  BasicJsonType, CompatibleObjectType,
2511  enable_if_t<is_detected<mapped_type_t, CompatibleObjectType>::value and
2512  is_detected<key_type_t, CompatibleObjectType>::value >>
2513 {
2514 
2515  using object_t = typename BasicJsonType::object_t;
2516 
2517  // macOS's is_constructible does not play well with nonesuch...
2518  static constexpr bool value =
2519  std::is_constructible<typename object_t::key_type,
2520  typename CompatibleObjectType::key_type>::value and
2521  std::is_constructible<typename object_t::mapped_type,
2522  typename CompatibleObjectType::mapped_type>::value;
2523 };
2524 
2525 template <typename BasicJsonType, typename CompatibleObjectType>
2526 struct is_compatible_object_type
2527  : is_compatible_object_type_impl<BasicJsonType, CompatibleObjectType> {};
2528 
2529 template <typename BasicJsonType, typename ConstructibleObjectType,
2530  typename = void>
2531 struct is_constructible_object_type_impl : std::false_type {};
2532 
2533 template <typename BasicJsonType, typename ConstructibleObjectType>
2534 struct is_constructible_object_type_impl <
2535  BasicJsonType, ConstructibleObjectType,
2536  enable_if_t<is_detected<mapped_type_t, ConstructibleObjectType>::value and
2537  is_detected<key_type_t, ConstructibleObjectType>::value >>
2538 {
2539  using object_t = typename BasicJsonType::object_t;
2540 
2541  static constexpr bool value =
2542  (std::is_default_constructible<ConstructibleObjectType>::value and
2543  (std::is_move_assignable<ConstructibleObjectType>::value or
2544  std::is_copy_assignable<ConstructibleObjectType>::value) and
2545  (std::is_constructible<typename ConstructibleObjectType::key_type,
2546  typename object_t::key_type>::value and
2547  std::is_same <
2548  typename object_t::mapped_type,
2549  typename ConstructibleObjectType::mapped_type >::value)) or
2550  (has_from_json<BasicJsonType,
2551  typename ConstructibleObjectType::mapped_type>::value or
2552  has_non_default_from_json <
2553  BasicJsonType,
2554  typename ConstructibleObjectType::mapped_type >::value);
2555 };
2556 
2557 template <typename BasicJsonType, typename ConstructibleObjectType>
2558 struct is_constructible_object_type
2559  : is_constructible_object_type_impl<BasicJsonType,
2560  ConstructibleObjectType> {};
2561 
2562 template <typename BasicJsonType, typename CompatibleStringType,
2563  typename = void>
2564 struct is_compatible_string_type_impl : std::false_type {};
2565 
2566 template <typename BasicJsonType, typename CompatibleStringType>
2567 struct is_compatible_string_type_impl <
2568  BasicJsonType, CompatibleStringType,
2569  enable_if_t<is_detected_exact<typename BasicJsonType::string_t::value_type,
2570  value_type_t, CompatibleStringType>::value >>
2571 {
2572  static constexpr auto value =
2573  std::is_constructible<typename BasicJsonType::string_t, CompatibleStringType>::value;
2574 };
2575 
2576 template <typename BasicJsonType, typename ConstructibleStringType>
2577 struct is_compatible_string_type
2578  : is_compatible_string_type_impl<BasicJsonType, ConstructibleStringType> {};
2579 
2580 template <typename BasicJsonType, typename ConstructibleStringType,
2581  typename = void>
2582 struct is_constructible_string_type_impl : std::false_type {};
2583 
2584 template <typename BasicJsonType, typename ConstructibleStringType>
2585 struct is_constructible_string_type_impl <
2586  BasicJsonType, ConstructibleStringType,
2587  enable_if_t<is_detected_exact<typename BasicJsonType::string_t::value_type,
2588  value_type_t, ConstructibleStringType>::value >>
2589 {
2590  static constexpr auto value =
2591  std::is_constructible<ConstructibleStringType,
2592  typename BasicJsonType::string_t>::value;
2593 };
2594 
2595 template <typename BasicJsonType, typename ConstructibleStringType>
2596 struct is_constructible_string_type
2597  : is_constructible_string_type_impl<BasicJsonType, ConstructibleStringType> {};
2598 
2599 template <typename BasicJsonType, typename CompatibleArrayType, typename = void>
2600 struct is_compatible_array_type_impl : std::false_type {};
2601 
2602 template <typename BasicJsonType, typename CompatibleArrayType>
2603 struct is_compatible_array_type_impl <
2604  BasicJsonType, CompatibleArrayType,
2605  enable_if_t<is_detected<value_type_t, CompatibleArrayType>::value and
2606  is_detected<iterator_t, CompatibleArrayType>::value and
2607 // This is needed because json_reverse_iterator has a ::iterator type...
2608 // Therefore it is detected as a CompatibleArrayType.
2609 // The real fix would be to have an Iterable concept.
2610  not is_iterator_traits<
2611  iterator_traits<CompatibleArrayType>>::value >>
2612 {
2613  static constexpr bool value =
2614  std::is_constructible<BasicJsonType,
2615  typename CompatibleArrayType::value_type>::value;
2616 };
2617 
2618 template <typename BasicJsonType, typename CompatibleArrayType>
2619 struct is_compatible_array_type
2620  : is_compatible_array_type_impl<BasicJsonType, CompatibleArrayType> {};
2621 
2622 template <typename BasicJsonType, typename ConstructibleArrayType, typename = void>
2623 struct is_constructible_array_type_impl : std::false_type {};
2624 
2625 template <typename BasicJsonType, typename ConstructibleArrayType>
2626 struct is_constructible_array_type_impl <
2627  BasicJsonType, ConstructibleArrayType,
2628  enable_if_t<std::is_same<ConstructibleArrayType,
2629  typename BasicJsonType::value_type>::value >>
2630  : std::true_type {};
2631 
2632 template <typename BasicJsonType, typename ConstructibleArrayType>
2633 struct is_constructible_array_type_impl <
2634  BasicJsonType, ConstructibleArrayType,
2635  enable_if_t<not std::is_same<ConstructibleArrayType,
2636  typename BasicJsonType::value_type>::value and
2637  std::is_default_constructible<ConstructibleArrayType>::value and
2638 (std::is_move_assignable<ConstructibleArrayType>::value or
2639  std::is_copy_assignable<ConstructibleArrayType>::value) and
2640 is_detected<value_type_t, ConstructibleArrayType>::value and
2641 is_detected<iterator_t, ConstructibleArrayType>::value and
2642 is_complete_type<
2643 detected_t<value_type_t, ConstructibleArrayType>>::value >>
2644 {
2645  static constexpr bool value =
2646  // This is needed because json_reverse_iterator has a ::iterator type,
2647  // furthermore, std::back_insert_iterator (and other iterators) have a
2648  // base class `iterator`... Therefore it is detected as a
2649  // ConstructibleArrayType. The real fix would be to have an Iterable
2650  // concept.
2651  not is_iterator_traits<iterator_traits<ConstructibleArrayType>>::value and
2652 
2653  (std::is_same<typename ConstructibleArrayType::value_type,
2654  typename BasicJsonType::array_t::value_type>::value or
2655  has_from_json<BasicJsonType,
2656  typename ConstructibleArrayType::value_type>::value or
2657  has_non_default_from_json <
2658  BasicJsonType, typename ConstructibleArrayType::value_type >::value);
2659 };
2660 
2661 template <typename BasicJsonType, typename ConstructibleArrayType>
2662 struct is_constructible_array_type
2663  : is_constructible_array_type_impl<BasicJsonType, ConstructibleArrayType> {};
2664 
2665 template <typename RealIntegerType, typename CompatibleNumberIntegerType,
2666  typename = void>
2667 struct is_compatible_integer_type_impl : std::false_type {};
2668 
2669 template <typename RealIntegerType, typename CompatibleNumberIntegerType>
2670 struct is_compatible_integer_type_impl <
2671  RealIntegerType, CompatibleNumberIntegerType,
2672  enable_if_t<std::is_integral<RealIntegerType>::value and
2673  std::is_integral<CompatibleNumberIntegerType>::value and
2674  not std::is_same<bool, CompatibleNumberIntegerType>::value >>
2675 {
2676  // is there an assert somewhere on overflows?
2677  using RealLimits = std::numeric_limits<RealIntegerType>;
2678  using CompatibleLimits = std::numeric_limits<CompatibleNumberIntegerType>;
2679 
2680  static constexpr auto value =
2681  std::is_constructible<RealIntegerType,
2682  CompatibleNumberIntegerType>::value and
2683  CompatibleLimits::is_integer and
2684  RealLimits::is_signed == CompatibleLimits::is_signed;
2685 };
2686 
2687 template <typename RealIntegerType, typename CompatibleNumberIntegerType>
2688 struct is_compatible_integer_type
2689  : is_compatible_integer_type_impl<RealIntegerType,
2690  CompatibleNumberIntegerType> {};
2691 
2692 template <typename BasicJsonType, typename CompatibleType, typename = void>
2693 struct is_compatible_type_impl: std::false_type {};
2694 
2695 template <typename BasicJsonType, typename CompatibleType>
2696 struct is_compatible_type_impl <
2697  BasicJsonType, CompatibleType,
2698  enable_if_t<is_complete_type<CompatibleType>::value >>
2699 {
2700  static constexpr bool value =
2701  has_to_json<BasicJsonType, CompatibleType>::value;
2702 };
2703 
2704 template <typename BasicJsonType, typename CompatibleType>
2705 struct is_compatible_type
2706  : is_compatible_type_impl<BasicJsonType, CompatibleType> {};
2707 } // namespace detail
2708 } // namespace nlohmann
2709 
2710 // #include <nlohmann/detail/value_t.hpp>
2711 
2712 
2713 #include <array> // array
2714 #include <ciso646> // and
2715 #include <cstddef> // size_t
2716 #include <cstdint> // uint8_t
2717 #include <string> // string
2718 
2719 namespace nlohmann
2720 {
2721 namespace detail
2722 {
2723 ///////////////////////////
2724 // JSON type enumeration //
2725 ///////////////////////////
2726 
2727 /*!
2728 @brief the JSON type enumeration
2729 
2730 This enumeration collects the different JSON types. It is internally used to
2731 distinguish the stored values, and the functions @ref basic_json::is_null(),
2732 @ref basic_json::is_object(), @ref basic_json::is_array(),
2733 @ref basic_json::is_string(), @ref basic_json::is_boolean(),
2734 @ref basic_json::is_number() (with @ref basic_json::is_number_integer(),
2735 @ref basic_json::is_number_unsigned(), and @ref basic_json::is_number_float()),
2736 @ref basic_json::is_discarded(), @ref basic_json::is_primitive(), and
2737 @ref basic_json::is_structured() rely on it.
2738 
2739 @note There are three enumeration entries (number_integer, number_unsigned, and
2740 number_float), because the library distinguishes these three types for numbers:
2741 @ref basic_json::number_unsigned_t is used for unsigned integers,
2742 @ref basic_json::number_integer_t is used for signed integers, and
2743 @ref basic_json::number_float_t is used for floating-point numbers or to
2744 approximate integers which do not fit in the limits of their respective type.
2745 
2746 @sa @ref basic_json::basic_json(const value_t value_type) -- create a JSON
2747 value with the default value for a given type
2748 
2749 @since version 1.0.0
2750 */
2751 enum class value_t : std::uint8_t
2752 {
2753  null, ///< null value
2754  object, ///< object (unordered set of name/value pairs)
2755  array, ///< array (ordered collection of values)
2756  string, ///< string value
2757  boolean, ///< boolean value
2758  number_integer, ///< number value (signed integer)
2759  number_unsigned, ///< number value (unsigned integer)
2760  number_float, ///< number value (floating-point)
2761  discarded ///< discarded by the the parser callback function
2762 };
2763 
2764 /*!
2765 @brief comparison operator for JSON types
2766 
2767 Returns an ordering that is similar to Python:
2768 - order: null < boolean < number < object < array < string
2769 - furthermore, each type is not smaller than itself
2770 - discarded values are not comparable
2771 
2772 @since version 1.0.0
2773 */
2774 inline bool operator<(const value_t lhs, const value_t rhs) noexcept
2775 {
2776  static constexpr std::array<std::uint8_t, 8> order = {{
2777  0 /* null */, 3 /* object */, 4 /* array */, 5 /* string */,
2778  1 /* boolean */, 2 /* integer */, 2 /* unsigned */, 2 /* float */
2779  }
2780  };
2781 
2782  const auto l_index = static_cast<std::size_t>(lhs);
2783  const auto r_index = static_cast<std::size_t>(rhs);
2784  return l_index < order.size() and r_index < order.size() and order[l_index] < order[r_index];
2785 }
2786 } // namespace detail
2787 } // namespace nlohmann
2788 
2789 
2790 namespace nlohmann
2791 {
2792 namespace detail
2793 {
2794 template<typename BasicJsonType>
2795 void from_json(const BasicJsonType& j, typename std::nullptr_t& n)
2796 {
2797  if (JSON_HEDLEY_UNLIKELY(not j.is_null()))
2798  {
2799  JSON_THROW(type_error::create(302, "type must be null, but is " + std::string(j.type_name())));
2800  }
2801  n = nullptr;
2802 }
2803 
2804 // overloads for basic_json template parameters
2805 template<typename BasicJsonType, typename ArithmeticType,
2806  enable_if_t<std::is_arithmetic<ArithmeticType>::value and
2807  not std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
2808  int> = 0>
2809 void get_arithmetic_value(const BasicJsonType& j, ArithmeticType& val)
2810 {
2811  switch (static_cast<value_t>(j))
2812  {
2813  case value_t::number_unsigned:
2814  {
2815  val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
2816  break;
2817  }
2818  case value_t::number_integer:
2819  {
2820  val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
2821  break;
2822  }
2823  case value_t::number_float:
2824  {
2825  val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
2826  break;
2827  }
2828 
2829  default:
2830  JSON_THROW(type_error::create(302, "type must be number, but is " + std::string(j.type_name())));
2831  }
2832 }
2833 
2834 template<typename BasicJsonType>
2835 void from_json(const BasicJsonType& j, typename BasicJsonType::boolean_t& b)
2836 {
2837  if (JSON_HEDLEY_UNLIKELY(not j.is_boolean()))
2838  {
2839  JSON_THROW(type_error::create(302, "type must be boolean, but is " + std::string(j.type_name())));
2840  }
2841  b = *j.template get_ptr<const typename BasicJsonType::boolean_t*>();
2842 }
2843 
2844 template<typename BasicJsonType>
2845 void from_json(const BasicJsonType& j, typename BasicJsonType::string_t& s)
2846 {
2847  if (JSON_HEDLEY_UNLIKELY(not j.is_string()))
2848  {
2849  JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name())));
2850  }
2851  s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
2852 }
2853 
2854 template <
2855  typename BasicJsonType, typename ConstructibleStringType,
2856  enable_if_t <
2857  is_constructible_string_type<BasicJsonType, ConstructibleStringType>::value and
2858  not std::is_same<typename BasicJsonType::string_t,
2859  ConstructibleStringType>::value,
2860  int > = 0 >
2861 void from_json(const BasicJsonType& j, ConstructibleStringType& s)
2862 {
2863  if (JSON_HEDLEY_UNLIKELY(not j.is_string()))
2864  {
2865  JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name())));
2866  }
2867 
2868  s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
2869 }
2870 
2871 template<typename BasicJsonType>
2872 void from_json(const BasicJsonType& j, typename BasicJsonType::number_float_t& val)
2873 {
2874  get_arithmetic_value(j, val);
2875 }
2876 
2877 template<typename BasicJsonType>
2878 void from_json(const BasicJsonType& j, typename BasicJsonType::number_unsigned_t& val)
2879 {
2880  get_arithmetic_value(j, val);
2881 }
2882 
2883 template<typename BasicJsonType>
2884 void from_json(const BasicJsonType& j, typename BasicJsonType::number_integer_t& val)
2885 {
2886  get_arithmetic_value(j, val);
2887 }
2888 
2889 template<typename BasicJsonType, typename EnumType,
2890  enable_if_t<std::is_enum<EnumType>::value, int> = 0>
2891 void from_json(const BasicJsonType& j, EnumType& e)
2892 {
2893  typename std::underlying_type<EnumType>::type val;
2894  get_arithmetic_value(j, val);
2895  e = static_cast<EnumType>(val);
2896 }
2897 
2898 // forward_list doesn't have an insert method
2899 template<typename BasicJsonType, typename T, typename Allocator,
2900  enable_if_t<std::is_convertible<BasicJsonType, T>::value, int> = 0>
2901 void from_json(const BasicJsonType& j, std::forward_list<T, Allocator>& l)
2902 {
2903  if (JSON_HEDLEY_UNLIKELY(not j.is_array()))
2904  {
2905  JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name())));
2906  }
2907  l.clear();
2908  std::transform(j.rbegin(), j.rend(),
2909  std::front_inserter(l), [](const BasicJsonType & i)
2910  {
2911  return i.template get<T>();
2912  });
2913 }
2914 
2915 // valarray doesn't have an insert method
2916 template<typename BasicJsonType, typename T,
2917  enable_if_t<std::is_convertible<BasicJsonType, T>::value, int> = 0>
2918 void from_json(const BasicJsonType& j, std::valarray<T>& l)
2919 {
2920  if (JSON_HEDLEY_UNLIKELY(not j.is_array()))
2921  {
2922  JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name())));
2923  }
2924  l.resize(j.size());
2925  std::copy(j.m_value.array->begin(), j.m_value.array->end(), std::begin(l));
2926 }
2927 
2928 template <typename BasicJsonType, typename T, std::size_t N>
2929 auto from_json(const BasicJsonType& j, T (&arr)[N])
2930 -> decltype(j.template get<T>(), void())
2931 {
2932  for (std::size_t i = 0; i < N; ++i)
2933  {
2934  arr[i] = j.at(i).template get<T>();
2935  }
2936 }
2937 
2938 template<typename BasicJsonType>
2939 void from_json_array_impl(const BasicJsonType& j, typename BasicJsonType::array_t& arr, priority_tag<3> /*unused*/)
2940 {
2941  arr = *j.template get_ptr<const typename BasicJsonType::array_t*>();
2942 }
2943 
2944 template <typename BasicJsonType, typename T, std::size_t N>
2945 auto from_json_array_impl(const BasicJsonType& j, std::array<T, N>& arr,
2946  priority_tag<2> /*unused*/)
2947 -> decltype(j.template get<T>(), void())
2948 {
2949  for (std::size_t i = 0; i < N; ++i)
2950  {
2951  arr[i] = j.at(i).template get<T>();
2952  }
2953 }
2954 
2955 template<typename BasicJsonType, typename ConstructibleArrayType>
2956 auto from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, priority_tag<1> /*unused*/)
2957 -> decltype(
2958  arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()),
2959  j.template get<typename ConstructibleArrayType::value_type>(),
2960  void())
2961 {
2962  using std::end;
2963 
2964  ConstructibleArrayType ret;
2965  ret.reserve(j.size());
2966  std::transform(j.begin(), j.end(),
2967  std::inserter(ret, end(ret)), [](const BasicJsonType & i)
2968  {
2969  // get<BasicJsonType>() returns *this, this won't call a from_json
2970  // method when value_type is BasicJsonType
2971  return i.template get<typename ConstructibleArrayType::value_type>();
2972  });
2973  arr = std::move(ret);
2974 }
2975 
2976 template <typename BasicJsonType, typename ConstructibleArrayType>
2977 void from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr,
2978  priority_tag<0> /*unused*/)
2979 {
2980  using std::end;
2981 
2982  ConstructibleArrayType ret;
2983  std::transform(
2984  j.begin(), j.end(), std::inserter(ret, end(ret)),
2985  [](const BasicJsonType & i)
2986  {
2987  // get<BasicJsonType>() returns *this, this won't call a from_json
2988  // method when value_type is BasicJsonType
2989  return i.template get<typename ConstructibleArrayType::value_type>();
2990  });
2991  arr = std::move(ret);
2992 }
2993 
2994 template <typename BasicJsonType, typename ConstructibleArrayType,
2995  enable_if_t <
2996  is_constructible_array_type<BasicJsonType, ConstructibleArrayType>::value and
2997  not is_constructible_object_type<BasicJsonType, ConstructibleArrayType>::value and
2998  not is_constructible_string_type<BasicJsonType, ConstructibleArrayType>::value and
2999  not is_basic_json<ConstructibleArrayType>::value,
3000  int > = 0 >
3001 
3002 auto from_json(const BasicJsonType& j, ConstructibleArrayType& arr)
3003 -> decltype(from_json_array_impl(j, arr, priority_tag<3> {}),
3004 j.template get<typename ConstructibleArrayType::value_type>(),
3005 void())
3006 {
3007  if (JSON_HEDLEY_UNLIKELY(not j.is_array()))
3008  {
3009  JSON_THROW(type_error::create(302, "type must be array, but is " +
3010  std::string(j.type_name())));
3011  }
3012 
3013  from_json_array_impl(j, arr, priority_tag<3> {});
3014 }
3015 
3016 template<typename BasicJsonType, typename ConstructibleObjectType,
3017  enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value, int> = 0>
3018 void from_json(const BasicJsonType& j, ConstructibleObjectType& obj)
3019 {
3020  if (JSON_HEDLEY_UNLIKELY(not j.is_object()))
3021  {
3022  JSON_THROW(type_error::create(302, "type must be object, but is " + std::string(j.type_name())));
3023  }
3024 
3025  ConstructibleObjectType ret;
3026  auto inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
3027  using value_type = typename ConstructibleObjectType::value_type;
3028  std::transform(
3029  inner_object->begin(), inner_object->end(),
3030  std::inserter(ret, ret.begin()),
3031  [](typename BasicJsonType::object_t::value_type const & p)
3032  {
3033  return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
3034  });
3035  obj = std::move(ret);
3036 }
3037 
3038 // overload for arithmetic types, not chosen for basic_json template arguments
3039 // (BooleanType, etc..); note: Is it really necessary to provide explicit
3040 // overloads for boolean_t etc. in case of a custom BooleanType which is not
3041 // an arithmetic type?
3042 template<typename BasicJsonType, typename ArithmeticType,
3043  enable_if_t <
3044  std::is_arithmetic<ArithmeticType>::value and
3045  not std::is_same<ArithmeticType, typename BasicJsonType::number_unsigned_t>::value and
3046  not std::is_same<ArithmeticType, typename BasicJsonType::number_integer_t>::value and
3047  not std::is_same<ArithmeticType, typename BasicJsonType::number_float_t>::value and
3048  not std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
3049  int> = 0>
3050 void from_json(const BasicJsonType& j, ArithmeticType& val)
3051 {
3052  switch (static_cast<value_t>(j))
3053  {
3054  case value_t::number_unsigned:
3055  {
3056  val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
3057  break;
3058  }
3059  case value_t::number_integer:
3060  {
3061  val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
3062  break;
3063  }
3064  case value_t::number_float:
3065  {
3066  val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
3067  break;
3068  }
3069  case value_t::boolean:
3070  {
3071  val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::boolean_t*>());
3072  break;
3073  }
3074 
3075  default:
3076  JSON_THROW(type_error::create(302, "type must be number, but is " + std::string(j.type_name())));
3077  }
3078 }
3079 
3080 template<typename BasicJsonType, typename A1, typename A2>
3081 void from_json(const BasicJsonType& j, std::pair<A1, A2>& p)
3082 {
3083  p = {j.at(0).template get<A1>(), j.at(1).template get<A2>()};
3084 }
3085 
3086 template<typename BasicJsonType, typename Tuple, std::size_t... Idx>
3087 void from_json_tuple_impl(const BasicJsonType& j, Tuple& t, index_sequence<Idx...> /*unused*/)
3088 {
3089  t = std::make_tuple(j.at(Idx).template get<typename std::tuple_element<Idx, Tuple>::type>()...);
3090 }
3091 
3092 template<typename BasicJsonType, typename... Args>
3093 void from_json(const BasicJsonType& j, std::tuple<Args...>& t)
3094 {
3095  from_json_tuple_impl(j, t, index_sequence_for<Args...> {});
3096 }
3097 
3098 template <typename BasicJsonType, typename Key, typename Value, typename Compare, typename Allocator,
3099  typename = enable_if_t<not std::is_constructible<
3100  typename BasicJsonType::string_t, Key>::value>>
3101 void from_json(const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>& m)
3102 {
3103  if (JSON_HEDLEY_UNLIKELY(not j.is_array()))
3104  {
3105  JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name())));
3106  }
3107  m.clear();
3108  for (const auto& p : j)
3109  {
3110  if (JSON_HEDLEY_UNLIKELY(not p.is_array()))
3111  {
3112  JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(p.type_name())));
3113  }
3114  m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
3115  }
3116 }
3117 
3118 template <typename BasicJsonType, typename Key, typename Value, typename Hash, typename KeyEqual, typename Allocator,
3119  typename = enable_if_t<not std::is_constructible<
3120  typename BasicJsonType::string_t, Key>::value>>
3121 void from_json(const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>& m)
3122 {
3123  if (JSON_HEDLEY_UNLIKELY(not j.is_array()))
3124  {
3125  JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name())));
3126  }
3127  m.clear();
3128  for (const auto& p : j)
3129  {
3130  if (JSON_HEDLEY_UNLIKELY(not p.is_array()))
3131  {
3132  JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(p.type_name())));
3133  }
3134  m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
3135  }
3136 }
3137 
3138 struct from_json_fn
3139 {
3140  template<typename BasicJsonType, typename T>
3141  auto operator()(const BasicJsonType& j, T& val) const
3142  noexcept(noexcept(from_json(j, val)))
3143  -> decltype(from_json(j, val), void())
3144  {
3145  return from_json(j, val);
3146  }
3147 };
3148 } // namespace detail
3149 
3150 /// namespace to hold default `from_json` function
3151 /// to see why this is required:
3152 /// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4381.html
3153 namespace
3154 {
3155 constexpr const auto& from_json = detail::static_const<detail::from_json_fn>::value;
3156 } // namespace
3157 } // namespace nlohmann
3158 
3159 // #include <nlohmann/detail/conversions/to_json.hpp>
3160 
3161 
3162 #include <algorithm> // copy
3163 #include <ciso646> // or, and, not
3164 #include <iterator> // begin, end
3165 #include <string> // string
3166 #include <tuple> // tuple, get
3167 #include <type_traits> // is_same, is_constructible, is_floating_point, is_enum, underlying_type
3168 #include <utility> // move, forward, declval, pair
3169 #include <valarray> // valarray
3170 #include <vector> // vector
3171 
3172 // #include <nlohmann/detail/iterators/iteration_proxy.hpp>
3173 
3174 
3175 #include <cstddef> // size_t
3176 #include <iterator> // input_iterator_tag
3177 #include <string> // string, to_string
3178 #include <tuple> // tuple_size, get, tuple_element
3179 
3180 // #include <nlohmann/detail/meta/type_traits.hpp>
3181 
3182 // #include <nlohmann/detail/value_t.hpp>
3183 
3184 
3185 namespace nlohmann
3186 {
3187 namespace detail
3188 {
3189 template <typename IteratorType> class iteration_proxy_value
3190 {
3191  public:
3192  using difference_type = std::ptrdiff_t;
3193  using value_type = iteration_proxy_value;
3194  using pointer = value_type * ;
3195  using reference = value_type & ;
3196  using iterator_category = std::input_iterator_tag;
3197 
3198  private:
3199  /// the iterator
3200  IteratorType anchor;
3201  /// an index for arrays (used to create key names)
3202  std::size_t array_index = 0;
3203  /// last stringified array index
3204  mutable std::size_t array_index_last = 0;
3205  /// a string representation of the array index
3206  mutable std::string array_index_str = "0";
3207  /// an empty string (to return a reference for primitive values)
3208  const std::string empty_str = "";
3209 
3210  public:
3211  explicit iteration_proxy_value(IteratorType it) noexcept : anchor(it) {}
3212 
3213  /// dereference operator (needed for range-based for)
3214  iteration_proxy_value& operator*()
3215  {
3216  return *this;
3217  }
3218 
3219  /// increment operator (needed for range-based for)
3220  iteration_proxy_value& operator++()
3221  {
3222  ++anchor;
3223  ++array_index;
3224 
3225  return *this;
3226  }
3227 
3228  /// equality operator (needed for InputIterator)
3229  bool operator==(const iteration_proxy_value& o) const
3230  {
3231  return anchor == o.anchor;
3232  }
3233 
3234  /// inequality operator (needed for range-based for)
3235  bool operator!=(const iteration_proxy_value& o) const
3236  {
3237  return anchor != o.anchor;
3238  }
3239 
3240  /// return key of the iterator
3241  const std::string& key() const
3242  {
3243  assert(anchor.m_object != nullptr);
3244 
3245  switch (anchor.m_object->type())
3246  {
3247  // use integer array index as key
3248  case value_t::array:
3249  {
3250  if (array_index != array_index_last)
3251  {
3252  array_index_str = std::to_string(array_index);
3253  array_index_last = array_index;
3254  }
3255  return array_index_str;
3256  }
3257 
3258  // use key from the object
3259  case value_t::object:
3260  return anchor.key();
3261 
3262  // use an empty key for all primitive types
3263  default:
3264  return empty_str;
3265  }
3266  }
3267 
3268  /// return value of the iterator
3269  typename IteratorType::reference value() const
3270  {
3271  return anchor.value();
3272  }
3273 };
3274 
3275 /// proxy class for the items() function
3276 template<typename IteratorType> class iteration_proxy
3277 {
3278  private:
3279  /// the container to iterate
3280  typename IteratorType::reference container;
3281 
3282  public:
3283  /// construct iteration proxy from a container
3284  explicit iteration_proxy(typename IteratorType::reference cont) noexcept
3285  : container(cont) {}
3286 
3287  /// return iterator begin (needed for range-based for)
3288  iteration_proxy_value<IteratorType> begin() noexcept
3289  {
3290  return iteration_proxy_value<IteratorType>(container.begin());
3291  }
3292 
3293  /// return iterator end (needed for range-based for)
3294  iteration_proxy_value<IteratorType> end() noexcept
3295  {
3296  return iteration_proxy_value<IteratorType>(container.end());
3297  }
3298 };
3299 // Structured Bindings Support
3300 // For further reference see https://blog.tartanllama.xyz/structured-bindings/
3301 // And see https://github.com/nlohmann/json/pull/1391
3302 template <std::size_t N, typename IteratorType, enable_if_t<N == 0, int> = 0>
3303 auto get(const nlohmann::detail::iteration_proxy_value<IteratorType>& i) -> decltype(i.key())
3304 {
3305  return i.key();
3306 }
3307 // Structured Bindings Support
3308 // For further reference see https://blog.tartanllama.xyz/structured-bindings/
3309 // And see https://github.com/nlohmann/json/pull/1391
3310 template <std::size_t N, typename IteratorType, enable_if_t<N == 1, int> = 0>
3311 auto get(const nlohmann::detail::iteration_proxy_value<IteratorType>& i) -> decltype(i.value())
3312 {
3313  return i.value();
3314 }
3315 } // namespace detail
3316 } // namespace nlohmann
3317 
3318 // The Addition to the STD Namespace is required to add
3319 // Structured Bindings Support to the iteration_proxy_value class
3320 // For further reference see https://blog.tartanllama.xyz/structured-bindings/
3321 // And see https://github.com/nlohmann/json/pull/1391
3322 namespace std
3323 {
3324 #if defined(__clang__)
3325  // Fix: https://github.com/nlohmann/json/issues/1401
3326  #pragma clang diagnostic push
3327  #pragma clang diagnostic ignored "-Wmismatched-tags"
3328 #endif
3329 template <typename IteratorType>
3330 class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>>
3331  : public std::integral_constant<std::size_t, 2> {};
3332 
3333 template <std::size_t N, typename IteratorType>
3334 class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType >>
3335 {
3336  public:
3337  using type = decltype(
3338  get<N>(std::declval <
3339  ::nlohmann::detail::iteration_proxy_value<IteratorType >> ()));
3340 };
3341 #if defined(__clang__)
3342  #pragma clang diagnostic pop
3343 #endif
3344 } // namespace std
3345 
3346 // #include <nlohmann/detail/meta/cpp_future.hpp>
3347 
3348 // #include <nlohmann/detail/meta/type_traits.hpp>
3349 
3350 // #include <nlohmann/detail/value_t.hpp>
3351 
3352 
3353 namespace nlohmann
3354 {
3355 namespace detail
3356 {
3357 //////////////////
3358 // constructors //
3359 //////////////////
3360 
3361 template<value_t> struct external_constructor;
3362 
3363 template<>
3364 struct external_constructor<value_t::boolean>
3365 {
3366  template<typename BasicJsonType>
3367  static void construct(BasicJsonType& j, typename BasicJsonType::boolean_t b) noexcept
3368  {
3369  j.m_type = value_t::boolean;
3370  j.m_value = b;
3371  j.assert_invariant();
3372  }
3373 };
3374 
3375 template<>
3376 struct external_constructor<value_t::string>
3377 {
3378  template<typename BasicJsonType>
3379  static void construct(BasicJsonType& j, const typename BasicJsonType::string_t& s)
3380  {
3381  j.m_type = value_t::string;
3382  j.m_value = s;
3383  j.assert_invariant();
3384  }
3385 
3386  template<typename BasicJsonType>
3387  static void construct(BasicJsonType& j, typename BasicJsonType::string_t&& s)
3388  {
3389  j.m_type = value_t::string;
3390  j.m_value = std::move(s);
3391  j.assert_invariant();
3392  }
3393 
3394  template<typename BasicJsonType, typename CompatibleStringType,
3396  int> = 0>
3397  static void construct(BasicJsonType& j, const CompatibleStringType& str)
3398  {
3399  j.m_type = value_t::string;
3400  j.m_value.string = j.template create<typename BasicJsonType::string_t>(str);
3401  j.assert_invariant();
3402  }
3403 };
3404 
3405 template<>
3406 struct external_constructor<value_t::number_float>
3407 {
3408  template<typename BasicJsonType>
3409  static void construct(BasicJsonType& j, typename BasicJsonType::number_float_t val) noexcept
3410  {
3411  j.m_type = value_t::number_float;
3412  j.m_value = val;
3413  j.assert_invariant();
3414  }
3415 };
3416 
3417 template<>
3418 struct external_constructor<value_t::number_unsigned>
3419 {
3420  template<typename BasicJsonType>
3421  static void construct(BasicJsonType& j, typename BasicJsonType::number_unsigned_t val) noexcept
3422  {
3423  j.m_type = value_t::number_unsigned;
3424  j.m_value = val;
3425  j.assert_invariant();
3426  }
3427 };
3428 
3429 template<>
3430 struct external_constructor<value_t::number_integer>
3431 {
3432  template<typename BasicJsonType>
3433  static void construct(BasicJsonType& j, typename BasicJsonType::number_integer_t val) noexcept
3434  {
3435  j.m_type = value_t::number_integer;
3436  j.m_value = val;
3437  j.assert_invariant();
3438  }
3439 };
3440 
3441 template<>
3442 struct external_constructor<value_t::array>
3443 {
3444  template<typename BasicJsonType>
3445  static void construct(BasicJsonType& j, const typename BasicJsonType::array_t& arr)
3446  {
3447  j.m_type = value_t::array;
3448  j.m_value = arr;
3449  j.assert_invariant();
3450  }
3451 
3452  template<typename BasicJsonType>
3453  static void construct(BasicJsonType& j, typename BasicJsonType::array_t&& arr)
3454  {
3455  j.m_type = value_t::array;
3456  j.m_value = std::move(arr);
3457  j.assert_invariant();
3458  }
3459 
3460  template<typename BasicJsonType, typename CompatibleArrayType,
3462  int> = 0>
3463  static void construct(BasicJsonType& j, const CompatibleArrayType& arr)
3464  {
3465  using std::begin;
3466  using std::end;
3467  j.m_type = value_t::array;
3468  j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
3469  j.assert_invariant();
3470  }
3471 
3472  template<typename BasicJsonType>
3473  static void construct(BasicJsonType& j, const std::vector<bool>& arr)
3474  {
3475  j.m_type = value_t::array;
3476  j.m_value = value_t::array;
3477  j.m_value.array->reserve(arr.size());
3478  for (const bool x : arr)
3479  {
3481  }
3482  j.assert_invariant();
3483  }
3484 
3485  template<typename BasicJsonType, typename T,
3487  static void construct(BasicJsonType& j, const std::valarray<T>& arr)
3488  {
3489  j.m_type = value_t::array;
3490  j.m_value = value_t::array;
3491  j.m_value.array->resize(arr.size());
3492  std::copy(std::begin(arr), std::end(arr), j.m_value.array->begin());
3493  j.assert_invariant();
3494  }
3495 };
3496 
3497 template<>
3498 struct external_constructor<value_t::object>
3499 {
3500  template<typename BasicJsonType>
3501  static void construct(BasicJsonType& j, const typename BasicJsonType::object_t& obj)
3502  {
3503  j.m_type = value_t::object;
3504  j.m_value = obj;
3505  j.assert_invariant();
3506  }
3507 
3508  template<typename BasicJsonType>
3509  static void construct(BasicJsonType& j, typename BasicJsonType::object_t&& obj)
3510  {
3511  j.m_type = value_t::object;
3512  j.m_value = std::move(obj);
3513  j.assert_invariant();
3514  }
3515 
3516  template<typename BasicJsonType, typename CompatibleObjectType,
3518  static void construct(BasicJsonType& j, const CompatibleObjectType& obj)
3519  {
3520  using std::begin;
3521  using std::end;
3522 
3523  j.m_type = value_t::object;
3524  j.m_value.object = j.template create<typename BasicJsonType::object_t>(begin(obj), end(obj));
3525  j.assert_invariant();
3526  }
3527 };
3528 
3529 /////////////
3530 // to_json //
3531 /////////////
3532 
3533 template<typename BasicJsonType, typename T,
3534  enable_if_t<std::is_same<T, typename BasicJsonType::boolean_t>::value, int> = 0>
3535 void to_json(BasicJsonType& j, T b) noexcept
3536 {
3537  external_constructor<value_t::boolean>::construct(j, b);
3538 }
3539 
3540 template<typename BasicJsonType, typename CompatibleString,
3541  enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value, int> = 0>
3542 void to_json(BasicJsonType& j, const CompatibleString& s)
3543 {
3544  external_constructor<value_t::string>::construct(j, s);
3545 }
3546 
3547 template<typename BasicJsonType>
3548 void to_json(BasicJsonType& j, typename BasicJsonType::string_t&& s)
3549 {
3550  external_constructor<value_t::string>::construct(j, std::move(s));
3551 }
3552 
3553 template<typename BasicJsonType, typename FloatType,
3554  enable_if_t<std::is_floating_point<FloatType>::value, int> = 0>
3555 void to_json(BasicJsonType& j, FloatType val) noexcept
3556 {
3557  external_constructor<value_t::number_float>::construct(j, static_cast<typename BasicJsonType::number_float_t>(val));
3558 }
3559 
3560 template<typename BasicJsonType, typename CompatibleNumberUnsignedType,
3561  enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_unsigned_t, CompatibleNumberUnsignedType>::value, int> = 0>
3562 void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val) noexcept
3563 {
3564  external_constructor<value_t::number_unsigned>::construct(j, static_cast<typename BasicJsonType::number_unsigned_t>(val));
3565 }
3566 
3567 template<typename BasicJsonType, typename CompatibleNumberIntegerType,
3568  enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_integer_t, CompatibleNumberIntegerType>::value, int> = 0>
3569 void to_json(BasicJsonType& j, CompatibleNumberIntegerType val) noexcept
3570 {
3571  external_constructor<value_t::number_integer>::construct(j, static_cast<typename BasicJsonType::number_integer_t>(val));
3572 }
3573 
3574 template<typename BasicJsonType, typename EnumType,
3575  enable_if_t<std::is_enum<EnumType>::value, int> = 0>
3576 void to_json(BasicJsonType& j, EnumType e) noexcept
3577 {
3578  using underlying_type = typename std::underlying_type<EnumType>::type;
3579  external_constructor<value_t::number_integer>::construct(j, static_cast<underlying_type>(e));
3580 }
3581 
3582 template<typename BasicJsonType>
3583 void to_json(BasicJsonType& j, const std::vector<bool>& e)
3584 {
3585  external_constructor<value_t::array>::construct(j, e);
3586 }
3587 
3588 template <typename BasicJsonType, typename CompatibleArrayType,
3589  enable_if_t<is_compatible_array_type<BasicJsonType,
3590  CompatibleArrayType>::value and
3591  not is_compatible_object_type<
3592  BasicJsonType, CompatibleArrayType>::value and
3593  not is_compatible_string_type<BasicJsonType, CompatibleArrayType>::value and
3594  not is_basic_json<CompatibleArrayType>::value,
3595  int> = 0>
3596 void to_json(BasicJsonType& j, const CompatibleArrayType& arr)
3597 {
3598  external_constructor<value_t::array>::construct(j, arr);
3599 }
3600 
3601 template<typename BasicJsonType, typename T,
3602  enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0>
3603 void to_json(BasicJsonType& j, const std::valarray<T>& arr)
3604 {
3605  external_constructor<value_t::array>::construct(j, std::move(arr));
3606 }
3607 
3608 template<typename BasicJsonType>
3609 void to_json(BasicJsonType& j, typename BasicJsonType::array_t&& arr)
3610 {
3611  external_constructor<value_t::array>::construct(j, std::move(arr));
3612 }
3613 
3614 template<typename BasicJsonType, typename CompatibleObjectType,
3615  enable_if_t<is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value and not is_basic_json<CompatibleObjectType>::value, int> = 0>
3616 void to_json(BasicJsonType& j, const CompatibleObjectType& obj)
3617 {
3618  external_constructor<value_t::object>::construct(j, obj);
3619 }
3620 
3621 template<typename BasicJsonType>
3622 void to_json(BasicJsonType& j, typename BasicJsonType::object_t&& obj)
3623 {
3624  external_constructor<value_t::object>::construct(j, std::move(obj));
3625 }
3626 
3627 template <
3628  typename BasicJsonType, typename T, std::size_t N,
3629  enable_if_t<not std::is_constructible<typename BasicJsonType::string_t,
3630  const T(&)[N]>::value,
3631  int> = 0 >
3632 void to_json(BasicJsonType& j, const T(&arr)[N])
3633 {
3634  external_constructor<value_t::array>::construct(j, arr);
3635 }
3636 
3637 template<typename BasicJsonType, typename... Args>
3638 void to_json(BasicJsonType& j, const std::pair<Args...>& p)
3639 {
3640  j = { p.first, p.second };
3641 }
3642 
3643 // for https://github.com/nlohmann/json/pull/1134
3644 template < typename BasicJsonType, typename T,
3645  enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>::value, int> = 0>
3646 void to_json(BasicJsonType& j, const T& b)
3647 {
3648  j = { {b.key(), b.value()} };
3649 }
3650 
3651 template<typename BasicJsonType, typename Tuple, std::size_t... Idx>
3652 void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence<Idx...> /*unused*/)
3653 {
3654  j = { std::get<Idx>(t)... };
3655 }
3656 
3657 template<typename BasicJsonType, typename... Args>
3658 void to_json(BasicJsonType& j, const std::tuple<Args...>& t)
3659 {
3660  to_json_tuple_impl(j, t, index_sequence_for<Args...> {});
3661 }
3662 
3663 struct to_json_fn
3664 {
3665  template<typename BasicJsonType, typename T>
3666  auto operator()(BasicJsonType& j, T&& val) const noexcept(noexcept(to_json(j, std::forward<T>(val))))
3667  -> decltype(to_json(j, std::forward<T>(val)), void())
3668  {
3669  return to_json(j, std::forward<T>(val));
3670  }
3671 };
3672 } // namespace detail
3673 
3674 /// namespace to hold default `to_json` function
3675 namespace
3676 {
3677 constexpr const auto& to_json = detail::static_const<detail::to_json_fn>::value;
3678 } // namespace
3679 } // namespace nlohmann
3680 
3681 
3682 namespace nlohmann
3683 {
3684 
3685 template<typename, typename>
3686 struct adl_serializer
3687 {
3688  /*!
3689  @brief convert a JSON value to any value type
3690 
3691  This function is usually called by the `get()` function of the
3692  @ref basic_json class (either explicit or via conversion operators).
3693 
3694  @param[in] j JSON value to read from
3695  @param[in,out] val value to write to
3696  */
3697  template<typename BasicJsonType, typename ValueType>
3698  static auto from_json(BasicJsonType&& j, ValueType& val) noexcept(
3699  noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
3700  -> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val), void())
3701  {
3702  ::nlohmann::from_json(std::forward<BasicJsonType>(j), val);
3703  }
3704 
3705  /*!
3706  @brief convert any value type to a JSON value
3707 
3708  This function is usually called by the constructors of the @ref basic_json
3709  class.
3710 
3711  @param[in,out] j JSON value to write to
3712  @param[in] val value to read from
3713  */
3714  template <typename BasicJsonType, typename ValueType>
3715  static auto to_json(BasicJsonType& j, ValueType&& val) noexcept(
3716  noexcept(::nlohmann::to_json(j, std::forward<ValueType>(val))))
3717  -> decltype(::nlohmann::to_json(j, std::forward<ValueType>(val)), void())
3718  {
3719  ::nlohmann::to_json(j, std::forward<ValueType>(val));
3720  }
3721 };
3722 
3723 } // namespace nlohmann
3724 
3725 // #include <nlohmann/detail/conversions/from_json.hpp>
3726 
3727 // #include <nlohmann/detail/conversions/to_json.hpp>
3728 
3729 // #include <nlohmann/detail/exceptions.hpp>
3730 
3731 // #include <nlohmann/detail/input/binary_reader.hpp>
3732 
3733 
3734 #include <algorithm> // generate_n
3735 #include <array> // array
3736 #include <cassert> // assert
3737 #include <cmath> // ldexp
3738 #include <cstddef> // size_t
3739 #include <cstdint> // uint8_t, uint16_t, uint32_t, uint64_t
3740 #include <cstdio> // snprintf
3741 #include <cstring> // memcpy
3742 #include <iterator> // back_inserter
3743 #include <limits> // numeric_limits
3744 #include <string> // char_traits, string
3745 #include <utility> // make_pair, move
3746 
3747 // #include <nlohmann/detail/exceptions.hpp>
3748 
3749 // #include <nlohmann/detail/input/input_adapters.hpp>
3750 
3751 
3752 #include <array> // array
3753 #include <cassert> // assert
3754 #include <cstddef> // size_t
3755 #include <cstdio> //FILE *
3756 #include <cstring> // strlen
3757 #include <istream> // istream
3758 #include <iterator> // begin, end, iterator_traits, random_access_iterator_tag, distance, next
3759 #include <memory> // shared_ptr, make_shared, addressof
3760 #include <numeric> // accumulate
3761 #include <string> // string, char_traits
3762 #include <type_traits> // enable_if, is_base_of, is_pointer, is_integral, remove_pointer
3763 #include <utility> // pair, declval
3764 
3765 // #include <nlohmann/detail/iterators/iterator_traits.hpp>
3766 
3767 // #include <nlohmann/detail/macro_scope.hpp>
3768 
3769 
3770 namespace nlohmann
3771 {
3772 namespace detail
3773 {
3774 /// the supported input formats
3775 enum class input_format_t { json, cbor, msgpack, ubjson, bson };
3776 
3777 ////////////////////
3778 // input adapters //
3779 ////////////////////
3780 
3781 /*!
3782 @brief abstract input adapter interface
3783 
3784 Produces a stream of std::char_traits<char>::int_type characters from a
3785 std::istream, a buffer, or some other input type. Accepts the return of
3786 exactly one non-EOF character for future input. The int_type characters
3787 returned consist of all valid char values as positive values (typically
3788 unsigned char), plus an EOF value outside that range, specified by the value
3789 of the function std::char_traits<char>::eof(). This value is typically -1, but
3790 could be any arbitrary value which is not a valid char value.
3791 */
3792 struct input_adapter_protocol
3793 {
3794  /// get a character [0,255] or std::char_traits<char>::eof().
3795  virtual std::char_traits<char>::int_type get_character() = 0;
3796  virtual ~input_adapter_protocol() = default;
3797 };
3798 
3799 /// a type to simplify interfaces
3800 using input_adapter_t = std::shared_ptr<input_adapter_protocol>;
3801 
3802 /*!
3803 Input adapter for stdio file access. This adapter read only 1 byte and do not use any
3804  buffer. This adapter is a very low level adapter.
3805 */
3806 class file_input_adapter : public input_adapter_protocol
3807 {
3808  public:
3810  explicit file_input_adapter(std::FILE* f) noexcept
3811  : m_file(f)
3812  {}
3813 
3814  // make class move-only
3815  file_input_adapter(const file_input_adapter&) = delete;
3816  file_input_adapter(file_input_adapter&&) = default;
3817  file_input_adapter& operator=(const file_input_adapter&) = delete;
3818  file_input_adapter& operator=(file_input_adapter&&) = default;
3819  ~file_input_adapter() override = default;
3820 
3821  std::char_traits<char>::int_type get_character() noexcept override
3822  {
3823  return std::fgetc(m_file);
3824  }
3825 
3826  private:
3827  /// the file pointer to read from
3828  std::FILE* m_file;
3829 };
3830 
3831 
3832 /*!
3833 Input adapter for a (caching) istream. Ignores a UFT Byte Order Mark at
3834 beginning of input. Does not support changing the underlying std::streambuf
3835 in mid-input. Maintains underlying std::istream and std::streambuf to support
3836 subsequent use of standard std::istream operations to process any input
3837 characters following those used in parsing the JSON input. Clears the
3838 std::istream flags; any input errors (e.g., EOF) will be detected by the first
3839 subsequent call for input from the std::istream.
3840 */
3841 class input_stream_adapter : public input_adapter_protocol
3842 {
3843  public:
3844  ~input_stream_adapter() override
3845  {
3846  // clear stream flags; we use underlying streambuf I/O, do not
3847  // maintain ifstream flags, except eof
3848  is.clear(is.rdstate() & std::ios::eofbit);
3849  }
3850 
3851  explicit input_stream_adapter(std::istream& i)
3852  : is(i), sb(*i.rdbuf())
3853  {}
3854 
3855  // delete because of pointer members
3856  input_stream_adapter(const input_stream_adapter&) = delete;
3857  input_stream_adapter& operator=(input_stream_adapter&) = delete;
3858  input_stream_adapter(input_stream_adapter&&) = delete;
3859  input_stream_adapter& operator=(input_stream_adapter&&) = delete;
3860 
3861  // std::istream/std::streambuf use std::char_traits<char>::to_int_type, to
3862  // ensure that std::char_traits<char>::eof() and the character 0xFF do not
3863  // end up as the same value, eg. 0xFFFFFFFF.
3864  std::char_traits<char>::int_type get_character() override
3865  {
3866  auto res = sb.sbumpc();
3867  // set eof manually, as we don't use the istream interface.
3868  if (res == EOF)
3869  {
3870  is.clear(is.rdstate() | std::ios::eofbit);
3871  }
3872  return res;
3873  }
3874 
3875  private:
3876  /// the associated input stream
3877  std::istream& is;
3878  std::streambuf& sb;
3879 };
3880 
3881 /// input adapter for buffer input
3882 class input_buffer_adapter : public input_adapter_protocol
3883 {
3884  public:
3886  input_buffer_adapter(const char* b, const std::size_t l) noexcept
3887  : cursor(b), limit(b + l)
3888  {}
3889 
3890  // delete because of pointer members
3891  input_buffer_adapter(const input_buffer_adapter&) = delete;
3892  input_buffer_adapter& operator=(input_buffer_adapter&) = delete;
3893  input_buffer_adapter(input_buffer_adapter&&) = delete;
3894  input_buffer_adapter& operator=(input_buffer_adapter&&) = delete;
3895  ~input_buffer_adapter() override = default;
3896 
3897  std::char_traits<char>::int_type get_character() noexcept override
3898  {
3899  if (JSON_HEDLEY_LIKELY(cursor < limit))
3900  {
3901  return std::char_traits<char>::to_int_type(*(cursor++));
3902  }
3903 
3904  return std::char_traits<char>::eof();
3905  }
3906 
3907  private:
3908  /// pointer to the current character
3909  const char* cursor;
3910  /// pointer past the last character
3911  const char* const limit;
3912 };
3913 
3914 template<typename WideStringType, size_t T>
3915 struct wide_string_input_helper
3916 {
3917  // UTF-32
3918  static void fill_buffer(const WideStringType& str,
3919  size_t& current_wchar,
3920  std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
3921  size_t& utf8_bytes_index,
3922  size_t& utf8_bytes_filled)
3923  {
3924  utf8_bytes_index = 0;
3925 
3926  if (current_wchar == str.size())
3927  {
3928  utf8_bytes[0] = std::char_traits<char>::eof();
3929  utf8_bytes_filled = 1;
3930  }
3931  else
3932  {
3933  // get the current character
3934  const auto wc = static_cast<unsigned int>(str[current_wchar++]);
3935 
3936  // UTF-32 to UTF-8 encoding
3937  if (wc < 0x80)
3938  {
3939  utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(wc);
3940  utf8_bytes_filled = 1;
3941  }
3942  else if (wc <= 0x7FF)
3943  {
3944  utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xC0u | ((wc >> 6u) & 0x1Fu));
3945  utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | (wc & 0x3Fu));
3946  utf8_bytes_filled = 2;
3947  }
3948  else if (wc <= 0xFFFF)
3949  {
3950  utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xE0u | ((wc >> 12u) & 0x0Fu));
3951  utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | ((wc >> 6u) & 0x3Fu));
3952  utf8_bytes[2] = static_cast<std::char_traits<char>::int_type>(0x80u | (wc & 0x3Fu));
3953  utf8_bytes_filled = 3;
3954  }
3955  else if (wc <= 0x10FFFF)
3956  {
3957  utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xF0u | ((wc >> 18u) & 0x07u));
3958  utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | ((wc >> 12u) & 0x3Fu));
3959  utf8_bytes[2] = static_cast<std::char_traits<char>::int_type>(0x80u | ((wc >> 6u) & 0x3Fu));
3960  utf8_bytes[3] = static_cast<std::char_traits<char>::int_type>(0x80u | (wc & 0x3Fu));
3961  utf8_bytes_filled = 4;
3962  }
3963  else
3964  {
3965  // unknown character
3966  utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(wc);
3967  utf8_bytes_filled = 1;
3968  }
3969  }
3970  }
3971 };
3972 
3973 template<typename WideStringType>
3974 struct wide_string_input_helper<WideStringType, 2>
3975 {
3976  // UTF-16
3977  static void fill_buffer(const WideStringType& str,
3978  size_t& current_wchar,
3979  std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
3980  size_t& utf8_bytes_index,
3981  size_t& utf8_bytes_filled)
3982  {
3983  utf8_bytes_index = 0;
3984 
3985  if (current_wchar == str.size())
3986  {
3987  utf8_bytes[0] = std::char_traits<char>::eof();
3988  utf8_bytes_filled = 1;
3989  }
3990  else
3991  {
3992  // get the current character
3993  const auto wc = static_cast<unsigned int>(str[current_wchar++]);
3994 
3995  // UTF-16 to UTF-8 encoding
3996  if (wc < 0x80)
3997  {
3998  utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(wc);
3999  utf8_bytes_filled = 1;
4000  }
4001  else if (wc <= 0x7FF)
4002  {
4003  utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xC0u | ((wc >> 6u)));
4004  utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | (wc & 0x3Fu));
4005  utf8_bytes_filled = 2;
4006  }
4007  else if (0xD800 > wc or wc >= 0xE000)
4008  {
4009  utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xE0u | ((wc >> 12u)));
4010  utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | ((wc >> 6u) & 0x3Fu));
4011  utf8_bytes[2] = static_cast<std::char_traits<char>::int_type>(0x80u | (wc & 0x3Fu));
4012  utf8_bytes_filled = 3;
4013  }
4014  else
4015  {
4016  if (current_wchar < str.size())
4017  {
4018  const auto wc2 = static_cast<unsigned int>(str[current_wchar++]);
4019  const auto charcode = 0x10000u + (((wc & 0x3FFu) << 10u) | (wc2 & 0x3FFu));
4020  utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xF0u | (charcode >> 18u));
4021  utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | ((charcode >> 12u) & 0x3Fu));
4022  utf8_bytes[2] = static_cast<std::char_traits<char>::int_type>(0x80u | ((charcode >> 6u) & 0x3Fu));
4023  utf8_bytes[3] = static_cast<std::char_traits<char>::int_type>(0x80u | (charcode & 0x3Fu));
4024  utf8_bytes_filled = 4;
4025  }
4026  else
4027  {
4028  // unknown character
4029  ++current_wchar;
4030  utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(wc);
4031  utf8_bytes_filled = 1;
4032  }
4033  }
4034  }
4035  }
4036 };
4037 
4038 template<typename WideStringType>
4039 class wide_string_input_adapter : public input_adapter_protocol
4040 {
4041  public:
4042  explicit wide_string_input_adapter(const WideStringType& w) noexcept
4043  : str(w)
4044  {}
4045 
4046  std::char_traits<char>::int_type get_character() noexcept override
4047  {
4048  // check if buffer needs to be filled
4049  if (utf8_bytes_index == utf8_bytes_filled)
4050  {
4051  fill_buffer<sizeof(typename WideStringType::value_type)>();
4052 
4053  assert(utf8_bytes_filled > 0);
4054  assert(utf8_bytes_index == 0);
4055  }
4056 
4057  // use buffer
4058  assert(utf8_bytes_filled > 0);
4059  assert(utf8_bytes_index < utf8_bytes_filled);
4060  return utf8_bytes[utf8_bytes_index++];
4061  }
4062 
4063  private:
4064  template<size_t T>
4065  void fill_buffer()
4066  {
4067  wide_string_input_helper<WideStringType, T>::fill_buffer(str, current_wchar, utf8_bytes, utf8_bytes_index, utf8_bytes_filled);
4068  }
4069 
4070  /// the wstring to process
4071  const WideStringType& str;
4072 
4073  /// index of the current wchar in str
4074  std::size_t current_wchar = 0;
4075 
4076  /// a buffer for UTF-8 bytes
4077  std::array<std::char_traits<char>::int_type, 4> utf8_bytes = {{0, 0, 0, 0}};
4078 
4079  /// index to the utf8_codes array for the next valid byte
4080  std::size_t utf8_bytes_index = 0;
4081  /// number of valid bytes in the utf8_codes array
4082  std::size_t utf8_bytes_filled = 0;
4083 };
4084 
4085 class input_adapter
4086 {
4087  public:
4088  // native support
4090  input_adapter(std::FILE* file)
4091  : ia(std::make_shared<file_input_adapter>(file)) {}
4092  /// input adapter for input stream
4093  input_adapter(std::istream& i)
4094  : ia(std::make_shared<input_stream_adapter>(i)) {}
4095 
4096  /// input adapter for input stream
4097  input_adapter(std::istream&& i)
4098  : ia(std::make_shared<input_stream_adapter>(i)) {}
4099 
4100  input_adapter(const std::wstring& ws)
4101  : ia(std::make_shared<wide_string_input_adapter<std::wstring>>(ws)) {}
4102 
4103  input_adapter(const std::u16string& ws)
4104  : ia(std::make_shared<wide_string_input_adapter<std::u16string>>(ws)) {}
4105 
4106  input_adapter(const std::u32string& ws)
4107  : ia(std::make_shared<wide_string_input_adapter<std::u32string>>(ws)) {}
4108 
4109  /// input adapter for buffer
4110  template<typename CharT,
4111  typename std::enable_if<
4112  std::is_pointer<CharT>::value and
4113  std::is_integral<typename std::remove_pointer<CharT>::type>::value and
4114  sizeof(typename std::remove_pointer<CharT>::type) == 1,
4115  int>::type = 0>
4116  input_adapter(CharT b, std::size_t l)
4117  : ia(std::make_shared<input_buffer_adapter>(reinterpret_cast<const char*>(b), l)) {}
4118 
4119  // derived support
4120 
4121  /// input adapter for string literal
4122  template<typename CharT,
4123  typename std::enable_if<
4124  std::is_pointer<CharT>::value and
4125  std::is_integral<typename std::remove_pointer<CharT>::type>::value and
4126  sizeof(typename std::remove_pointer<CharT>::type) == 1,
4127  int>::type = 0>
4128  input_adapter(CharT b)
4129  : input_adapter(reinterpret_cast<const char*>(b),
4130  std::strlen(reinterpret_cast<const char*>(b))) {}
4131 
4132  /// input adapter for iterator range with contiguous storage
4133  template<class IteratorType,
4134  typename std::enable_if<
4135  std::is_same<typename iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>::value,
4136  int>::type = 0>
4137  input_adapter(IteratorType first, IteratorType last)
4138  {
4139 #ifndef NDEBUG
4140  // assertion to check that the iterator range is indeed contiguous,
4141  // see http://stackoverflow.com/a/35008842/266378 for more discussion
4142  const auto is_contiguous = std::accumulate(
4143  first, last, std::pair<bool, int>(true, 0),
4144  [&first](std::pair<bool, int> res, decltype(*first) val)
4145  {
4146  res.first &= (val == *(std::next(std::addressof(*first), res.second++)));
4147  return res;
4148  }).first;
4149  assert(is_contiguous);
4150 #endif
4151 
4152  // assertion to check that each element is 1 byte long
4153  static_assert(
4154  sizeof(typename iterator_traits<IteratorType>::value_type) == 1,
4155  "each element in the iterator range must have the size of 1 byte");
4156 
4157  const auto len = static_cast<size_t>(std::distance(first, last));
4158  if (JSON_HEDLEY_LIKELY(len > 0))
4159  {
4160  // there is at least one element: use the address of first
4161  ia = std::make_shared<input_buffer_adapter>(reinterpret_cast<const char*>(&(*first)), len);
4162  }
4163  else
4164  {
4165  // the address of first cannot be used: use nullptr
4166  ia = std::make_shared<input_buffer_adapter>(nullptr, len);
4167  }
4168  }
4169 
4170  /// input adapter for array
4171  template<class T, std::size_t N>
4172  input_adapter(T (&array)[N])
4173  : input_adapter(std::begin(array), std::end(array)) {}
4174 
4175  /// input adapter for contiguous container
4176  template<class ContiguousContainer, typename
4177  std::enable_if<not std::is_pointer<ContiguousContainer>::value and
4178  std::is_base_of<std::random_access_iterator_tag, typename iterator_traits<decltype(std::begin(std::declval<ContiguousContainer const>()))>::iterator_category>::value,
4179  int>::type = 0>
4180  input_adapter(const ContiguousContainer& c)
4181  : input_adapter(std::begin(c), std::end(c)) {}
4182 
4183  operator input_adapter_t()
4184  {
4185  return ia;
4186  }
4187 
4188  private:
4189  /// the actual adapter
4190  input_adapter_t ia = nullptr;
4191 };
4192 } // namespace detail
4193 } // namespace nlohmann
4194 
4195 // #include <nlohmann/detail/input/json_sax.hpp>
4196 
4197 
4198 #include <cassert> // assert
4199 #include <cstddef>
4200 #include <string> // string
4201 #include <utility> // move
4202 #include <vector> // vector
4203 
4204 // #include <nlohmann/detail/exceptions.hpp>
4205 
4206 // #include <nlohmann/detail/macro_scope.hpp>
4207 
4208 
4209 namespace nlohmann
4210 {
4211 
4212 /*!
4213 @brief SAX interface
4214 
4215 This class describes the SAX interface used by @ref nlohmann::json::sax_parse.
4216 Each function is called in different situations while the input is parsed. The
4217 boolean return value informs the parser whether to continue processing the
4218 input.
4219 */
4220 template<typename BasicJsonType>
4221 struct json_sax
4222 {
4223  /// type for (signed) integers
4224  using number_integer_t = typename BasicJsonType::number_integer_t;
4225  /// type for unsigned integers
4226  using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
4227  /// type for floating-point numbers
4228  using number_float_t = typename BasicJsonType::number_float_t;
4229  /// type for strings
4230  using string_t = typename BasicJsonType::string_t;
4231 
4232  /*!
4233  @brief a null value was read
4234  @return whether parsing should proceed
4235  */
4236  virtual bool null() = 0;
4237 
4238  /*!
4239  @brief a boolean value was read
4240  @param[in] val boolean value
4241  @return whether parsing should proceed
4242  */
4243  virtual bool boolean(bool val) = 0;
4244 
4245  /*!
4246  @brief an integer number was read
4247  @param[in] val integer value
4248  @return whether parsing should proceed
4249  */
4250  virtual bool number_integer(number_integer_t val) = 0;
4251 
4252  /*!
4253  @brief an unsigned integer number was read
4254  @param[in] val unsigned integer value
4255  @return whether parsing should proceed
4256  */
4257  virtual bool number_unsigned(number_unsigned_t val) = 0;
4258 
4259  /*!
4260  @brief an floating-point number was read
4261  @param[in] val floating-point value
4262  @param[in] s raw token value
4263  @return whether parsing should proceed
4264  */
4265  virtual bool number_float(number_float_t val, const string_t& s) = 0;
4266 
4267  /*!
4268  @brief a string was read
4269  @param[in] val string value
4270  @return whether parsing should proceed
4271  @note It is safe to move the passed string.
4272  */
4273  virtual bool string(string_t& val) = 0;
4274 
4275  /*!
4276  @brief the beginning of an object was read
4277  @param[in] elements number of object elements or -1 if unknown
4278  @return whether parsing should proceed
4279  @note binary formats may report the number of elements
4280  */
4281  virtual bool start_object(std::size_t elements) = 0;
4282 
4283  /*!
4284  @brief an object key was read
4285  @param[in] val object key
4286  @return whether parsing should proceed
4287  @note It is safe to move the passed string.
4288  */
4289  virtual bool key(string_t& val) = 0;
4290 
4291  /*!
4292  @brief the end of an object was read
4293  @return whether parsing should proceed
4294  */
4295  virtual bool end_object() = 0;
4296 
4297  /*!
4298  @brief the beginning of an array was read
4299  @param[in] elements number of array elements or -1 if unknown
4300  @return whether parsing should proceed
4301  @note binary formats may report the number of elements
4302  */
4303  virtual bool start_array(std::size_t elements) = 0;
4304 
4305  /*!
4306  @brief the end of an array was read
4307  @return whether parsing should proceed
4308  */
4309  virtual bool end_array() = 0;
4310 
4311  /*!
4312  @brief a parse error occurred
4313  @param[in] position the position in the input where the error occurs
4314  @param[in] last_token the last read token
4315  @param[in] ex an exception object describing the error
4316  @return whether parsing should proceed (must return false)
4317  */
4318  virtual bool parse_error(std::size_t position,
4319  const std::string& last_token,
4320  const detail::exception& ex) = 0;
4321 
4322  virtual ~json_sax() = default;
4323 };
4324 
4325 
4326 namespace detail
4327 {
4328 /*!
4329 @brief SAX implementation to create a JSON value from SAX events
4330 
4331 This class implements the @ref json_sax interface and processes the SAX events
4332 to create a JSON value which makes it basically a DOM parser. The structure or
4333 hierarchy of the JSON value is managed by the stack `ref_stack` which contains
4334 a pointer to the respective array or object for each recursion depth.
4335 
4336 After successful parsing, the value that is passed by reference to the
4337 constructor contains the parsed value.
4338 
4339 @tparam BasicJsonType the JSON type
4340 */
4341 template<typename BasicJsonType>
4342 class json_sax_dom_parser
4343 {
4344  public:
4345  using number_integer_t = typename BasicJsonType::number_integer_t;
4346  using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
4347  using number_float_t = typename BasicJsonType::number_float_t;
4348  using string_t = typename BasicJsonType::string_t;
4349 
4350  /*!
4351  @param[in, out] r reference to a JSON value that is manipulated while
4352  parsing
4353  @param[in] allow_exceptions_ whether parse errors yield exceptions
4354  */
4355  explicit json_sax_dom_parser(BasicJsonType& r, const bool allow_exceptions_ = true)
4356  : root(r), allow_exceptions(allow_exceptions_)
4357  {}
4358 
4359  // make class move-only
4360  json_sax_dom_parser(const json_sax_dom_parser&) = delete;
4361  json_sax_dom_parser(json_sax_dom_parser&&) = default;
4362  json_sax_dom_parser& operator=(const json_sax_dom_parser&) = delete;
4363  json_sax_dom_parser& operator=(json_sax_dom_parser&&) = default;
4364  ~json_sax_dom_parser() = default;
4365 
4366  bool null()
4367  {
4368  handle_value(nullptr);
4369  return true;
4370  }
4371 
4372  bool boolean(bool val)
4373  {
4374  handle_value(val);
4375  return true;
4376  }
4377 
4378  bool number_integer(number_integer_t val)
4379  {
4380  handle_value(val);
4381  return true;
4382  }
4383 
4384  bool number_unsigned(number_unsigned_t val)
4385  {
4386  handle_value(val);
4387  return true;
4388  }
4389 
4390  bool number_float(number_float_t val, const string_t& /*unused*/)
4391  {
4392  handle_value(val);
4393  return true;
4394  }
4395 
4396  bool string(string_t& val)
4397  {
4398  handle_value(val);
4399  return true;
4400  }
4401 
4402  bool start_object(std::size_t len)
4403  {
4404  ref_stack.push_back(handle_value(BasicJsonType::value_t::object));
4405 
4406  if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
4407  {
4408  JSON_THROW(out_of_range::create(408,
4409  "excessive object size: " + std::to_string(len)));
4410  }
4411 
4412  return true;
4413  }
4414 
4415  bool key(string_t& val)
4416  {
4417  // add null at given key and store the reference for later
4418  object_element = &(ref_stack.back()->m_value.object->operator[](val));
4419  return true;
4420  }
4421 
4422  bool end_object()
4423  {
4424  ref_stack.pop_back();
4425  return true;
4426  }
4427 
4428  bool start_array(std::size_t len)
4429  {
4430  ref_stack.push_back(handle_value(BasicJsonType::value_t::array));
4431 
4432  if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
4433  {
4434  JSON_THROW(out_of_range::create(408,
4435  "excessive array size: " + std::to_string(len)));
4436  }
4437 
4438  return true;
4439  }
4440 
4441  bool end_array()
4442  {
4443  ref_stack.pop_back();
4444  return true;
4445  }
4446 
4447  bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/,
4448  const detail::exception& ex)
4449  {
4450  errored = true;
4451  if (allow_exceptions)
4452  {
4453  // determine the proper exception type from the id
4454  switch ((ex.id / 100) % 100)
4455  {
4456  case 1:
4457  JSON_THROW(*static_cast<const detail::parse_error*>(&ex));
4458  case 4:
4459  JSON_THROW(*static_cast<const detail::out_of_range*>(&ex));
4460  // LCOV_EXCL_START
4461  case 2:
4462  JSON_THROW(*static_cast<const detail::invalid_iterator*>(&ex));
4463  case 3:
4464  JSON_THROW(*static_cast<const detail::type_error*>(&ex));
4465  case 5:
4466  JSON_THROW(*static_cast<const detail::other_error*>(&ex));
4467  default:
4468  assert(false);
4469  // LCOV_EXCL_STOP
4470  }
4471  }
4472  return false;
4473  }
4474 
4475  constexpr bool is_errored() const
4476  {
4477  return errored;
4478  }
4479 
4480  private:
4481  /*!
4482  @invariant If the ref stack is empty, then the passed value will be the new
4483  root.
4484  @invariant If the ref stack contains a value, then it is an array or an
4485  object to which we can add elements
4486  */
4487  template<typename Value>
4488 
4489  BasicJsonType* handle_value(Value&& v)
4490  {
4491  if (ref_stack.empty())
4492  {
4493  root = BasicJsonType(std::forward<Value>(v));
4494  return &root;
4495  }
4496 
4497  assert(ref_stack.back()->is_array() or ref_stack.back()->is_object());
4498 
4499  if (ref_stack.back()->is_array())
4500  {
4501  ref_stack.back()->m_value.array->emplace_back(std::forward<Value>(v));
4502  return &(ref_stack.back()->m_value.array->back());
4503  }
4504 
4505  assert(ref_stack.back()->is_object());
4506  assert(object_element);
4507  *object_element = BasicJsonType(std::forward<Value>(v));
4508  return object_element;
4509  }
4510 
4511  /// the parsed JSON value
4512  BasicJsonType& root;
4513  /// stack to model hierarchy of values
4514  std::vector<BasicJsonType*> ref_stack {};
4515  /// helper to hold the reference for the next object element
4516  BasicJsonType* object_element = nullptr;
4517  /// whether a syntax error occurred
4518  bool errored = false;
4519  /// whether to throw exceptions in case of errors
4520  const bool allow_exceptions = true;
4521 };
4522 
4523 template<typename BasicJsonType>
4524 class json_sax_dom_callback_parser
4525 {
4526  public:
4527  using number_integer_t = typename BasicJsonType::number_integer_t;
4528  using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
4529  using number_float_t = typename BasicJsonType::number_float_t;
4530  using string_t = typename BasicJsonType::string_t;
4531  using parser_callback_t = typename BasicJsonType::parser_callback_t;
4532  using parse_event_t = typename BasicJsonType::parse_event_t;
4533 
4534  json_sax_dom_callback_parser(BasicJsonType& r,
4535  const parser_callback_t cb,
4536  const bool allow_exceptions_ = true)
4537  : root(r), callback(cb), allow_exceptions(allow_exceptions_)
4538  {
4539  keep_stack.push_back(true);
4540  }
4541 
4542  // make class move-only
4543  json_sax_dom_callback_parser(const json_sax_dom_callback_parser&) = delete;
4544  json_sax_dom_callback_parser(json_sax_dom_callback_parser&&) = default;
4545  json_sax_dom_callback_parser& operator=(const json_sax_dom_callback_parser&) = delete;
4546  json_sax_dom_callback_parser& operator=(json_sax_dom_callback_parser&&) = default;
4547  ~json_sax_dom_callback_parser() = default;
4548 
4549  bool null()
4550  {
4551  handle_value(nullptr);
4552  return true;
4553  }
4554 
4555  bool boolean(bool val)
4556  {
4557  handle_value(val);
4558  return true;
4559  }
4560 
4561  bool number_integer(number_integer_t val)
4562  {
4563  handle_value(val);
4564  return true;
4565  }
4566 
4567  bool number_unsigned(number_unsigned_t val)
4568  {
4569  handle_value(val);
4570  return true;
4571  }
4572 
4573  bool number_float(number_float_t val, const string_t& /*unused*/)
4574  {
4575  handle_value(val);
4576  return true;
4577  }
4578 
4579  bool string(string_t& val)
4580  {
4581  handle_value(val);
4582  return true;
4583  }
4584 
4585  bool start_object(std::size_t len)
4586  {
4587  // check callback for object start
4588  const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::object_start, discarded);
4589  keep_stack.push_back(keep);
4590 
4591  auto val = handle_value(BasicJsonType::value_t::object, true);
4592  ref_stack.push_back(val.second);
4593 
4594  // check object limit
4595  if (ref_stack.back() and JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
4596  {
4597  JSON_THROW(out_of_range::create(408, "excessive object size: " + std::to_string(len)));
4598  }
4599 
4600  return true;
4601  }
4602 
4603  bool key(string_t& val)
4604  {
4605  BasicJsonType k = BasicJsonType(val);
4606 
4607  // check callback for key
4608  const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::key, k);
4609  key_keep_stack.push_back(keep);
4610 
4611  // add discarded value at given key and store the reference for later
4612  if (keep and ref_stack.back())
4613  {
4614  object_element = &(ref_stack.back()->m_value.object->operator[](val) = discarded);
4615  }
4616 
4617  return true;
4618  }
4619 
4620  bool end_object()
4621  {
4622  if (ref_stack.back() and not callback(static_cast<int>(ref_stack.size()) - 1, parse_event_t::object_end, *ref_stack.back()))
4623  {
4624  // discard object
4625  *ref_stack.back() = discarded;
4626  }
4627 
4628  assert(not ref_stack.empty());
4629  assert(not keep_stack.empty());
4630  ref_stack.pop_back();
4631  keep_stack.pop_back();
4632 
4633  if (not ref_stack.empty() and ref_stack.back() and ref_stack.back()->is_object())
4634  {
4635  // remove discarded value
4636  for (auto it = ref_stack.back()->begin(); it != ref_stack.back()->end(); ++it)
4637  {
4638  if (it->is_discarded())
4639  {
4640  ref_stack.back()->erase(it);
4641  break;
4642  }
4643  }
4644  }
4645 
4646  return true;
4647  }
4648 
4649  bool start_array(std::size_t len)
4650  {
4651  const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::array_start, discarded);
4652  keep_stack.push_back(keep);
4653 
4654  auto val = handle_value(BasicJsonType::value_t::array, true);
4655  ref_stack.push_back(val.second);
4656 
4657  // check array limit
4658  if (ref_stack.back() and JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
4659  {
4660  JSON_THROW(out_of_range::create(408, "excessive array size: " + std::to_string(len)));
4661  }
4662 
4663  return true;
4664  }
4665 
4666  bool end_array()
4667  {
4668  bool keep = true;
4669 
4670  if (ref_stack.back())
4671  {
4672  keep = callback(static_cast<int>(ref_stack.size()) - 1, parse_event_t::array_end, *ref_stack.back());
4673  if (not keep)
4674  {
4675  // discard array
4676