35 #ifndef WPIUTIL_JSON_H
36 #define WPIUTIL_JSON_H
38 #define NLOHMANN_JSON_VERSION_MAJOR 3
39 #define NLOHMANN_JSON_VERSION_MINOR 1
40 #define NLOHMANN_JSON_VERSION_PATCH 2
51 #include <initializer_list>
58 #include <type_traits>
62 #include "wpi/ArrayRef.h"
63 #include "wpi/StringMap.h"
64 #include "wpi/StringRef.h"
65 #include "wpi/Twine.h"
82 template<
typename =
void,
typename =
void>
110 #if defined(__clang__)
111 #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400
112 #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers"
114 #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER))
115 #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40900
116 #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers"
121 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
122 #pragma GCC diagnostic push
123 #pragma GCC diagnostic ignored "-Wfloat-equal"
127 #if defined(__clang__)
128 #pragma GCC diagnostic push
129 #pragma GCC diagnostic ignored "-Wdocumentation"
133 #if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
134 #define JSON_THROW(exception) throw exception
136 #define JSON_CATCH(exception) catch(exception)
138 #define JSON_THROW(exception) std::abort()
139 #define JSON_TRY if(true)
140 #define JSON_CATCH(exception) if(false)
144 #if defined(JSON_THROW_USER)
146 #define JSON_THROW JSON_THROW_USER
148 #if defined(JSON_TRY_USER)
150 #define JSON_TRY JSON_TRY_USER
152 #if defined(JSON_CATCH_USER)
154 #define JSON_CATCH JSON_CATCH_USER
158 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
159 #define JSON_LIKELY(x) __builtin_expect(!!(x), 1)
160 #define JSON_UNLIKELY(x) __builtin_expect(!!(x), 0)
162 #define JSON_LIKELY(x) x
163 #define JSON_UNLIKELY(x) x
167 #if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464
168 #define JSON_HAS_CPP_17
169 #define JSON_HAS_CPP_14
170 #elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
171 #define JSON_HAS_CPP_14
184 #define NLOHMANN_JSON_HAS_HELPER(type) \
185 template<typename T> struct has_##type { \
187 template<typename U, typename = typename U::type> \
188 static int detect(U &&); \
189 static void detect(...); \
191 static constexpr bool value = \
192 std::is_integral<decltype(detect(std::declval<T>()))>::value; \
211 template<
typename>
struct is_json : std::false_type {};
216 template<
bool B,
typename T =
void>
217 using enable_if_t =
typename std::enable_if<B, T>::type;
220 using uncvref_t =
typename std::remove_cv<typename std::remove_reference<T>::type>::type;
224 template<std::size_t... Ints>
228 using value_type = std::size_t;
229 static constexpr std::size_t size() noexcept
231 return sizeof...(Ints);
235 template<
class Sequence1,
class Sequence2>
238 template<std::size_t... I1, std::size_t... I2>
242 template<std::
size_t N>
245 typename make_index_sequence < N - N / 2 >::type > {};
250 template<
typename... Ts>
268 template<
class B1,
class... Bn>
269 struct conjunction<B1, Bn...> : std::conditional<bool(B1::value), conjunction<Bn...>, B1>::type {};
271 template<
class B>
struct negation : std::integral_constant<bool, not B::value> {};
283 template <
typename T,
typename =
void>
286 template <
typename T>
289 NLOHMANN_JSON_HAS_HELPER(mapped_type);
290 NLOHMANN_JSON_HAS_HELPER(key_type);
291 NLOHMANN_JSON_HAS_HELPER(value_type);
292 NLOHMANN_JSON_HAS_HELPER(iterator);
294 template<
bool B,
class RealType,
class CompatibleObjectType>
297 template<
class RealType,
class CompatibleObjectType>
300 static constexpr
auto value =
301 std::is_constructible<StringRef, typename CompatibleObjectType::key_type>::value and
302 std::is_constructible<typename RealType::mapped_type, typename CompatibleObjectType::mapped_type>::value;
305 template<
class BasicJsonType,
class CompatibleObjectType>
310 has_mapped_type<CompatibleObjectType>,
311 has_key_type<CompatibleObjectType>>::value,
312 typename BasicJsonType::object_t, CompatibleObjectType >::value;
315 template<
typename BasicJsonType,
typename T>
318 static auto constexpr value = std::is_same<T, typename BasicJsonType::iterator>::value or
319 std::is_same<T, typename BasicJsonType::const_iterator>::value or
320 std::is_same<T, typename BasicJsonType::reverse_iterator>::value or
321 std::is_same<T, typename BasicJsonType::const_reverse_iterator>::value;
324 template<
class BasicJsonType,
class CompatibleArrayType>
327 static auto constexpr value =
330 BasicJsonType, CompatibleArrayType>>,
332 CompatibleArrayType>>,
334 has_value_type<CompatibleArrayType>,
335 has_iterator<CompatibleArrayType>>::value;
338 template<
bool,
typename,
typename>
341 template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
345 using RealLimits = std::numeric_limits<RealIntegerType>;
346 using CompatibleLimits = std::numeric_limits<CompatibleNumberIntegerType>;
348 static constexpr
auto value =
349 std::is_constructible<RealIntegerType, CompatibleNumberIntegerType>::value and
350 CompatibleLimits::is_integer and
351 RealLimits::is_signed == CompatibleLimits::is_signed;
354 template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
357 static constexpr
auto value =
359 std::is_integral<CompatibleNumberIntegerType>::value and
360 not std::is_same<bool, CompatibleNumberIntegerType>::value,
361 RealIntegerType, CompatibleNumberIntegerType > ::value;
365 template<
typename BasicJsonType,
typename T>
370 template<typename U, typename = enable_if_t<std::is_same<void, decltype(uncvref_t<U>::from_json(
371 std::declval<BasicJsonType>(), std::declval<T&>()))>::value>>
372 static int detect(U&&);
373 static void detect(...);
376 static constexpr
bool value = std::is_integral<decltype(
377 detect(std::declval<
typename BasicJsonType::template json_serializer<T, void>>()))>::value;
382 template<
typename BasicJsonType,
typename T>
388 typename = enable_if_t<std::is_same<
389 T, decltype(uncvref_t<U>::from_json(std::declval<BasicJsonType>()))>::value >>
390 static int detect(U&&);
391 static void detect(...);
394 static constexpr
bool value = std::is_integral<decltype(detect(
395 std::declval<
typename BasicJsonType::template json_serializer<T, void>>()))>::value;
399 template<
typename BasicJsonType,
typename T>
403 template<typename U, typename = decltype(uncvref_t<U>::to_json(
404 std::declval<BasicJsonType&>(), std::declval<T>()))>
405 static int detect(U&&);
406 static void detect(...);
409 static constexpr
bool value = std::is_integral<decltype(detect(
410 std::declval<
typename BasicJsonType::template json_serializer<T, void>>()))>::value;
413 template <
typename BasicJsonType,
typename CompatibleCompleteType>
416 static constexpr
bool value =
417 not std::is_base_of<std::istream, CompatibleCompleteType>::value and
423 template <
typename BasicJsonType,
typename CompatibleType>
426 is_compatible_complete_type<BasicJsonType, CompatibleType>>
434 static constexpr T value{};
476 const char*
what() const noexcept
override
489 std::runtime_error m;
561 :
exception(id_, what_arg), byte(byte_) {}
785 static constexpr std::array<std::uint8_t, 8> order = {{
791 const auto l_index =
static_cast<std::size_t
>(lhs);
792 const auto r_index =
static_cast<std::size_t
>(rhs);
793 return l_index < order.size() and r_index < order.size() and order[l_index] < order[r_index];
797 template<
typename BasicJsonType,
typename ArithmeticType,
798 enable_if_t<std::is_arithmetic<ArithmeticType>::value and
799 not std::is_same<ArithmeticType, bool>::value,
801 void get_arithmetic_value(
const BasicJsonType& j, ArithmeticType& val)
803 switch (static_cast<value_t>(j))
807 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const uint64_t*>());
812 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const int64_t*>());
817 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const double*>());
822 JSON_THROW(type_error::create(302,
"type must be number, but is " + Twine(j.type_name())));
826 template<
typename BasicJsonType>
827 void from_json(
const BasicJsonType& j,
bool& b)
829 if (JSON_UNLIKELY(not j.is_boolean()))
831 JSON_THROW(type_error::create(302,
"type must be boolean, but is " + Twine(j.type_name())));
833 b = *j.template get_ptr<const bool*>();
836 template<
typename BasicJsonType>
837 void from_json(
const BasicJsonType& j,
std::string& s)
839 if (JSON_UNLIKELY(not j.is_string()))
841 JSON_THROW(type_error::create(302,
"type must be string, but is " + Twine(j.type_name())));
843 s = *j.template get_ptr<const std::string*>();
846 template<
typename BasicJsonType>
847 void from_json(
const BasicJsonType& j,
double& val)
849 get_arithmetic_value(j, val);
852 template<
typename BasicJsonType>
853 void from_json(
const BasicJsonType& j, uint64_t& val)
855 get_arithmetic_value(j, val);
858 template<
typename BasicJsonType>
859 void from_json(
const BasicJsonType& j, int64_t& val)
861 get_arithmetic_value(j, val);
864 template<
typename BasicJsonType,
typename EnumType,
865 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
866 void from_json(
const BasicJsonType& j, EnumType& e)
868 typename std::underlying_type<EnumType>::type val;
869 get_arithmetic_value(j, val);
870 e =
static_cast<EnumType
>(val);
873 template<
typename BasicJsonType>
874 void from_json(
const BasicJsonType& j,
typename BasicJsonType::array_t& arr)
876 if (JSON_UNLIKELY(not j.is_array()))
878 JSON_THROW(type_error::create(302,
"type must be array, but is " + Twine(j.type_name())));
880 arr = *j.template get_ptr<const typename BasicJsonType::array_t*>();
883 template<
typename BasicJsonType,
typename CompatibleArrayType>
884 void from_json_array_impl(
const BasicJsonType& j, CompatibleArrayType& arr, priority_tag<0> )
888 std::transform(j.begin(), j.end(),
889 std::inserter(arr, end(arr)), [](
const BasicJsonType & i)
893 return i.template get<typename CompatibleArrayType::value_type>();
897 template<
typename BasicJsonType,
typename CompatibleArrayType>
898 auto from_json_array_impl(
const BasicJsonType& j, CompatibleArrayType& arr, priority_tag<1> )
900 arr.reserve(std::declval<typename CompatibleArrayType::size_type>()),
905 arr.reserve(j.size());
906 std::transform(j.begin(), j.end(),
907 std::inserter(arr, end(arr)), [](
const BasicJsonType & i)
911 return i.template get<typename CompatibleArrayType::value_type>();
915 template<
typename BasicJsonType,
typename T, std::
size_t N>
916 void from_json_array_impl(
const BasicJsonType& j, std::array<T, N>& arr, priority_tag<2> )
918 for (std::size_t i = 0; i < N; ++i)
920 arr[i] = j.at(i).template get<T>();
925 typename BasicJsonType,
typename CompatibleArrayType,
927 is_compatible_array_type<BasicJsonType, CompatibleArrayType>::value and
928 not std::is_same<
typename BasicJsonType::array_t,
929 CompatibleArrayType>::value and
930 std::is_constructible <
931 BasicJsonType,
typename CompatibleArrayType::value_type >::value,
933 void from_json(
const BasicJsonType& j, CompatibleArrayType& arr)
935 if (JSON_UNLIKELY(not j.is_array()))
937 JSON_THROW(type_error::create(302,
"type must be array, but is " +
938 Twine(j.type_name())));
941 from_json_array_impl(j, arr, priority_tag<2> {});
944 template<
typename BasicJsonType>
946 void from_json(
const BasicJsonType& j,
typename BasicJsonType::object_t& obj)
950 JSON_THROW(type_error::create(302,
"type must be object, but is " + Twine(j.type_name())));
953 auto inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
954 for (
const auto& i : *inner_object) {
955 obj.try_emplace(i.first(), i.second);
959 template<
typename BasicJsonType,
typename CompatibleObjectType,
960 enable_if_t<is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value and
961 not std::is_same<typename BasicJsonType::object_t, CompatibleObjectType>::value,
int> = 0>
962 void from_json(
const BasicJsonType& j, CompatibleObjectType& obj)
964 if (JSON_UNLIKELY(not j.is_object()))
966 JSON_THROW(type_error::create(302,
"type must be object, but is " + Twine(j.type_name())));
969 auto inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
972 using value_type =
typename CompatibleObjectType::value_type;
973 std::vector<value_type> v;
975 for (
const auto& p : *inner_object)
980 .template get<typename CompatibleObjectType::mapped_type>());
985 obj = CompatibleObjectType(std::make_move_iterator(begin(v)),
986 std::make_move_iterator(end(v)));
993 template<
typename BasicJsonType,
typename ArithmeticType,
995 std::is_arithmetic<ArithmeticType>::value and
996 not std::is_same<ArithmeticType, uint64_t>::value and
997 not std::is_same<ArithmeticType, int64_t>::value and
998 not std::is_same<ArithmeticType, double>::value and
999 not std::is_same<ArithmeticType, bool>::value,
1001 void from_json(
const BasicJsonType& j, ArithmeticType& val)
1003 switch (static_cast<value_t>(j))
1007 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const uint64_t*>());
1012 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const int64_t*>());
1017 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const double*>());
1022 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const bool*>());
1027 JSON_THROW(type_error::create(302,
"type must be number, but is " + Twine(j.type_name())));
1031 template<
typename BasicJsonType,
typename A1,
typename A2>
1032 void from_json(
const BasicJsonType& j, std::pair<A1, A2>& p)
1034 p = {j.at(0).template get<A1>(), j.at(1).template get<A2>()};
1037 template<
typename BasicJsonType,
typename Tuple, std::size_t... Idx>
1038 void from_json_tuple_impl(
const BasicJsonType& j, Tuple& t, index_sequence<Idx...>)
1040 t = std::make_tuple(j.at(Idx).template get<typename std::tuple_element<Idx, Tuple>::type>()...);
1043 template<
typename BasicJsonType,
typename... Args>
1044 void from_json(
const BasicJsonType& j, std::tuple<Args...>& t)
1046 from_json_tuple_impl(j, t, index_sequence_for<Args...> {});
1052 template<
typename BasicJsonType,
typename T>
1054 noexcept(noexcept(from_json(j, val)))
1055 -> decltype(from_json(j, val),
void())
1057 return from_json(j, val);
1060 template<
typename BasicJsonType,
typename T>
1061 void call(
const BasicJsonType& , T& ,
priority_tag<0> )
const noexcept
1063 static_assert(
sizeof(BasicJsonType) == 0,
1064 "could not find from_json() method in T's namespace");
1067 using decayed = uncvref_t<T>;
1068 static_assert(
sizeof(
typename decayed::force_msvc_stacktrace) == 0,
1069 "forcing MSVC stacktrace to show which T we're talking about.");
1074 template<
typename BasicJsonType,
typename T>
1075 void operator()(
const BasicJsonType& j, T& val)
const
1076 noexcept(noexcept(std::declval<from_json_fn>().call(j, val,
priority_tag<1> {})))
1102 template<
typename BasicJsonType>
1103 static void construct(BasicJsonType& j,
bool b) noexcept
1107 j.assert_invariant();
1114 template<
typename BasicJsonType>
1115 static void construct(BasicJsonType& j,
StringRef s)
1119 j.assert_invariant();
1122 template<
typename BasicJsonType,
typename T,
1123 enable_if_t<std::is_same<std::string, T>::value,
int> = 0>
1124 static void construct(BasicJsonType& j, T&& s)
1127 j.m_value = std::move(s);
1128 j.assert_invariant();
1135 template<
typename BasicJsonType>
1136 static void construct(BasicJsonType& j,
double val) noexcept
1140 j.assert_invariant();
1147 template<
typename BasicJsonType>
1148 static void construct(BasicJsonType& j, uint64_t val) noexcept
1152 j.assert_invariant();
1159 template<
typename BasicJsonType>
1160 static void construct(BasicJsonType& j, int64_t val) noexcept
1164 j.assert_invariant();
1171 template<
typename BasicJsonType>
1172 static void construct(BasicJsonType& j,
const typename BasicJsonType::array_t& arr)
1176 j.assert_invariant();
1179 template<
typename BasicJsonType>
1180 static void construct(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
1183 j.m_value = std::move(arr);
1184 j.assert_invariant();
1187 template<
typename BasicJsonType,
typename T>
1188 static void construct(BasicJsonType& j,
ArrayRef<T> arr)
1193 j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
1194 j.assert_invariant();
1197 template<
typename BasicJsonType,
typename CompatibleArrayType,
1198 enable_if_t<not std::is_same<CompatibleArrayType, typename BasicJsonType::array_t>::value,
1200 static void construct(BasicJsonType& j,
const CompatibleArrayType& arr)
1205 j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
1206 j.assert_invariant();
1209 template<
typename BasicJsonType>
1210 static void construct(BasicJsonType& j,
const std::vector<bool>& arr)
1214 j.m_value.array->reserve(arr.size());
1215 for (
const bool x : arr)
1217 j.m_value.array->push_back(x);
1219 j.assert_invariant();
1226 template<
typename BasicJsonType>
1227 static void construct(BasicJsonType& j,
const typename BasicJsonType::object_t& obj)
1231 j.assert_invariant();
1234 template<
typename BasicJsonType>
1235 static void construct(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
1238 j.m_value = std::move(obj);
1239 j.assert_invariant();
1242 template<
typename BasicJsonType,
typename CompatibleObjectType,
1243 enable_if_t<not std::is_same<CompatibleObjectType, typename BasicJsonType::object_t>::value,
int> = 0>
1244 static void construct(BasicJsonType& j,
const CompatibleObjectType& obj)
1248 for (
const auto& x : obj)
1250 j.m_value.object->try_emplace(x.first, x.second);
1252 j.assert_invariant();
1260 template<
typename BasicJsonType,
typename T,
1261 enable_if_t<std::is_same<T, bool>::value,
int> = 0>
1262 void to_json(BasicJsonType& j, T b) noexcept
1267 template<
typename BasicJsonType,
typename CompatibleString,
1268 enable_if_t<std::is_constructible<StringRef, CompatibleString>::value,
int> = 0>
1269 void to_json(BasicJsonType& j,
const CompatibleString& s)
1271 external_constructor<value_t::string>::construct(j, s);
1274 template<
typename BasicJsonType,
typename T,
1275 enable_if_t<std::is_same<std::string, T>::value,
int> = 0>
1276 void to_json(BasicJsonType& j, T&& s)
1278 external_constructor<value_t::string>::construct(j, std::move(s));
1281 template<
typename BasicJsonType,
typename FloatType,
1282 enable_if_t<std::is_floating_point<FloatType>::value,
int> = 0>
1283 void to_json(BasicJsonType& j, FloatType val) noexcept
1285 external_constructor<value_t::number_float>::construct(j, static_cast<double>(val));
1288 template<
typename BasicJsonType,
typename CompatibleNumberUnsignedType,
1289 enable_if_t<is_compatible_integer_type<uint64_t, CompatibleNumberUnsignedType>::value,
int> = 0>
1290 void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val) noexcept
1292 external_constructor<value_t::number_unsigned>::construct(j, static_cast<uint64_t>(val));
1295 template<
typename BasicJsonType,
typename CompatibleNumberIntegerType,
1296 enable_if_t<is_compatible_integer_type<int64_t, CompatibleNumberIntegerType>::value,
int> = 0>
1297 void to_json(BasicJsonType& j, CompatibleNumberIntegerType val) noexcept
1299 external_constructor<value_t::number_integer>::construct(j, static_cast<int64_t>(val));
1302 template<
typename BasicJsonType,
typename EnumType,
1303 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
1304 void to_json(BasicJsonType& j, EnumType e) noexcept
1306 using underlying_type =
typename std::underlying_type<EnumType>::type;
1307 external_constructor<value_t::number_integer>::construct(j, static_cast<underlying_type>(e));
1310 template<
typename BasicJsonType>
1311 void to_json(BasicJsonType& j,
const std::vector<bool>& e)
1313 external_constructor<value_t::array>::construct(j, e);
1316 template<
typename BasicJsonType,
typename CompatibleArrayType,
1317 enable_if_t<is_compatible_array_type<BasicJsonType, CompatibleArrayType>::value or
1318 std::is_same<typename BasicJsonType::array_t, CompatibleArrayType>::value,
1320 void to_json(BasicJsonType& j,
const CompatibleArrayType& arr)
1322 external_constructor<value_t::array>::construct(j, arr);
1325 template<
typename BasicJsonType>
1326 void to_json(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
1328 external_constructor<value_t::array>::construct(j, std::move(arr));
1331 template<
typename BasicJsonType,
typename CompatibleObjectType,
1332 enable_if_t<is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value,
int> = 0>
1333 void to_json(BasicJsonType& j,
const CompatibleObjectType& obj)
1335 external_constructor<value_t::object>::construct(j, obj);
1338 template<
typename BasicJsonType>
1339 void to_json(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
1341 external_constructor<value_t::object>::construct(j, std::move(obj));
1344 template<
typename BasicJsonType,
typename T, std::size_t N,
1345 enable_if_t<not std::is_constructible<StringRef, T (&)[N]>::value,
int> = 0>
1346 void to_json(BasicJsonType& j, T (&arr)[N])
1348 external_constructor<value_t::array>::construct(j, arr);
1351 template<
typename BasicJsonType,
typename... Args>
1352 void to_json(BasicJsonType& j,
const std::pair<Args...>& p)
1354 j = {p.first, p.second};
1357 template<
typename BasicJsonType,
typename Tuple, std::size_t... Idx>
1358 void to_json_tuple_impl(BasicJsonType& j,
const Tuple& t, index_sequence<Idx...>)
1360 j = {std::get<Idx>(t)...};
1363 template<
typename BasicJsonType,
typename... Args>
1364 void to_json(BasicJsonType& j,
const std::tuple<Args...>& t)
1366 to_json_tuple_impl(j, t, index_sequence_for<Args...> {});
1372 template<
typename BasicJsonType,
typename T>
1373 auto call(BasicJsonType& j, T&& val,
priority_tag<1> )
const noexcept(noexcept(to_json(j, std::forward<T>(val))))
1374 -> decltype(to_json(j, std::forward<T>(val)),
void())
1376 return to_json(j, std::forward<T>(val));
1379 template<
typename BasicJsonType,
typename T>
1382 static_assert(
sizeof(BasicJsonType) == 0,
1383 "could not find to_json() method in T's namespace");
1387 using decayed = uncvref_t<T>;
1388 static_assert(
sizeof(
typename decayed::force_msvc_stacktrace) == 0,
1389 "forcing MSVC stacktrace to show which T we're talking about.");
1394 template<
typename BasicJsonType,
typename T>
1395 void operator()(BasicJsonType& j, T&& val)
const
1396 noexcept(noexcept(std::declval<to_json_fn>().call(j, std::forward<T>(val),
priority_tag<1> {})))
1423 using difference_type = std::ptrdiff_t;
1424 static constexpr difference_type begin_value = 0;
1425 static constexpr difference_type end_value = begin_value + 1;
1428 difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)();
1431 constexpr difference_type get_value()
const noexcept
1451 return m_it == begin_value;
1457 return m_it == end_value;
1462 return lhs.m_it == rhs.m_it;
1465 friend constexpr
bool operator<(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
1467 return lhs.m_it < rhs.m_it;
1470 primitive_iterator_t operator+(difference_type n) noexcept
1472 auto result = *
this;
1477 friend constexpr difference_type operator-(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
1479 return lhs.m_it - rhs.m_it;
1482 primitive_iterator_t& operator++() noexcept
1488 primitive_iterator_t
const operator++(
int) noexcept
1490 auto result = *
this;
1495 primitive_iterator_t& operator--() noexcept
1501 primitive_iterator_t
const operator--(
int) noexcept
1503 auto result = *
this;
1508 primitive_iterator_t& operator+=(difference_type n) noexcept
1514 primitive_iterator_t& operator-=(difference_type n) noexcept
1530 typename BasicJsonType::object_t::iterator object_iterator {};
1532 typename BasicJsonType::array_t::iterator array_iterator {};
1560 template<
typename BasicJsonType>
1565 friend BasicJsonType;
1567 friend class ::wpi::JsonTest;
1569 using object_t =
typename BasicJsonType::object_t;
1570 using array_t =
typename BasicJsonType::array_t;
1572 static_assert(
is_json<
typename std::remove_const<BasicJsonType>::type>::value,
1573 "iter_impl only accepts (const) json");
1582 using iterator_category = std::bidirectional_iterator_tag;
1585 using value_type =
typename BasicJsonType::value_type;
1587 using difference_type =
typename BasicJsonType::difference_type;
1589 using pointer =
typename std::conditional<std::is_const<BasicJsonType>::value,
1590 typename BasicJsonType::const_pointer,
1591 typename BasicJsonType::pointer>::type;
1594 typename std::conditional<std::is_const<BasicJsonType>::value,
1595 typename BasicJsonType::const_reference,
1596 typename BasicJsonType::reference>::type;
1607 explicit iter_impl(pointer
object) noexcept : m_object(
object)
1609 assert(m_object !=
nullptr);
1611 switch (m_object->m_type)
1615 m_it.object_iterator =
typename object_t::iterator();
1621 m_it.array_iterator =
typename array_t::iterator();
1647 iter_impl(
const iter_impl<
typename std::remove_const<BasicJsonType>::type>& other) noexcept
1648 : m_object(other.m_object), m_it(other.m_it) {}
1656 iter_impl& operator=(
const iter_impl<
typename std::remove_const<BasicJsonType>::type>& other) noexcept
1658 m_object = other.m_object;
1668 void set_begin() noexcept
1670 assert(m_object !=
nullptr);
1672 switch (m_object->m_type)
1676 m_it.object_iterator = m_object->m_value.object->begin();
1682 m_it.array_iterator = m_object->m_value.array->begin();
1689 m_it.primitive_iterator.set_end();
1695 m_it.primitive_iterator.set_begin();
1705 void set_end() noexcept
1707 assert(m_object !=
nullptr);
1709 switch (m_object->m_type)
1713 m_it.object_iterator = m_object->m_value.object->end();
1719 m_it.array_iterator = m_object->m_value.array->end();
1725 m_it.primitive_iterator.set_end();
1736 reference operator*()
const
1738 assert(m_object !=
nullptr);
1740 switch (m_object->m_type)
1744 assert(m_it.object_iterator != m_object->m_value.object->end());
1745 return m_it.object_iterator->second;
1750 assert(m_it.array_iterator != m_object->m_value.array->end());
1751 return *m_it.array_iterator;
1755 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
1759 if (JSON_LIKELY(m_it.primitive_iterator.is_begin()))
1764 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
1773 pointer operator->()
const
1775 assert(m_object !=
nullptr);
1777 switch (m_object->m_type)
1781 assert(m_it.object_iterator != m_object->m_value.object->end());
1782 return &(m_it.object_iterator->second);
1787 assert(m_it.array_iterator != m_object->m_value.array->end());
1788 return &*m_it.array_iterator;
1793 if (JSON_LIKELY(m_it.primitive_iterator.is_begin()))
1798 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
1809 auto result = *
this;
1820 assert(m_object !=
nullptr);
1822 switch (m_object->m_type)
1826 ++m_it.object_iterator;
1832 std::advance(m_it.array_iterator, 1);
1838 ++m_it.primitive_iterator;
1852 auto result = *
this;
1863 assert(m_object !=
nullptr);
1865 switch (m_object->m_type)
1869 --m_it.object_iterator;
1875 std::advance(m_it.array_iterator, -1);
1881 --m_it.primitive_iterator;
1893 bool operator==(
const iter_impl& other)
const
1896 if (JSON_UNLIKELY(m_object != other.m_object))
1898 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers"));
1901 assert(m_object !=
nullptr);
1903 switch (m_object->m_type)
1906 return (m_it.object_iterator == other.m_it.object_iterator);
1909 return (m_it.array_iterator == other.m_it.array_iterator);
1912 return (m_it.primitive_iterator == other.m_it.primitive_iterator);
1920 bool operator!=(
const iter_impl& other)
const
1922 return not operator==(other);
1932 if (JSON_UNLIKELY(m_object != other.m_object))
1934 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers"));
1937 assert(m_object !=
nullptr);
1939 switch (m_object->m_type)
1942 JSON_THROW(invalid_iterator::create(213,
"cannot compare order of object iterators"));
1945 return (m_it.array_iterator < other.m_it.array_iterator);
1948 return (m_it.primitive_iterator < other.m_it.primitive_iterator);
1956 bool operator<=(
const iter_impl& other)
const
1958 return not other.operator < (*this);
1965 bool operator>(
const iter_impl& other)
const
1967 return not operator<=(other);
1974 bool operator>=(
const iter_impl& other)
const
1983 iter_impl& operator+=(difference_type i)
1985 assert(m_object !=
nullptr);
1987 switch (m_object->m_type)
1990 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators"));
1994 std::advance(m_it.array_iterator, i);
2000 m_it.primitive_iterator += i;
2012 iter_impl& operator-=(difference_type i)
2014 return operator+=(-i);
2021 iter_impl operator+(difference_type i)
const
2023 auto result = *
this;
2043 iter_impl operator-(difference_type i)
const
2045 auto result = *
this;
2054 difference_type operator-(
const iter_impl& other)
const
2056 assert(m_object !=
nullptr);
2058 switch (m_object->m_type)
2061 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators"));
2064 return m_it.array_iterator - other.m_it.array_iterator;
2067 return m_it.primitive_iterator - other.m_it.primitive_iterator;
2075 reference operator[](difference_type n)
const
2077 assert(m_object !=
nullptr);
2079 switch (m_object->m_type)
2082 JSON_THROW(invalid_iterator::create(208,
"cannot use operator[] for object iterators"));
2085 return *std::next(m_it.array_iterator, n);
2088 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
2092 if (JSON_LIKELY(m_it.primitive_iterator.get_value() == -n))
2097 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
2108 assert(m_object !=
nullptr);
2110 if (JSON_LIKELY(m_object->is_object()))
2112 return m_it.object_iterator->first();
2115 JSON_THROW(invalid_iterator::create(207,
"cannot use key() for non-object iterators"));
2122 reference value()
const
2129 pointer m_object =
nullptr;
2139 class iteration_proxy_internal
2143 IteratorType anchor;
2145 std::size_t array_index = 0;
2148 explicit iteration_proxy_internal(IteratorType it) noexcept : anchor(it) {}
2151 iteration_proxy_internal& operator*()
2157 iteration_proxy_internal& operator++()
2166 bool operator!=(
const iteration_proxy_internal& o)
const noexcept
2168 return anchor != o.anchor;
2174 assert(anchor.m_object !=
nullptr);
2176 switch (anchor.m_object->type())
2180 return std::to_string(array_index);
2184 return anchor.key();
2193 typename IteratorType::reference value()
const
2195 return anchor.value();
2200 typename IteratorType::reference container;
2205 : container(cont) {}
2208 iteration_proxy_internal
begin() noexcept
2210 return iteration_proxy_internal(container.begin());
2214 iteration_proxy_internal
end() noexcept
2216 return iteration_proxy_internal(container.end());
2242 template<
typename Base>
2246 using difference_type = std::ptrdiff_t;
2310 return *(this->operator+(n));
2314 auto key() const -> decltype(
std::declval<Base>().key())
2316 auto it = --this->base();
2323 auto it = --this->base();
2324 return it.operator * ();
2328 template<
typename BasicJsonType>
2332 using value_type = BasicJsonType;
2335 : owned_value(std::move(value)), value_ref(&owned_value), is_rvalue(
true)
2339 : value_ref(const_cast<value_type*>(&value)), is_rvalue(
false)
2342 json_ref(std::initializer_list<json_ref> init)
2343 : owned_value(init), value_ref(&owned_value), is_rvalue(
true)
2346 template<
class... Args>
2348 : owned_value(std::forward<Args>(args)...), value_ref(&owned_value), is_rvalue(
true)
2352 json_ref(json_ref&&) =
default;
2353 json_ref(
const json_ref&) =
delete;
2354 json_ref& operator=(
const json_ref&) =
delete;
2356 value_type moved_or_copied()
const
2360 return std::move(*value_ref);
2365 value_type
const& operator*()
const
2367 return *
static_cast<value_type const*
>(value_ref);
2370 value_type
const* operator->()
const
2372 return static_cast<value_type const*
>(value_ref);
2376 mutable value_type owned_value =
nullptr;
2377 value_type* value_ref =
nullptr;
2378 const bool is_rvalue;
2386 friend class JsonTest;
2411 : reference_tokens(split(s))
2444 static int array_index(
const Twine& s);
2453 if (JSON_UNLIKELY(is_root()))
2455 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent"));
2458 auto last = reference_tokens.back();
2459 reference_tokens.pop_back();
2464 bool is_root()
const
2466 return reference_tokens.empty();
2469 json_pointer top()
const
2471 if (JSON_UNLIKELY(is_root()))
2473 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent"));
2476 json_pointer result = *
this;
2477 result.reference_tokens = {reference_tokens[0]};
2489 json& get_and_create(json& j)
const;
2510 json& get_unchecked(json* ptr)
const;
2518 json& get_checked(json* ptr)
const;
2533 const json& get_unchecked(
const json* ptr)
const;
2541 const json& get_checked(
const json* ptr)
const;
2552 static std::vector<std::string> split(
const Twine& reference_string);
2583 static void flatten(
const Twine& reference_string,
2598 unflatten(
const json& value);
2600 friend bool operator==(json_pointer
const& lhs,
2601 json_pointer
const& rhs) noexcept
2603 return (lhs.reference_tokens == rhs.reference_tokens);
2606 friend bool operator!=(json_pointer
const& lhs,
2607 json_pointer
const& rhs) noexcept
2609 return not (lhs == rhs);
2613 std::vector<std::string> reference_tokens;
2616 template<
typename,
typename>
2617 struct adl_serializer
2628 template<
typename BasicJsonType,
typename ValueType>
2629 static void from_json(BasicJsonType&& j, ValueType& val) noexcept(
2630 noexcept(::wpi::from_json(std::forward<BasicJsonType>(j), val)))
2632 ::wpi::from_json(std::forward<BasicJsonType>(j), val);
2644 template<
typename BasicJsonType,
typename ValueType>
2645 static void to_json(BasicJsonType& j, ValueType&& val) noexcept(
2646 noexcept(::
wpi::to_json(j,
std::forward<ValueType>(val))))
2648 ::wpi::to_json(j, std::forward<ValueType>(val));
2718 friend ::wpi::json_pointer;
2719 template<
typename BasicJsonType>
2720 friend class ::wpi::detail::iter_impl;
2721 friend class JsonTest;
2728 template<
typename BasicJsonType>
2730 template<
typename BasicJsonType>
2732 template<
typename Iterator>
2736 class binary_reader;
2737 class binary_writer;
2746 template<
typename T,
typename SFINAE>
2863 #if defined(JSON_HAS_CPP_14)
2866 using object_comparator_t = std::less<>;
2868 using object_comparator_t = std::less<std::string>;
2960 template<
typename T,
typename... Args>
2961 static T* create(Args&& ... args)
2963 std::allocator<T> alloc;
2965 auto deleter = [&](T *
object)
2967 alloc.deallocate(
object, 1);
2969 std::unique_ptr<T, decltype(deleter)>
object(alloc.allocate(1), deleter);
2970 alloc.construct(
object.
get(), std::forward<Args>(args)...);
2971 assert(
object !=
nullptr);
2972 return object.release();
3021 json_value() =
default;
3023 json_value(
bool v) noexcept :
boolean(v) {}
3034 json_value(StringRef value)
3036 string = create<std::string>(value);
3042 string = create<std::string>(value);
3048 string = create<std::string>(std::move(value));
3052 json_value(
const object_t& value)
3054 object = create<object_t>(value);
3058 json_value(object_t&& value)
3060 object = create<object_t>(std::move(value));
3064 json_value(
const array_t& value)
3066 array = create<array_t>(value);
3070 json_value(array_t&& value)
3072 array = create<array_t>(std::move(value));
3075 void destroy(
value_t t) noexcept;
3087 void assert_invariant() const noexcept
3179 using parser_callback_t =
3180 std::function<bool(int depth, parse_event_t event, json& parsed)>;
3222 : m_type(v), m_value(v)
3245 json(std::nullptr_t =
nullptr) noexcept
3308 template <
typename CompatibleType,
3309 typename U = detail::uncvref_t<CompatibleType>,
3310 detail::enable_if_t<
3312 json(CompatibleType && val) noexcept(noexcept(
3314 std::forward<CompatibleType>(val))))
3394 json(initializer_list_t init,
3395 bool type_deduction =
true,
3505 json(size_type cnt,
const json& val);
3562 template<
class InputIT,
typename std::enable_if<
3563 std::is_same<InputIT, typename json_t::iterator>::value or
3564 std::is_same<InputIT, typename json_t::const_iterator>::value,
int>::type = 0>
3567 assert(first.m_object !=
nullptr);
3568 assert(last.m_object !=
nullptr);
3571 if (JSON_UNLIKELY(first.m_object != last.m_object))
3573 JSON_THROW(invalid_iterator::create(201,
"iterators are not compatible"));
3577 m_type = first.m_object->m_type;
3588 if (JSON_UNLIKELY(not first.m_it.primitive_iterator.is_begin()
3589 or not last.m_it.primitive_iterator.is_end()))
3591 JSON_THROW(invalid_iterator::create(204,
"iterators out of range"));
3604 m_value.number_integer = first.m_object->m_value.number_integer;
3610 m_value.number_unsigned = first.m_object->m_value.number_unsigned;
3616 m_value.number_float = first.m_object->m_value.number_float;
3622 m_value.boolean = first.m_object->m_value.boolean;
3628 m_value = *first.m_object->m_value.string;
3634 m_value.array = create<array_t>(first.m_it.array_iterator,
3635 last.m_it.array_iterator);
3640 JSON_THROW(invalid_iterator::create(206,
"cannot construct with iterators from " +
3641 Twine(first.m_object->type_name())));
3654 :
json(ref.moved_or_copied())
3682 json(
const json& other);
3711 : m_type(
std::move(other.m_type)),
3712 m_value(
std::move(other.m_value))
3715 other.assert_invariant();
3748 std::is_nothrow_move_constructible<value_t>::value and
3749 std::is_nothrow_move_assignable<value_t>::value and
3750 std::is_nothrow_move_constructible<json_value>::value and
3751 std::is_nothrow_move_assignable<json_value>::value
3755 other.assert_invariant();
3758 swap(m_type, other.m_type);
3759 swap(m_value, other.m_value);
3783 m_value.destroy(m_type);
3833 std::string dump(
const int indent = -1,
const char indent_char =
' ',
3834 const bool ensure_ascii =
false)
const;
3836 void dump(
raw_ostream& os,
int indent = -1,
const char indent_char =
' ',
3837 const bool ensure_ascii =
false)
const;
3903 return is_null() or is_string() or is_boolean() or is_number();
3930 return is_array() or is_object();
4004 return is_number_integer() or is_number_float();
4219 bool get_impl(
bool* )
const
4221 if (JSON_LIKELY(is_boolean()))
4223 return m_value.boolean;
4226 JSON_THROW(type_error::create(302,
"type must be boolean, but is " + Twine(type_name())));
4230 object_t* get_impl_ptr(object_t* ) noexcept
4232 return is_object() ? m_value.object :
nullptr;
4236 const object_t* get_impl_ptr(
const object_t* ) const noexcept
4238 return is_object() ? m_value.object :
nullptr;
4242 array_t* get_impl_ptr(array_t* ) noexcept
4244 return is_array() ? m_value.array :
nullptr;
4248 const array_t* get_impl_ptr(
const array_t* ) const noexcept
4250 return is_array() ? m_value.array :
nullptr;
4256 return is_string() ? m_value.string :
nullptr;
4262 return is_string() ? m_value.string :
nullptr;
4266 bool* get_impl_ptr(
bool* ) noexcept
4268 return is_boolean() ? &m_value.boolean :
nullptr;
4272 const bool* get_impl_ptr(
const bool* ) const noexcept
4274 return is_boolean() ? &m_value.boolean :
nullptr;
4278 int64_t* get_impl_ptr(int64_t* ) noexcept
4280 return is_number_integer() ? &m_value.number_integer :
nullptr;
4284 const int64_t* get_impl_ptr(
const int64_t* ) const noexcept
4286 return is_number_integer() ? &m_value.number_integer :
nullptr;
4290 uint64_t* get_impl_ptr(uint64_t* ) noexcept
4292 return is_number_unsigned() ? &m_value.number_unsigned :
nullptr;
4296 const uint64_t* get_impl_ptr(
const uint64_t* ) const noexcept
4298 return is_number_unsigned() ? &m_value.number_unsigned :
nullptr;
4302 double* get_impl_ptr(
double* ) noexcept
4304 return is_number_float() ? &m_value.number_float :
nullptr;
4308 const double* get_impl_ptr(
const double* ) const noexcept
4310 return is_number_float() ? &m_value.number_float :
nullptr;
4324 template<
typename ReferenceType,
typename ThisType>
4325 static ReferenceType get_ref_impl(ThisType& obj)
4328 auto ptr = obj.template get_ptr<typename std::add_pointer<ReferenceType>::type>();
4330 if (JSON_LIKELY(ptr !=
nullptr))
4335 JSON_THROW(type_error::create(303,
"incompatible ReferenceType for get_ref, actual type is " + Twine(obj.type_name())));
4357 template<
typename BasicJsonType, detail::enable_if_t<
4358 std::is_same<typename std::remove_const<BasicJsonType>::type, json_t>::value,
4404 template<
typename ValueTypeCV,
typename ValueType = detail::uncvref_t<ValueTypeCV>,
4405 detail::enable_if_t <
4406 not detail::is_json<ValueType>::value and
4407 detail::has_from_json<json_t, ValueType>::value and
4408 not detail::has_non_default_from_json<json_t, ValueType>::value,
4410 ValueType
get()
const noexcept(noexcept(
4416 static_assert(not std::is_reference<ValueTypeCV>::value,
4417 "get() cannot be used with reference types, you might want to use get_ref()");
4418 static_assert(std::is_default_constructible<ValueType>::value,
4419 "types must be DefaultConstructible when used with get()");
4457 template<
typename ValueTypeCV,
typename ValueType = detail::uncvref_t<ValueTypeCV>,
4458 detail::enable_if_t<not std::is_same<json_t, ValueType>::value and
4459 detail::has_non_default_from_json<json_t, ValueType>::value,
4461 ValueType
get()
const noexcept(noexcept(
4464 static_assert(not std::is_reference<ValueTypeCV>::value,
4465 "get() cannot be used with reference types, you might want to use get_ref()");
4495 template<
typename PointerType,
typename std::enable_if<
4496 std::is_pointer<PointerType>::value,
int>::type = 0>
4497 PointerType
get() noexcept
4500 return get_ptr<PointerType>();
4507 template<
typename PointerType,
typename std::enable_if<
4508 std::is_pointer<PointerType>::value,
int>::type = 0>
4509 const PointerType
get()
const noexcept
4512 return get_ptr<PointerType>();
4540 template<
typename PointerType,
typename std::enable_if<
4541 std::is_pointer<PointerType>::value,
int>::type = 0>
4545 using pointee_t =
typename std::remove_const<
typename
4546 std::remove_pointer<
typename
4547 std::remove_const<PointerType>::type>::type>::type;
4550 std::is_same<object_t, pointee_t>::value
4551 or std::is_same<array_t, pointee_t>::value
4552 or std::is_same<std::string, pointee_t>::value
4553 or std::is_same<bool, pointee_t>::value
4554 or std::is_same<int64_t, pointee_t>::value
4555 or std::is_same<uint64_t, pointee_t>::value
4556 or std::is_same<double, pointee_t>::value
4557 ,
"incompatible pointer type");
4560 return get_impl_ptr(static_cast<PointerType>(
nullptr));
4567 template<
typename PointerType,
typename std::enable_if<
4568 std::is_pointer<PointerType>::value and
4569 std::is_const<typename std::remove_pointer<PointerType>::type>::value,
int>::type = 0>
4573 using pointee_t =
typename std::remove_const<
typename
4574 std::remove_pointer<
typename
4575 std::remove_const<PointerType>::type>::type>::type;
4578 std::is_same<object_t, pointee_t>::value
4579 or std::is_same<array_t, pointee_t>::value
4580 or std::is_same<std::string, pointee_t>::value
4581 or std::is_same<bool, pointee_t>::value
4582 or std::is_same<int64_t, pointee_t>::value
4583 or std::is_same<uint64_t, pointee_t>::value
4584 or std::is_same<double, pointee_t>::value
4585 ,
"incompatible pointer type");
4588 return get_impl_ptr(static_cast<PointerType>(
nullptr));
4617 template<
typename ReferenceType,
typename std::enable_if<
4618 std::is_reference<ReferenceType>::value,
int>::type = 0>
4622 return get_ref_impl<ReferenceType>(*this);
4629 template<
typename ReferenceType,
typename std::enable_if<
4630 std::is_reference<ReferenceType>::value and
4631 std::is_const<typename std::remove_reference<ReferenceType>::type>::value,
int>::type = 0>
4635 return get_ref_impl<ReferenceType>(*this);
4667 template <
typename ValueType,
typename std::enable_if <
4668 not std::is_pointer<ValueType>::value and
4669 not std::is_same<ValueType, detail::json_ref<json>>::value and
4670 not std::is_same<ValueType, std::string::value_type>::value and
4672 #ifndef _MSC_VER // fix for issue #167 operator<< ambiguity under VS2015
4673 and not std::is_same<ValueType, std::initializer_list<std::string::value_type>>::value
4675 #if defined(JSON_HAS_CPP_17)
4676 and not std::is_same<ValueType, typename std::string_view>::value
4679 operator ValueType()
const
4682 return get<ValueType>();
4722 reference at(size_type idx);
4750 const_reference at(size_type idx)
const;
4814 const_reference at(
StringRef key)
const;
4841 reference operator[](size_type idx);
4862 const_reference operator[](size_type idx)
const;
4923 const_reference operator[](
StringRef key)
const;
4952 template<
typename T>
4964 if (JSON_LIKELY(is_object()))
4966 return m_value.object->operator[](key);
4969 JSON_THROW(type_error::create(305,
"cannot use operator[] with " +
Twine(type_name())));
5002 template<
typename T>
5006 if (JSON_LIKELY(is_object()))
5008 assert(m_value.object->find(key) != m_value.object->end());
5012 JSON_THROW(type_error::create(305,
"cannot use operator[] with " +
Twine(type_name())));
5063 template<
class ValueType,
typename std::enable_if<
5064 std::is_convertible<json_t, ValueType>::value,
int>::type = 0>
5068 if (JSON_LIKELY(is_object()))
5071 const auto it =
find(key);
5077 return default_value;
5080 JSON_THROW(type_error::create(306,
"cannot use value() with " +
Twine(type_name())));
5133 template<
class ValueType,
typename std::enable_if<
5134 std::is_convertible<json_t, ValueType>::value,
int>::type = 0>
5138 if (JSON_LIKELY(is_object()))
5143 return ptr.get_checked(
this);
5147 return default_value;
5151 JSON_THROW(type_error::create(306,
"cannot use value() with " +
Twine(type_name())));
5293 template<
class IteratorType,
typename std::enable_if<
5294 std::is_same<IteratorType, typename json_t::iterator>::value or
5295 std::is_same<IteratorType, typename json_t::const_iterator>::value,
int>::type
5300 if (JSON_UNLIKELY(
this != pos.m_object))
5302 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value"));
5313 if (JSON_UNLIKELY(not pos.m_it.primitive_iterator.is_begin()))
5315 JSON_THROW(invalid_iterator::create(205,
"iterator out of range"));
5320 std::allocator<std::string> alloc;
5321 alloc.destroy(m_value.string);
5322 alloc.deallocate(m_value.string, 1);
5323 m_value.string =
nullptr;
5333 m_value.object->erase(pos.m_it.object_iterator);
5339 m_value.array->erase(pos.m_it.array_iterator);
5344 JSON_THROW(type_error::create(307,
"cannot use erase() with " +
Twine(type_name())));
5394 template<
class IteratorType,
typename std::enable_if<
5395 std::is_same<IteratorType, typename json_t::iterator>::value or
5396 std::is_same<IteratorType, typename json_t::const_iterator>::value,
int>::type
5398 IteratorType
erase(IteratorType first, IteratorType last)
5401 if (JSON_UNLIKELY(
this != first.m_object or
this != last.m_object))
5403 JSON_THROW(invalid_iterator::create(203,
"iterators do not fit current value"));
5406 IteratorType result = end();
5416 if (JSON_LIKELY(not first.m_it.primitive_iterator.is_begin()
5417 or not last.m_it.primitive_iterator.is_end()))
5419 JSON_THROW(invalid_iterator::create(204,
"iterators out of range"));
5424 std::allocator<std::string> alloc;
5425 alloc.destroy(m_value.string);
5426 alloc.deallocate(m_value.string, 1);
5427 m_value.string =
nullptr;
5437 result.m_it.array_iterator = m_value.array->erase(first.m_it.array_iterator,
5438 last.m_it.array_iterator);
5443 JSON_THROW(type_error::create(307,
"cannot use erase() with " +
Twine(type_name())));
5504 void erase(
const size_type idx);
5969 bool empty() const noexcept;
6013 size_type
size() const noexcept;
6055 size_type max_size() const noexcept;
6103 void clear() noexcept;
6125 void push_back(
json&& val);
6133 push_back(std::move(val));
6141 void push_back(
const json& val);
6173 template<
typename T,
typename U>
6177 if (JSON_UNLIKELY(not(is_null() or is_object())))
6179 JSON_THROW(type_error::create(308,
"cannot use push_back() with " +
Twine(type_name())));
6191 m_value.object->try_emplace(val.first, std::move(val.second));
6198 template<
typename T,
typename U>
6230 void push_back(initializer_list_t init);
6263 template<
class... Args>
6267 if (JSON_UNLIKELY(not(is_null() or is_array())))
6269 JSON_THROW(type_error::create(311,
"cannot use emplace_back() with " +
Twine(type_name())));
6281 m_value.array->emplace_back(std::forward<Args>(args)...);
6311 template<
class... Args>
6315 if (JSON_UNLIKELY(not(is_null() or is_object())))
6317 JSON_THROW(type_error::create(311,
"cannot use emplace() with " +
Twine(type_name())));
6329 auto res = m_value.object->try_emplace(key, std::forward<Args>(args)...);
6332 it.m_it.object_iterator = res.first;
6335 return {it, res.second};
6360 iterator insert(const_iterator pos,
const json& val);
6368 return insert(pos, val);
6395 iterator insert(const_iterator pos, size_type cnt,
const json& val);
6427 iterator insert(const_iterator pos, const_iterator first, const_iterator last);
6453 iterator insert(const_iterator pos, initializer_list_t ilist);
6478 void insert(const_iterator first, const_iterator last);
6499 void update(const_reference j);
6527 void update(const_iterator first, const_iterator last);
6547 std::is_nothrow_move_constructible<value_t>::value and
6548 std::is_nothrow_move_assignable<value_t>::value and
6549 std::is_nothrow_move_constructible<json_value>::value and
6550 std::is_nothrow_move_assignable<json_value>::value
6553 std::swap(m_type, other.m_type);
6554 std::swap(m_value, other.m_value);
6581 if (JSON_LIKELY(is_array()))
6583 std::swap(*(m_value.array), other);
6587 JSON_THROW(type_error::create(310,
"cannot use swap() with " +
Twine(type_name())));
6614 if (JSON_LIKELY(is_object()))
6616 std::swap(*(m_value.object), other);
6620 JSON_THROW(type_error::create(310,
"cannot use swap() with " +
Twine(type_name())));
6647 if (JSON_LIKELY(is_string()))
6649 std::swap(*(m_value.string), other);
6653 JSON_THROW(type_error::create(310,
"cannot use swap() with " +
Twine(type_name())));
6706 friend bool operator==(const_reference lhs, const_reference rhs) noexcept;
6712 template<
typename ScalarType,
typename std::enable_if<
6713 std::is_scalar<ScalarType>::value,
int>::type = 0>
6716 return (lhs ==
json(rhs));
6723 template<
typename ScalarType,
typename std::enable_if<
6724 std::is_scalar<ScalarType>::value,
int>::type = 0>
6727 return (
json(lhs) == rhs);
6750 return not (lhs == rhs);
6757 template<
typename ScalarType,
typename std::enable_if<
6758 std::is_scalar<ScalarType>::value,
int>::type = 0>
6761 return (lhs !=
json(rhs));
6768 template<
typename ScalarType,
typename std::enable_if<
6769 std::is_scalar<ScalarType>::value,
int>::type = 0>
6772 return (
json(lhs) != rhs);
6801 friend bool operator<(const_reference lhs, const_reference rhs) noexcept;
6807 template<
typename ScalarType,
typename std::enable_if<
6808 std::is_scalar<ScalarType>::value,
int>::type = 0>
6811 return (lhs <
json(rhs));
6818 template<
typename ScalarType,
typename std::enable_if<
6819 std::is_scalar<ScalarType>::value,
int>::type = 0>
6822 return (
json(lhs) < rhs);
6846 return not (rhs < lhs);
6853 template<
typename ScalarType,
typename std::enable_if<
6854 std::is_scalar<ScalarType>::value,
int>::type = 0>
6857 return (lhs <=
json(rhs));
6864 template<
typename ScalarType,
typename std::enable_if<
6865 std::is_scalar<ScalarType>::value,
int>::type = 0>
6868 return (
json(lhs) <= rhs);
6892 return not (lhs <= rhs);
6899 template<
typename ScalarType,
typename std::enable_if<
6900 std::is_scalar<ScalarType>::value,
int>::type = 0>
6903 return (lhs >
json(rhs));
6910 template<
typename ScalarType,
typename std::enable_if<
6911 std::is_scalar<ScalarType>::value,
int>::type = 0>
6914 return (
json(lhs) > rhs);
6938 return not (lhs < rhs);
6945 template<
typename ScalarType,
typename std::enable_if<
6946 std::is_scalar<ScalarType>::value,
int>::type = 0>
6949 return (lhs >=
json(rhs));
6956 template<
typename ScalarType,
typename std::enable_if<
6957 std::is_scalar<ScalarType>::value,
int>::type = 0>
6960 return (
json(lhs) >= rhs);
7078 const parser_callback_t cb =
nullptr,
7079 const bool allow_exceptions =
true);
7082 const parser_callback_t cb =
nullptr,
7083 const bool allow_exceptions =
true);
7089 const parser_callback_t cb =
nullptr,
7090 const bool allow_exceptions =
true);
7161 const char* type_name() const noexcept;
7173 json_value m_value = {};
7271 static std::vector<uint8_t> to_cbor(
const json& j);
7272 static ArrayRef<uint8_t> to_cbor(
const json& j, std::vector<uint8_t>& buf);
7273 static ArrayRef<uint8_t> to_cbor(
const json& j, SmallVectorImpl<uint8_t>& buf);
7274 static void to_cbor(raw_ostream& os,
const json& j);
7356 static std::vector<uint8_t> to_msgpack(
const json& j);
7357 static ArrayRef<uint8_t> to_msgpack(
const json& j, std::vector<uint8_t>& buf);
7358 static ArrayRef<uint8_t> to_msgpack(
const json& j, SmallVectorImpl<uint8_t>& buf);
7359 static void to_msgpack(raw_ostream& os,
const json& j);
7441 static std::vector<uint8_t> to_ubjson(
const json& j,
7442 const bool use_size =
false,
7443 const bool use_type =
false);
7444 static ArrayRef<uint8_t> to_ubjson(
const json& j, std::vector<uint8_t>& buf,
7445 const bool use_size =
false,
const bool use_type =
false);
7446 static ArrayRef<uint8_t> to_ubjson(
const json& j, SmallVectorImpl<uint8_t>& buf,
7447 const bool use_size =
false,
const bool use_type =
false);
7448 static void to_ubjson(raw_ostream& os,
const json& j,
7449 const bool use_size =
false,
const bool use_type =
false);
7544 static json from_cbor(raw_istream& is,
7545 const bool strict =
true);
7550 static json from_cbor(ArrayRef<uint8_t> arr,
const bool strict =
true);
7625 static json from_msgpack(raw_istream& is,
7626 const bool strict =
true);
7631 static json from_msgpack(ArrayRef<uint8_t> arr,
const bool strict =
true);
7686 static json from_ubjson(raw_istream& is,
7687 const bool strict =
true);
7689 static json from_ubjson(ArrayRef<uint8_t> arr,
const bool strict =
true);
7735 return ptr.get_unchecked(
this);
7763 return ptr.get_unchecked(
this);
7806 return ptr.get_checked(
this);
7849 return ptr.get_checked(
this);
7877 json_pointer::flatten(
"", *
this, result);
7913 return json_pointer::unflatten(*
this);
7972 json patch(
const json& json_patch)
const;
8007 static json diff(
const json& source,
const json& target,
8061 void merge_patch(
const json& patch);
8082 is_nothrow_move_constructible<wpi::json>::value and
8083 is_nothrow_move_assignable<wpi::json>::value
8101 const auto& h = hash<std::string>();
8138 inline wpi::json operator "" _json(
const char* s, std::size_t n)
8161 #ifndef WPI_JSON_IMPLEMENTATION
8164 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
8165 #pragma GCC diagnostic pop
8167 #if defined(__clang__)
8168 #pragma GCC diagnostic pop
8176 #undef JSON_UNLIKELY
8177 #undef JSON_HAS_CPP_14
8178 #undef JSON_HAS_CPP_17
8179 #undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
8180 #undef NLOHMANN_BASIC_JSON_TPL
8181 #undef NLOHMANN_JSON_HAS_HELPER
8183 #endif // WPI_JSON_IMPLEMENTATION
iteration_proxy_internal end() noexcept
return iterator end (needed for range-based for)
Definition: json.h:2214
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
static allocator_type get_allocator()
returns the allocator associated with the container
Definition: json.h:2820
friend bool operator==(const_reference lhs, const ScalarType rhs) noexcept
comparison: equal
Definition: json.h:6714
friend bool operator==(const ScalarType lhs, const_reference rhs) noexcept
comparison: equal
Definition: json.h:6725
IteratorType erase(IteratorType first, IteratorType last)
remove elements given an iterator range
Definition: json.h:5398
std::size_t operator()(const wpi::json &j) const
return a hash value for a JSON object
Definition: json.h:8098
iteration_proxy< const_iterator > items() const noexcept
helper to access iterator member functions in range-based for
Definition: json.h:5913
friend bool operator>(const_reference lhs, const_reference rhs) noexcept
comparison: greater than
Definition: json.h:6890
std::vector< json > array_t
a type for an array
Definition: json.h:2953
ValueType value(const json_pointer &ptr, const ValueType &default_value) const
access specified object element via JSON Pointer with default value
Definition: json.h:5135
const_reference operator[](T *key) const
read-only access specified object element
Definition: json.h:5003
::wpi::json_pointer json_pointer
Definition: json.h:2745
json_reverse_iterator operator+(difference_type i) const
add to iterator
Definition: json.h:2290
void swap(array_t &other)
exchanges the values
Definition: json.h:6578
reference front()
access the first element
Definition: json.h:5188
bool is_null() const noexcept
return whether value is null
Definition: json.h:3950
std::initializer_list< detail::json_ref< json >> initializer_list_t
helper type for initializer lists of json values
Definition: json.h:2749
value_t
the JSON type enumeration
Definition: json.h:760
reference operator+=(const json &val)
add an object to an array
Definition: json.h:6147
number value (signed integer)
bool is_discarded() const noexcept
return whether value is discarded
Definition: json.h:4180
iterator end() noexcept
returns an iterator to one past the last element
Definition: json.h:5674
default JSONSerializer template argument
Definition: json.h:83
void erase(IteratorType pos)
remove element given an iterator
Definition: json.h:5297
const_reference back() const
access the last element
Definition: json.h:5242
constexpr bool is_end() const noexcept
return whether the iterator is at end
Definition: json.h:1455
const_reference at(const json_pointer &ptr) const
access specified element via JSON Pointer
Definition: json.h:7847
bool operator()(wpi::detail::value_t lhs, wpi::detail::value_t rhs) const noexcept
compare two value_t enum values
Definition: json.h:8116
friend bool operator!=(const_reference lhs, const ScalarType rhs) noexcept
comparison: not equal
Definition: json.h:6759
const_iterator cbegin() const noexcept
returns a const iterator to the first element
Definition: json.h:5643
std::string value(const json_pointer &ptr, const char *default_value) const
overload for a default value of type const char*
Definition: json.h:5158
static json object(initializer_list_t init={})
explicitly create an object from an initializer list
Definition: json.h:3478
Definition: optional.h:885
friend bool operator<=(const ScalarType lhs, const_reference rhs) noexcept
comparison: less than or equal
Definition: json.h:6866
value_t type() const noexcept
return the type of the JSON value (explicit)
Definition: json.h:3871
bool is_structured() const noexcept
return whether type is structured
Definition: json.h:3928
iterator begin() noexcept
returns an iterator to the first element
Definition: json.h:5603
reference value() const
return the value of an iterator
Definition: json.h:2321
void push_back(const std::pair< T, U > &val)
add an object to an object
Definition: json.h:6174
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:41
reference operator[](T *key)
access specified object element
Definition: json.h:4953
friend bool operator>=(const ScalarType lhs, const_reference rhs) noexcept
comparison: greater than or equal
Definition: json.h:6958
bool is_number_integer() const noexcept
return whether value is an integer number
Definition: json.h:4031
reference operator+=(initializer_list_t init)
add an object to an object
Definition: json.h:6236
reference operator[](difference_type n) const
access to successor
Definition: json.h:2308
WPILib C++ utilities (wpiutil) namespace.
Definition: SmallString.h:21
const_iterator end() const noexcept
returns a const iterator to one past the last element
Definition: json.h:5684
const_reverse_iterator rend() const noexcept
returns a const reverse iterator to one before the first
Definition: json.h:5789
void swap(std::string &other)
exchanges the values
Definition: json.h:6644
constexpr bool is_begin() const noexcept
return whether the iterator can be dereferenced
Definition: json.h:1449
json(json &&other) noexcept
move constructor
Definition: json.h:3710
json_reverse_iterator const operator--(int)
post-decrement (it–)
Definition: json.h:2272
reference at(const json_pointer &ptr)
access specified element via JSON Pointer
Definition: json.h:7804
void swap(object_t &other)
exchanges the values
Definition: json.h:6611
bool is_boolean() const noexcept
return whether value is a boolean
Definition: json.h:3972
reverse_iterator rbegin() noexcept
returns an iterator to the reverse-beginning
Definition: json.h:5744
static json array(initializer_list_t init={})
explicitly create an array from an initializer list
Definition: json.h:3435
iterator insert(const_iterator pos, json &&val)
inserts element
Definition: json.h:6366
static json parse(StringRef s, const parser_callback_t cb=nullptr, const bool allow_exceptions=true)
deserialize from a compatible input
ReferenceType get_ref()
get a reference value (implicit)
Definition: json.h:4619
a template for a bidirectional iterator for the json class
Definition: json.h:1561
iteration_proxy< iterator > items() noexcept
helper to access iterator member functions in range-based for
Definition: json.h:5905
json_reverse_iterator(const base_iterator &it) noexcept
create reverse iterator from base class
Definition: json.h:2257
friend bool operator>(const_reference lhs, const ScalarType rhs) noexcept
comparison: greater than
Definition: json.h:6901
proxy class for the items() function
Definition: json.h:1538
PointerType get_ptr() noexcept
get a pointer value (implicit)
Definition: json.h:4542
iteration_proxy(typename IteratorType::reference cont) noexcept
construct iteration proxy from a container
Definition: json.h:2204
Definition: raw_istream.h:26
reference operator[](const json_pointer &ptr)
access specified element via JSON Pointer
Definition: json.h:7733
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:896
reference operator+=(const std::pair< T, U > &val)
add an object to an object
Definition: json.h:6199
static parse_error create(int id_, std::size_t byte_, const Twine &what_arg)
create a parse error exception
const_reverse_iterator crbegin() const noexcept
returns a const reverse iterator to the last element
Definition: json.h:5818
bool is_array() const noexcept
return whether value is an array
Definition: json.h:4131
bool is_number_unsigned() const noexcept
return whether value is an unsigned integer number
Definition: json.h:4059
const int id
the id of the exception
Definition: json.h:482
number value (floating-point)
json(std::nullptr_t=nullptr) noexcept
create a null object
Definition: json.h:3245
friend bool operator<=(const_reference lhs, const ScalarType rhs) noexcept
comparison: less than or equal
Definition: json.h:6855
void set_end() noexcept
set iterator to a defined past the end
Definition: json.h:1443
exception indicating access out of the defined range
Definition: json.h:690
array (ordered collection of values)
ReferenceType get_ref() const
get a reference value (implicit)
Definition: json.h:4632
const_reverse_iterator rbegin() const noexcept
returns a const reverse iterator to the last element
Definition: json.h:5752
std::reverse_iterator< Base > base_iterator
shortcut to the reverse iterator adapter
Definition: json.h:2248
general exception of the json class
Definition: json.h:472
static void to_json(BasicJsonType &j, ValueType &&val) noexcept(noexcept(::wpi::to_json(j, std::forward< ValueType >(val))))
convert any value type to a JSON value
Definition: json.h:2645
json(CompatibleType &&val) noexcept(noexcept(adl_serializer< U, void >::to_json(std::declval< json_t & >(), std::forward< CompatibleType >(val))))
create a JSON value
Definition: json.h:3312
json_pointer(const Twine &s={})
create JSON pointer
Definition: json.h:2410
friend bool operator>=(const_reference lhs, const_reference rhs) noexcept
comparison: greater than or equal
Definition: json.h:6936
friend bool operator<=(const_reference lhs, const_reference rhs) noexcept
comparison: less than or equal
Definition: json.h:6844
bool operator<(const value_t lhs, const value_t rhs) noexcept
comparison operator for JSON types
Definition: json.h:783
bool is_string() const noexcept
return whether value is a string
Definition: json.h:4153
exception indicating other library errors
Definition: json.h:723
std::string value(StringRef key, const char *default_value) const
overload for a default value of type const char*
Definition: json.h:5087
json_reverse_iterator operator-(difference_type i) const
subtract from iterator
Definition: json.h:2296
std::pair< iterator, bool > emplace(StringRef key, Args &&...args)
add an object to an object if key does not exist
Definition: json.h:6312
json(const value_t v)
create an empty value with a given type
Definition: json.h:3221
number value (unsigned integer)
json(InputIT first, InputIT last)
construct a JSON container given an iterator range
Definition: json.h:3565
friend bool operator<(const_reference lhs, const ScalarType rhs) noexcept
comparison: less than
Definition: json.h:6809
an iterator value
Definition: json.h:1527
object (unordered set of name/value pairs)
auto key() const -> decltype(std::declval< Base >().key())
return the key of an object iterator
Definition: json.h:2314
friend bool operator!=(const ScalarType lhs, const_reference rhs) noexcept
comparison: not equal
Definition: json.h:6770
friend bool operator>(const ScalarType lhs, const_reference rhs) noexcept
comparison: greater than
Definition: json.h:6912
const std::size_t byte
byte index of the parse error
Definition: json.h:557
a class to store JSON values
Definition: json.h:2714
~json() noexcept
destructor
Definition: json.h:3780
reference back()
access the last element
Definition: json.h:5232
typename Base::reference reference
the reference type for the pointed-to element
Definition: json.h:2250
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
Definition: STLExtras.h:999
json_reverse_iterator & operator+=(difference_type i)
add to iterator
Definition: json.h:2284
iterator find(StringRef key)
find an element in a JSON object
bool is_number() const noexcept
return whether value is a number
Definition: json.h:4002
static void from_json(BasicJsonType &&j, ValueType &val) noexcept(noexcept(::wpi::from_json(std::forward< BasicJsonType >(j), val)))
convert a JSON value to any value type
Definition: json.h:2629
exception indicating a parse error
Definition: json.h:535
exception indicating errors with iterators
Definition: json.h:601
bool is_number_float() const noexcept
return whether value is a floating-point number
Definition: json.h:4087
const PointerType get_ptr() const noexcept
get a pointer value (implicit)
Definition: json.h:4570
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
const char * what() const noexceptoverride
returns the explanatory string
Definition: json.h:476
iteration_proxy_internal begin() noexcept
return iterator begin (needed for range-based for)
Definition: json.h:2208
reference & operator=(json other) noexcept(std::is_nothrow_move_constructible< value_t >::value andstd::is_nothrow_move_assignable< value_t >::value andstd::is_nothrow_move_constructible< json_value >::value andstd::is_nothrow_move_assignable< json_value >::value)
copy assignment
Definition: json.h:3747
bool is_object() const noexcept
return whether value is an object
Definition: json.h:4109
std::size_t size_type
a type to represent container sizes
Definition: json.h:2795
friend bool operator>=(const_reference lhs, const ScalarType rhs) noexcept
comparison: greater than or equal
Definition: json.h:6947
json unflatten() const
unflatten a previously flattened JSON value
Definition: json.h:7911
auto count(R &&Range, const E &Element) -> typename std::iterator_traits< decltype(adl_begin(Range))>::difference_type
Wrapper function around std::count to count the number of times an element Element occurs in the give...
Definition: STLExtras.h:941
std::string dump(const int indent=-1, const char indent_char= ' ', const bool ensure_ascii=false) const
serialization
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:205
json_reverse_iterator const operator++(int)
post-increment (it++)
Definition: json.h:2260
exception indicating executing a member function with a wrong type
Definition: json.h:649
void swap(reference other) noexcept(std::is_nothrow_move_constructible< value_t >::value andstd::is_nothrow_move_assignable< value_t >::value andstd::is_nothrow_move_constructible< json_value >::value andstd::is_nothrow_move_assignable< json_value >::value)
exchanges the values
Definition: json.h:6546
ValueType value(StringRef key, const ValueType &default_value) const
access specified object element with default value
Definition: json.h:5065
const_reference operator[](const json_pointer &ptr) const
access specified element via JSON Pointer
Definition: json.h:7761
const_reference front() const
access the first element
Definition: json.h:5196
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
const_iterator cend() const noexcept
returns a const iterator to one past the last element
Definition: json.h:5714
json_reverse_iterator(const typename base_iterator::iterator_type &it) noexcept
create reverse iterator from iterator
Definition: json.h:2253
void emplace_back(Args &&...args)
add an object to an array
Definition: json.h:6264
reverse_iterator rend() noexcept
returns an iterator to the reverse-end
Definition: json.h:5781
json_reverse_iterator & operator--()
pre-decrement (–it)
Definition: json.h:2278
void set_begin() noexcept
set iterator to a defined beginning
Definition: json.h:1437
const_reverse_iterator crend() const noexcept
returns a const reverse iterator to one before the first
Definition: json.h:5847
parse_event_t
parser event types
Definition: json.h:3114
const_iterator begin() const noexcept
returns a const iterator to the first element
Definition: json.h:5613
std::ptrdiff_t difference_type
a type to represent differences between iterators
Definition: json.h:2793
friend bool operator<(const ScalarType lhs, const_reference rhs) noexcept
comparison: less than
Definition: json.h:6820
discarded by the the parser callback function
difference_type operator-(const json_reverse_iterator &other) const
return difference
Definition: json.h:2302
std::allocator< json > allocator_type
the allocator type
Definition: json.h:2798
bool is_primitive() const noexcept
return whether type is primitive
Definition: json.h:3901
friend bool operator!=(const_reference lhs, const_reference rhs) noexcept
comparison: not equal
Definition: json.h:6748
json flatten() const
return flattened JSON value
Definition: json.h:7874
json_reverse_iterator & operator++()
pre-increment (++it)
Definition: json.h:2266
a template for a reverse iterator class
Definition: json.h:2243