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
176 #define NLOHMANN_JSON_HAS_HELPER(type) \
177 template<typename T> struct has_##type { \
179 template<typename U, typename = typename U::type> \
180 static int detect(U &&); \
181 static void detect(...); \
183 static constexpr bool value = \
184 std::is_integral<decltype(detect(std::declval<T>()))>::value; \
203 template<
typename>
struct is_json : std::false_type {};
208 template<
bool B,
typename T =
void>
209 using enable_if_t =
typename std::enable_if<B, T>::type;
212 using uncvref_t =
typename std::remove_cv<typename std::remove_reference<T>::type>::type;
224 template <
typename T,
typename =
void>
227 template <
typename T>
230 NLOHMANN_JSON_HAS_HELPER(mapped_type);
231 NLOHMANN_JSON_HAS_HELPER(key_type);
232 NLOHMANN_JSON_HAS_HELPER(value_type);
233 NLOHMANN_JSON_HAS_HELPER(iterator);
235 template<
bool B,
class RealType,
class CompatibleObjectType>
238 template<
class RealType,
class CompatibleObjectType>
241 static constexpr
auto value =
242 std::is_constructible<StringRef, typename CompatibleObjectType::key_type>::value and
243 std::is_constructible<typename RealType::mapped_type, typename CompatibleObjectType::mapped_type>::value;
246 template<
class BasicJsonType,
class CompatibleObjectType>
250 std::conjunction<std::negation<std::is_same<void, CompatibleObjectType>>,
251 has_mapped_type<CompatibleObjectType>,
252 has_key_type<CompatibleObjectType>>::value,
253 typename BasicJsonType::object_t, CompatibleObjectType >::value;
256 template<
typename BasicJsonType,
typename T>
259 static auto constexpr value = std::is_same<T, typename BasicJsonType::iterator>::value or
260 std::is_same<T, typename BasicJsonType::const_iterator>::value or
261 std::is_same<T, typename BasicJsonType::reverse_iterator>::value or
262 std::is_same<T, typename BasicJsonType::const_reverse_iterator>::value;
265 template<
class BasicJsonType,
class CompatibleArrayType>
268 static auto constexpr value =
269 std::conjunction<std::negation<std::is_same<void, CompatibleArrayType>>,
271 BasicJsonType, CompatibleArrayType>>,
272 std::negation<std::is_constructible<
StringRef,
273 CompatibleArrayType>>,
274 std::negation<is_json_nested_type<BasicJsonType, CompatibleArrayType>>,
275 has_value_type<CompatibleArrayType>,
276 has_iterator<CompatibleArrayType>>::value;
279 template<
bool,
typename,
typename>
282 template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
286 using RealLimits = std::numeric_limits<RealIntegerType>;
287 using CompatibleLimits = std::numeric_limits<CompatibleNumberIntegerType>;
289 static constexpr
auto value =
290 std::is_constructible<RealIntegerType, CompatibleNumberIntegerType>::value and
291 CompatibleLimits::is_integer and
292 RealLimits::is_signed == CompatibleLimits::is_signed;
295 template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
298 static constexpr
auto value =
300 std::is_integral<CompatibleNumberIntegerType>::value and
301 not std::is_same<bool, CompatibleNumberIntegerType>::value,
302 RealIntegerType, CompatibleNumberIntegerType > ::value;
306 template<
typename BasicJsonType,
typename T>
311 template<
typename U,
typename = enable_if_t<std::is_same<
void, decltype(uncvref_t<U>::from_json(
312 std::declval<BasicJsonType>(), std::declval<T&>()))>::value>>
313 static int detect(U&&);
314 static void detect(...);
317 static constexpr
bool value = std::is_integral<decltype(
318 detect(std::declval<
typename BasicJsonType::template json_serializer<T, void>>()))>::value;
323 template<
typename BasicJsonType,
typename T>
329 typename = enable_if_t<std::is_same<
330 T, decltype(uncvref_t<U>::from_json(std::declval<BasicJsonType>()))>::value >>
331 static int detect(U&&);
332 static void detect(...);
335 static constexpr
bool value = std::is_integral<decltype(detect(
336 std::declval<
typename BasicJsonType::template json_serializer<T, void>>()))>::value;
340 template<
typename BasicJsonType,
typename T>
344 template<
typename U,
typename = decltype(uncvref_t<U>::to_json(
345 std::declval<BasicJsonType&>(), std::declval<T>()))>
346 static int detect(U&&);
347 static void detect(...);
350 static constexpr
bool value = std::is_integral<decltype(detect(
351 std::declval<
typename BasicJsonType::template json_serializer<T, void>>()))>::value;
354 template <
typename BasicJsonType,
typename CompatibleCompleteType>
357 static constexpr
bool value =
358 not std::is_base_of<std::istream, CompatibleCompleteType>::value and
364 template <
typename BasicJsonType,
typename CompatibleType>
366 : std::conjunction<is_complete_type<CompatibleType>,
367 is_compatible_complete_type<BasicJsonType, CompatibleType>>
375 static constexpr T value{};
417 const char*
what() const noexcept
override
430 std::runtime_error m;
726 static constexpr std::array<std::uint8_t, 8> order = {{
732 const auto l_index = static_cast<std::size_t>(lhs);
733 const auto r_index = static_cast<std::size_t>(rhs);
734 return l_index < order.size() and r_index < order.size() and order[l_index] < order[r_index];
738 template<
typename BasicJsonType,
typename ArithmeticType,
739 enable_if_t<std::is_arithmetic<ArithmeticType>::value and
740 not std::is_same<ArithmeticType, bool>::value,
742 void get_arithmetic_value(
const BasicJsonType& j, ArithmeticType& val)
744 switch (static_cast<value_t>(j))
748 val = static_cast<ArithmeticType>(*j.template get_ptr<const uint64_t*>());
753 val = static_cast<ArithmeticType>(*j.template get_ptr<const int64_t*>());
758 val = static_cast<ArithmeticType>(*j.template get_ptr<const double*>());
763 JSON_THROW(type_error::create(302,
"type must be number, but is " + Twine(j.type_name())));
767 template<
typename BasicJsonType>
768 void from_json(
const BasicJsonType& j,
bool& b)
770 if (JSON_UNLIKELY(not j.is_boolean()))
772 JSON_THROW(type_error::create(302,
"type must be boolean, but is " + Twine(j.type_name())));
774 b = *j.template get_ptr<const bool*>();
777 template<
typename BasicJsonType>
778 void from_json(
const BasicJsonType& j,
std::string& s)
780 if (JSON_UNLIKELY(not j.is_string()))
782 JSON_THROW(type_error::create(302,
"type must be string, but is " + Twine(j.type_name())));
784 s = *j.template get_ptr<const std::string*>();
787 template<
typename BasicJsonType>
788 void from_json(
const BasicJsonType& j,
double& val)
790 get_arithmetic_value(j, val);
793 template<
typename BasicJsonType>
794 void from_json(
const BasicJsonType& j, uint64_t& val)
796 get_arithmetic_value(j, val);
799 template<
typename BasicJsonType>
800 void from_json(
const BasicJsonType& j, int64_t& val)
802 get_arithmetic_value(j, val);
805 template<
typename BasicJsonType,
typename EnumType,
806 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
807 void from_json(
const BasicJsonType& j, EnumType& e)
809 typename std::underlying_type<EnumType>::type val;
810 get_arithmetic_value(j, val);
811 e = static_cast<EnumType>(val);
814 template<
typename BasicJsonType>
815 void from_json(
const BasicJsonType& j,
typename BasicJsonType::array_t& arr)
817 if (JSON_UNLIKELY(not j.is_array()))
819 JSON_THROW(type_error::create(302,
"type must be array, but is " + Twine(j.type_name())));
821 arr = *j.template get_ptr<const typename BasicJsonType::array_t*>();
824 template<
typename BasicJsonType,
typename CompatibleArrayType>
825 void from_json_array_impl(
const BasicJsonType& j, CompatibleArrayType& arr, priority_tag<0> )
829 std::transform(j.begin(), j.end(),
830 std::inserter(arr, end(arr)), [](
const BasicJsonType & i)
834 return i.template get<typename CompatibleArrayType::value_type>();
838 template<
typename BasicJsonType,
typename CompatibleArrayType>
839 auto from_json_array_impl(
const BasicJsonType& j, CompatibleArrayType& arr, priority_tag<1> )
841 arr.reserve(std::declval<typename CompatibleArrayType::size_type>()),
846 arr.reserve(j.size());
847 std::transform(j.begin(), j.end(),
848 std::inserter(arr, end(arr)), [](
const BasicJsonType & i)
852 return i.template get<typename CompatibleArrayType::value_type>();
856 template<
typename BasicJsonType,
typename T, std::
size_t N>
857 void from_json_array_impl(
const BasicJsonType& j, std::array<T, N>& arr, priority_tag<2> )
859 for (std::size_t i = 0; i < N; ++i)
861 arr[i] = j.at(i).template get<T>();
866 typename BasicJsonType,
typename CompatibleArrayType,
868 is_compatible_array_type<BasicJsonType, CompatibleArrayType>::value and
869 not std::is_same<
typename BasicJsonType::array_t,
870 CompatibleArrayType>::value and
871 std::is_constructible <
872 BasicJsonType,
typename CompatibleArrayType::value_type >::value,
874 void from_json(
const BasicJsonType& j, CompatibleArrayType& arr)
876 if (JSON_UNLIKELY(not j.is_array()))
878 JSON_THROW(type_error::create(302,
"type must be array, but is " +
879 Twine(j.type_name())));
882 from_json_array_impl(j, arr, priority_tag<2> {});
885 template<
typename BasicJsonType>
887 void from_json(
const BasicJsonType& j,
typename BasicJsonType::object_t& obj)
891 JSON_THROW(type_error::create(302,
"type must be object, but is " + Twine(j.type_name())));
894 auto inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
895 for (
const auto& i : *inner_object) {
896 obj.try_emplace(i.first(), i.second);
900 template<
typename BasicJsonType,
typename CompatibleObjectType,
901 enable_if_t<is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value and
902 not std::is_same<typename BasicJsonType::object_t, CompatibleObjectType>::value,
int> = 0>
903 void from_json(
const BasicJsonType& j, CompatibleObjectType& obj)
905 if (JSON_UNLIKELY(not j.is_object()))
907 JSON_THROW(type_error::create(302,
"type must be object, but is " + Twine(j.type_name())));
910 auto inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
913 using value_type =
typename CompatibleObjectType::value_type;
914 std::vector<value_type> v;
916 for (
const auto& p : *inner_object)
921 .template get<typename CompatibleObjectType::mapped_type>());
926 obj = CompatibleObjectType(std::make_move_iterator(begin(v)),
927 std::make_move_iterator(end(v)));
934 template<
typename BasicJsonType,
typename ArithmeticType,
936 std::is_arithmetic<ArithmeticType>::value and
937 not std::is_same<ArithmeticType, uint64_t>::value and
938 not std::is_same<ArithmeticType, int64_t>::value and
939 not std::is_same<ArithmeticType, double>::value and
940 not std::is_same<ArithmeticType, bool>::value,
942 void from_json(
const BasicJsonType& j, ArithmeticType& val)
944 switch (static_cast<value_t>(j))
948 val = static_cast<ArithmeticType>(*j.template get_ptr<const uint64_t*>());
953 val = static_cast<ArithmeticType>(*j.template get_ptr<const int64_t*>());
958 val = static_cast<ArithmeticType>(*j.template get_ptr<const double*>());
963 val = static_cast<ArithmeticType>(*j.template get_ptr<const bool*>());
968 JSON_THROW(type_error::create(302,
"type must be number, but is " + Twine(j.type_name())));
972 template<
typename BasicJsonType,
typename A1,
typename A2>
973 void from_json(
const BasicJsonType& j, std::pair<A1, A2>& p)
975 p = {j.at(0).template get<A1>(), j.at(1).template get<A2>()};
978 template<
typename BasicJsonType,
typename Tuple, std::size_t... Idx>
979 void from_json_tuple_impl(
const BasicJsonType& j, Tuple& t, std::index_sequence<Idx...>)
981 t = std::make_tuple(j.at(Idx).template get<typename std::tuple_element<Idx, Tuple>::type>()...);
984 template<
typename BasicJsonType,
typename... Args>
985 void from_json(
const BasicJsonType& j, std::tuple<Args...>& t)
987 from_json_tuple_impl(j, t, std::index_sequence_for<Args...> {});
993 template<
typename BasicJsonType,
typename T>
995 noexcept(noexcept(from_json(j, val)))
996 -> decltype(from_json(j, val),
void())
998 return from_json(j, val);
1001 template<
typename BasicJsonType,
typename T>
1002 void call(
const BasicJsonType& , T& ,
priority_tag<0> )
const noexcept
1004 static_assert(
sizeof(BasicJsonType) == 0,
1005 "could not find from_json() method in T's namespace");
1008 using decayed = uncvref_t<T>;
1009 static_assert(
sizeof(
typename decayed::force_msvc_stacktrace) == 0,
1010 "forcing MSVC stacktrace to show which T we're talking about.");
1015 template<
typename BasicJsonType,
typename T>
1016 void operator()(
const BasicJsonType& j, T& val)
const
1017 noexcept(noexcept(std::declval<from_json_fn>().call(j, val,
priority_tag<1> {})))
1043 template<
typename BasicJsonType>
1044 static void construct(BasicJsonType& j,
bool b) noexcept
1048 j.assert_invariant();
1055 template<
typename BasicJsonType>
1056 static void construct(BasicJsonType& j,
StringRef s)
1060 j.assert_invariant();
1063 template<
typename BasicJsonType,
typename T,
1064 enable_if_t<std::is_same<std::string, T>::value,
int> = 0>
1065 static void construct(BasicJsonType& j, T&& s)
1068 j.m_value = std::move(s);
1069 j.assert_invariant();
1076 template<
typename BasicJsonType>
1077 static void construct(BasicJsonType& j,
double val) noexcept
1081 j.assert_invariant();
1088 template<
typename BasicJsonType>
1089 static void construct(BasicJsonType& j, uint64_t val) noexcept
1093 j.assert_invariant();
1100 template<
typename BasicJsonType>
1101 static void construct(BasicJsonType& j, int64_t val) noexcept
1105 j.assert_invariant();
1112 template<
typename BasicJsonType>
1113 static void construct(BasicJsonType& j,
const typename BasicJsonType::array_t& arr)
1117 j.assert_invariant();
1120 template<
typename BasicJsonType>
1121 static void construct(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
1124 j.m_value = std::move(arr);
1125 j.assert_invariant();
1128 template<
typename BasicJsonType,
typename T>
1129 static void construct(BasicJsonType& j,
ArrayRef<T> arr)
1134 j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
1135 j.assert_invariant();
1138 template<
typename BasicJsonType,
typename CompatibleArrayType,
1139 enable_if_t<not std::is_same<CompatibleArrayType, typename BasicJsonType::array_t>::value,
1141 static void construct(BasicJsonType& j,
const CompatibleArrayType& arr)
1146 j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
1147 j.assert_invariant();
1150 template<
typename BasicJsonType>
1151 static void construct(BasicJsonType& j,
const std::vector<bool>& arr)
1155 j.m_value.array->reserve(arr.size());
1156 for (
const bool x : arr)
1158 j.m_value.array->push_back(x);
1160 j.assert_invariant();
1167 template<
typename BasicJsonType>
1168 static void construct(BasicJsonType& j,
const typename BasicJsonType::object_t& obj)
1172 j.assert_invariant();
1175 template<
typename BasicJsonType>
1176 static void construct(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
1179 j.m_value = std::move(obj);
1180 j.assert_invariant();
1183 template<
typename BasicJsonType,
typename CompatibleObjectType,
1184 enable_if_t<not std::is_same<CompatibleObjectType, typename BasicJsonType::object_t>::value,
int> = 0>
1185 static void construct(BasicJsonType& j,
const CompatibleObjectType& obj)
1189 for (
const auto& x : obj)
1191 j.m_value.object->try_emplace(x.first, x.second);
1193 j.assert_invariant();
1201 template<
typename BasicJsonType,
typename T,
1202 enable_if_t<std::is_same<T, bool>::value,
int> = 0>
1203 void to_json(BasicJsonType& j, T b) noexcept
1208 template<
typename BasicJsonType,
typename CompatibleString,
1209 enable_if_t<std::is_constructible<StringRef, CompatibleString>::value,
int> = 0>
1210 void to_json(BasicJsonType& j,
const CompatibleString& s)
1212 external_constructor<value_t::string>::construct(j, s);
1215 template<
typename BasicJsonType,
typename T,
1216 enable_if_t<std::is_same<std::string, T>::value,
int> = 0>
1217 void to_json(BasicJsonType& j, T&& s)
1219 external_constructor<value_t::string>::construct(j, std::move(s));
1222 template<
typename BasicJsonType,
typename FloatType,
1223 enable_if_t<std::is_floating_point<FloatType>::value,
int> = 0>
1224 void to_json(BasicJsonType& j, FloatType val) noexcept
1226 external_constructor<value_t::number_float>::construct(j, static_cast<double>(val));
1229 template<
typename BasicJsonType,
typename CompatibleNumberUnsignedType,
1230 enable_if_t<is_compatible_integer_type<uint64_t, CompatibleNumberUnsignedType>::value,
int> = 0>
1231 void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val) noexcept
1233 external_constructor<value_t::number_unsigned>::construct(j, static_cast<uint64_t>(val));
1236 template<
typename BasicJsonType,
typename CompatibleNumberIntegerType,
1237 enable_if_t<is_compatible_integer_type<int64_t, CompatibleNumberIntegerType>::value,
int> = 0>
1238 void to_json(BasicJsonType& j, CompatibleNumberIntegerType val) noexcept
1240 external_constructor<value_t::number_integer>::construct(j, static_cast<int64_t>(val));
1243 template<
typename BasicJsonType,
typename EnumType,
1244 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
1245 void to_json(BasicJsonType& j, EnumType e) noexcept
1247 using underlying_type =
typename std::underlying_type<EnumType>::type;
1248 external_constructor<value_t::number_integer>::construct(j, static_cast<underlying_type>(e));
1251 template<
typename BasicJsonType>
1252 void to_json(BasicJsonType& j,
const std::vector<bool>& e)
1254 external_constructor<value_t::array>::construct(j, e);
1257 template<
typename BasicJsonType,
typename CompatibleArrayType,
1258 enable_if_t<is_compatible_array_type<BasicJsonType, CompatibleArrayType>::value or
1259 std::is_same<typename BasicJsonType::array_t, CompatibleArrayType>::value,
1261 void to_json(BasicJsonType& j,
const CompatibleArrayType& arr)
1263 external_constructor<value_t::array>::construct(j, arr);
1266 template<
typename BasicJsonType>
1267 void to_json(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
1269 external_constructor<value_t::array>::construct(j, std::move(arr));
1272 template<
typename BasicJsonType,
typename CompatibleObjectType,
1273 enable_if_t<is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value,
int> = 0>
1274 void to_json(BasicJsonType& j,
const CompatibleObjectType& obj)
1276 external_constructor<value_t::object>::construct(j, obj);
1279 template<
typename BasicJsonType>
1280 void to_json(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
1282 external_constructor<value_t::object>::construct(j, std::move(obj));
1285 template<
typename BasicJsonType,
typename T, std::size_t N,
1286 enable_if_t<not std::is_constructible<StringRef, T (&)[N]>::value,
int> = 0>
1287 void to_json(BasicJsonType& j, T (&arr)[N])
1289 external_constructor<value_t::array>::construct(j, arr);
1292 template<
typename BasicJsonType,
typename... Args>
1293 void to_json(BasicJsonType& j,
const std::pair<Args...>& p)
1295 j = {p.first, p.second};
1298 template<
typename BasicJsonType,
typename Tuple, std::size_t... Idx>
1299 void to_json_tuple_impl(BasicJsonType& j,
const Tuple& t, std::index_sequence<Idx...>)
1301 j = {std::get<Idx>(t)...};
1304 template<
typename BasicJsonType,
typename... Args>
1305 void to_json(BasicJsonType& j,
const std::tuple<Args...>& t)
1307 to_json_tuple_impl(j, t, std::index_sequence_for<Args...> {});
1313 template<
typename BasicJsonType,
typename T>
1314 auto call(BasicJsonType& j, T&& val,
priority_tag<1> )
const noexcept(noexcept(to_json(j, std::forward<T>(val))))
1315 -> decltype(to_json(j, std::forward<T>(val)),
void())
1317 return to_json(j, std::forward<T>(val));
1320 template<
typename BasicJsonType,
typename T>
1323 static_assert(
sizeof(BasicJsonType) == 0,
1324 "could not find to_json() method in T's namespace");
1328 using decayed = uncvref_t<T>;
1329 static_assert(
sizeof(
typename decayed::force_msvc_stacktrace) == 0,
1330 "forcing MSVC stacktrace to show which T we're talking about.");
1335 template<
typename BasicJsonType,
typename T>
1336 void operator()(BasicJsonType& j, T&& val)
const
1337 noexcept(noexcept(std::declval<to_json_fn>().call(j, std::forward<T>(val),
priority_tag<1> {})))
1364 using difference_type = std::ptrdiff_t;
1365 static constexpr difference_type begin_value = 0;
1366 static constexpr difference_type end_value = begin_value + 1;
1369 difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)();
1372 constexpr difference_type get_value()
const noexcept
1392 return m_it == begin_value;
1398 return m_it == end_value;
1403 return lhs.m_it == rhs.m_it;
1406 friend constexpr
bool operator<(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
1408 return lhs.m_it < rhs.m_it;
1411 primitive_iterator_t operator+(difference_type n) noexcept
1413 auto result = *
this;
1418 friend constexpr difference_type operator-(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
1420 return lhs.m_it - rhs.m_it;
1423 primitive_iterator_t& operator++() noexcept
1429 primitive_iterator_t
const operator++(
int) noexcept
1431 auto result = *
this;
1436 primitive_iterator_t& operator--() noexcept
1442 primitive_iterator_t
const operator--(
int) noexcept
1444 auto result = *
this;
1449 primitive_iterator_t& operator+=(difference_type n) noexcept
1455 primitive_iterator_t& operator-=(difference_type n) noexcept
1501 template<
typename BasicJsonType>
1506 friend BasicJsonType;
1508 friend class ::wpi::JsonTest;
1510 using object_t =
typename BasicJsonType::object_t;
1511 using array_t =
typename BasicJsonType::array_t;
1513 static_assert(
is_json<
typename std::remove_const<BasicJsonType>::type>::
value,
1514 "iter_impl only accepts (const) json");
1530 using pointer =
typename std::conditional<std::is_const<BasicJsonType>::value,
1531 typename BasicJsonType::const_pointer,
1532 typename BasicJsonType::pointer>::type;
1535 typename std::conditional<std::is_const<BasicJsonType>::value,
1536 typename BasicJsonType::const_reference,
1537 typename BasicJsonType::reference>::type;
1550 assert(m_object !=
nullptr);
1552 switch (m_object->m_type)
1589 : m_object(other.m_object), m_it(other.m_it) {}
1599 m_object = other.m_object;
1609 void set_begin() noexcept
1611 assert(m_object !=
nullptr);
1613 switch (m_object->m_type)
1646 void set_end() noexcept
1648 assert(m_object !=
nullptr);
1650 switch (m_object->m_type)
1679 assert(m_object !=
nullptr);
1681 switch (m_object->m_type)
1696 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
1705 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
1716 assert(m_object !=
nullptr);
1718 switch (m_object->m_type)
1739 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
1750 auto result = *
this;
1761 assert(m_object !=
nullptr);
1763 switch (m_object->m_type)
1793 auto result = *
this;
1804 assert(m_object !=
nullptr);
1806 switch (m_object->m_type)
1837 if (JSON_UNLIKELY(m_object != other.m_object))
1839 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers"));
1842 assert(m_object !=
nullptr);
1844 switch (m_object->m_type)
1873 if (JSON_UNLIKELY(m_object != other.m_object))
1875 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers"));
1878 assert(m_object !=
nullptr);
1880 switch (m_object->m_type)
1883 JSON_THROW(invalid_iterator::create(213,
"cannot compare order of object iterators"));
1899 return not other.operator < (*this);
1926 assert(m_object !=
nullptr);
1928 switch (m_object->m_type)
1931 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators"));
1964 auto result = *
this;
1986 auto result = *
this;
1997 assert(m_object !=
nullptr);
1999 switch (m_object->m_type)
2002 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators"));
2018 assert(m_object !=
nullptr);
2020 switch (m_object->m_type)
2023 JSON_THROW(invalid_iterator::create(208,
"cannot use operator[] for object iterators"));
2029 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
2038 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
2049 assert(m_object !=
nullptr);
2051 if (JSON_LIKELY(m_object->is_object()))
2056 JSON_THROW(invalid_iterator::create(207,
"cannot use key() for non-object iterators"));
2076 template<
typename IteratorType>
class iteration_proxy
2080 class iteration_proxy_internal
2084 IteratorType anchor;
2086 std::size_t array_index = 0;
2089 explicit iteration_proxy_internal(IteratorType it) noexcept : anchor(it) {}
2092 iteration_proxy_internal& operator*()
2098 iteration_proxy_internal& operator++()
2107 bool operator!=(
const iteration_proxy_internal& o)
const noexcept
2109 return anchor != o.anchor;
2115 assert(anchor.m_object !=
nullptr);
2117 switch (anchor.m_object->type())
2121 return std::to_string(array_index);
2125 return anchor.key();
2134 typename IteratorType::reference value()
const
2136 return anchor.value();
2141 typename IteratorType::reference container;
2146 : container(cont) {}
2149 iteration_proxy_internal
begin() noexcept
2151 return iteration_proxy_internal(container.begin());
2155 iteration_proxy_internal
end() noexcept
2157 return iteration_proxy_internal(container.end());
2183 template<
typename Base>
2187 using difference_type = std::ptrdiff_t;
2203 return static_cast<json_reverse_iterator>(base_iterator::operator++(1));
2209 return static_cast<json_reverse_iterator&>(base_iterator::operator++());
2215 return static_cast<json_reverse_iterator>(base_iterator::operator--(1));
2221 return static_cast<json_reverse_iterator&>(base_iterator::operator--());
2227 return static_cast<json_reverse_iterator&>(base_iterator::operator+=(i));
2233 return static_cast<json_reverse_iterator>(base_iterator::operator+(i));
2239 return static_cast<json_reverse_iterator>(base_iterator::operator-(i));
2255 auto key() const -> decltype(std::declval<Base>().
key())
2257 auto it = --this->base();
2264 auto it = --this->base();
2265 return it.operator * ();
2269 template<
typename BasicJsonType>
2273 using value_type = BasicJsonType;
2276 : owned_value(std::move(value)), value_ref(&owned_value), is_rvalue(
true)
2280 : value_ref(const_cast<value_type*>(&value)), is_rvalue(
false)
2283 json_ref(std::initializer_list<json_ref> init)
2284 : owned_value(init), value_ref(&owned_value), is_rvalue(
true)
2287 template<
class... Args>
2289 : owned_value(std::forward<Args>(args)...), value_ref(&owned_value), is_rvalue(
true)
2297 value_type moved_or_copied()
const
2301 return std::move(*value_ref);
2306 value_type
const& operator*()
const
2308 return *static_cast<value_type const*>(value_ref);
2311 value_type
const* operator->()
const
2313 return static_cast<value_type const*>(value_ref);
2317 mutable value_type owned_value =
nullptr;
2318 value_type* value_ref =
nullptr;
2319 const bool is_rvalue;
2327 friend class JsonTest;
2352 : reference_tokens(split(s))
2373 operator std::
string()
const
2392 std::string pop_back()
2394 if (JSON_UNLIKELY(is_root()))
2396 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent"));
2399 auto last = reference_tokens.back();
2400 reference_tokens.pop_back();
2405 bool is_root()
const
2407 return reference_tokens.empty();
2412 if (JSON_UNLIKELY(is_root()))
2414 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent"));
2418 result.reference_tokens = {reference_tokens[0]};
2430 json& get_and_create(json& j)
const;
2451 json& get_unchecked(json* ptr)
const;
2459 json& get_checked(json* ptr)
const;
2474 const json& get_unchecked(
const json* ptr)
const;
2482 const json& get_checked(
const json* ptr)
const;
2493 static std::vector<std::string> split(
const Twine& reference_string);
2508 static void replace_substring(std::string& s,
const std::string& f,
2509 const std::string& t);
2512 static std::string escape(std::string s);
2515 static void unescape(std::string& s);
2524 static void flatten(
const Twine& reference_string,
2539 unflatten(
const json& value);
2544 return (lhs.reference_tokens == rhs.reference_tokens);
2550 return not (lhs == rhs);
2554 std::vector<std::string> reference_tokens;
2557 template<
typename,
typename>
2558 struct adl_serializer
2569 template<
typename BasicJsonType,
typename ValueType>
2570 static void from_json(BasicJsonType&& j, ValueType& val) noexcept(
2571 noexcept(::wpi::from_json(std::forward<BasicJsonType>(j), val)))
2573 ::wpi::from_json(std::forward<BasicJsonType>(j), val);
2585 template<
typename BasicJsonType,
typename ValueType>
2586 static void to_json(BasicJsonType& j, ValueType&& val) noexcept(
2587 noexcept(::wpi::to_json(j, std::forward<ValueType>(val))))
2589 ::wpi::to_json(j, std::forward<ValueType>(val));
2659 friend ::wpi::json_pointer;
2660 template<
typename BasicJsonType>
2661 friend class ::wpi::detail::iter_impl;
2662 friend class JsonTest;
2669 template<
typename BasicJsonType>
2671 template<
typename BasicJsonType>
2673 template<
typename Iterator>
2677 class binary_reader;
2678 class binary_writer;
2687 template<
typename T,
typename SFINAE>
2806 using object_comparator_t = std::less<>;
2897 template<
typename T,
typename... Args>
2898 static T* create(Args&& ... args)
2900 std::allocator<T> alloc;
2902 using AllocatorTraits = std::allocator_traits<std::allocator<T>>;
2904 auto deleter = [&](T *
object)
2906 AllocatorTraits::deallocate(alloc,
object, 1);
2908 std::unique_ptr<T, decltype(deleter)>
object(AllocatorTraits::allocate(alloc, 1), deleter);
2909 AllocatorTraits::construct(alloc,
object.
get(), std::forward<Args>(args)...);
2910 assert(
object !=
nullptr);
2911 return object.release();
2949 std::string* string;
2953 int64_t number_integer;
2955 uint64_t number_unsigned;
2957 double number_float;
2960 json_value() =
default;
2962 json_value(
bool v) noexcept : boolean(v) {}
2964 json_value(int64_t v) noexcept : number_integer(v) {}
2970 json_value(value_t t);
2973 json_value(StringRef
value)
2975 string = create<std::string>(
value);
2979 json_value(
const std::string&
value)
2981 string = create<std::string>(
value);
2985 json_value(std::string&&
value)
2987 string = create<std::string>(std::move(
value));
2993 object = create<object_t>(
value);
2999 object = create<object_t>(std::move(
value));
3014 void destroy(value_t t) noexcept;
3026 void assert_invariant() const noexcept
3161 : m_type(v), m_value(v)
3184 json(std::nullptr_t =
nullptr) noexcept
3247 template <
typename CompatibleType,
3248 typename U = detail::uncvref_t<CompatibleType>,
3249 detail::enable_if_t<
3251 json(CompatibleType && val) noexcept(noexcept(
3253 std::forward<CompatibleType>(val))))
3334 bool type_deduction =
true,
3501 template<
class InputIT,
typename std::enable_if<
3502 std::is_same<InputIT, typename json_t::iterator>::value or
3503 std::is_same<InputIT, typename json_t::const_iterator>::value,
int>
::type = 0>
3506 assert(first.m_object !=
nullptr);
3507 assert(last.m_object !=
nullptr);
3510 if (JSON_UNLIKELY(first.m_object != last.m_object))
3512 JSON_THROW(invalid_iterator::create(201,
"iterators are not compatible"));
3516 m_type = first.m_object->m_type;
3527 if (JSON_UNLIKELY(not first.m_it.primitive_iterator.is_begin()
3528 or not last.m_it.primitive_iterator.is_end()))
3530 JSON_THROW(invalid_iterator::create(204,
"iterators out of range"));
3543 m_value.number_integer = first.m_object->m_value.number_integer;
3549 m_value.number_unsigned = first.m_object->m_value.number_unsigned;
3555 m_value.number_float = first.m_object->m_value.number_float;
3561 m_value.boolean = first.m_object->m_value.boolean;
3567 m_value = *first.m_object->m_value.string;
3573 m_value.array = create<array_t>(first.m_it.array_iterator,
3574 last.m_it.array_iterator);
3579 JSON_THROW(invalid_iterator::create(206,
"cannot construct with iterators from " +
3580 Twine(first.m_object->type_name())));
3593 :
json(ref.moved_or_copied())
3650 : m_type(std::move(other.m_type)),
3651 m_value(std::move(other.m_value))
3654 other.assert_invariant();
3657 other.m_type = value_t::null;
3687 std::is_nothrow_move_constructible<value_t>::value and
3688 std::is_nothrow_move_assignable<value_t>::value and
3689 std::is_nothrow_move_constructible<json_value>::value and
3690 std::is_nothrow_move_assignable<json_value>::value
3694 other.assert_invariant();
3697 swap(m_type, other.m_type);
3698 swap(m_value, other.m_value);
3722 m_value.destroy(m_type);
3772 std::string
dump(
const int indent = -1,
const char indent_char =
' ',
3773 const bool ensure_ascii =
false)
const;
3775 void dump(
raw_ostream& os,
int indent = -1,
const char indent_char =
' ',
3776 const bool ensure_ascii =
false)
const;
3891 return (m_type == value_t::null);
4121 return (m_type == value_t::discarded);
4158 bool get_impl(
bool* )
const
4162 return m_value.boolean;
4165 JSON_THROW(type_error::create(302,
"type must be boolean, but is " + Twine(
type_name())));
4171 return is_object() ? m_value.object :
nullptr;
4177 return is_object() ? m_value.object :
nullptr;
4183 return is_array() ? m_value.array :
nullptr;
4189 return is_array() ? m_value.array :
nullptr;
4193 std::string* get_impl_ptr(std::string* ) noexcept
4195 return is_string() ? m_value.string :
nullptr;
4199 const std::string* get_impl_ptr(
const std::string* )
const noexcept
4201 return is_string() ? m_value.string :
nullptr;
4205 bool* get_impl_ptr(
bool* ) noexcept
4207 return is_boolean() ? &m_value.boolean :
nullptr;
4211 const bool* get_impl_ptr(
const bool* )
const noexcept
4213 return is_boolean() ? &m_value.boolean :
nullptr;
4217 int64_t* get_impl_ptr(int64_t* ) noexcept
4223 const int64_t* get_impl_ptr(
const int64_t* )
const noexcept
4229 uint64_t* get_impl_ptr(uint64_t* ) noexcept
4235 const uint64_t* get_impl_ptr(
const uint64_t* )
const noexcept
4241 double* get_impl_ptr(
double* ) noexcept
4247 const double* get_impl_ptr(
const double* )
const noexcept
4263 template<
typename ReferenceType,
typename ThisType>
4264 static ReferenceType get_ref_impl(ThisType& obj)
4267 auto ptr = obj.template get_ptr<typename std::add_pointer<ReferenceType>::type>();
4269 if (JSON_LIKELY(ptr !=
nullptr))
4274 JSON_THROW(type_error::create(303,
"incompatible ReferenceType for get_ref, actual type is " + Twine(obj.type_name())));
4296 template<
typename BasicJsonType, detail::enable_if_t<
4297 std::is_same<typename std::remove_const<BasicJsonType>::type, json_t>
::value,
4343 template<
typename ValueTypeCV,
typename ValueType = detail::uncvref_t<ValueTypeCV>,
4344 detail::enable_if_t <
4345 not detail::is_json<ValueType>::value and
4346 detail::has_from_json<json_t, ValueType>::value and
4347 not detail::has_non_default_from_json<json_t, ValueType>::value,
4349 ValueType
get() const noexcept(noexcept(
4350 adl_serializer<ValueType,
void>::from_json(std::declval<const
json_t&>(), std::declval<ValueType&>())))
4355 static_assert(not std::is_reference<ValueTypeCV>::value,
4356 "get() cannot be used with reference types, you might want to use get_ref()");
4357 static_assert(std::is_default_constructible<ValueType>::value,
4358 "types must be DefaultConstructible when used with get()");
4396 template<
typename ValueTypeCV,
typename ValueType = detail::uncvref_t<ValueTypeCV>,
4397 detail::enable_if_t<not std::is_same<json_t, ValueType>::value and
4398 detail::has_non_default_from_json<json_t, ValueType>::value,
4400 ValueType
get() const noexcept(noexcept(
4403 static_assert(not std::is_reference<ValueTypeCV>::value,
4404 "get() cannot be used with reference types, you might want to use get_ref()");
4434 template<
typename PointerType,
typename std::enable_if<
4435 std::is_pointer<PointerType>::value,
int>
::type = 0>
4439 return get_ptr<PointerType>();
4446 template<
typename PointerType,
typename std::enable_if<
4447 std::is_pointer<PointerType>::value,
int>
::type = 0>
4448 const PointerType
get() const noexcept
4451 return get_ptr<PointerType>();
4479 template<
typename PointerType,
typename std::enable_if<
4480 std::is_pointer<PointerType>::value,
int>
::type = 0>
4484 using pointee_t =
typename std::remove_const<
typename
4485 std::remove_pointer<
typename
4489 std::is_same<object_t, pointee_t>::value
4490 or std::is_same<array_t, pointee_t>::value
4491 or std::is_same<std::string, pointee_t>::value
4492 or std::is_same<bool, pointee_t>::value
4493 or std::is_same<int64_t, pointee_t>::value
4494 or std::is_same<uint64_t, pointee_t>::value
4495 or std::is_same<double, pointee_t>::value
4496 ,
"incompatible pointer type");
4499 return get_impl_ptr(static_cast<PointerType>(
nullptr));
4506 template<
typename PointerType,
typename std::enable_if<
4507 std::is_pointer<PointerType>::value and
4508 std::is_const<typename std::remove_pointer<PointerType>::type>
::value,
int>
::type = 0>
4512 using pointee_t =
typename std::remove_const<
typename
4513 std::remove_pointer<
typename
4517 std::is_same<object_t, pointee_t>::value
4518 or std::is_same<array_t, pointee_t>::value
4519 or std::is_same<std::string, pointee_t>::value
4520 or std::is_same<bool, pointee_t>::value
4521 or std::is_same<int64_t, pointee_t>::value
4522 or std::is_same<uint64_t, pointee_t>::value
4523 or std::is_same<double, pointee_t>::value
4524 ,
"incompatible pointer type");
4527 return get_impl_ptr(static_cast<PointerType>(
nullptr));
4556 template<
typename ReferenceType,
typename std::enable_if<
4557 std::is_reference<ReferenceType>::value,
int>
::type = 0>
4561 return get_ref_impl<ReferenceType>(*
this);
4568 template<
typename ReferenceType,
typename std::enable_if<
4569 std::is_reference<ReferenceType>::value and
4570 std::is_const<typename std::remove_reference<ReferenceType>::type>
::value,
int>
::type = 0>
4574 return get_ref_impl<ReferenceType>(*
this);
4606 template <
typename ValueType,
typename std::enable_if <
4607 not std::is_pointer<ValueType>::value and
4608 not std::is_same<ValueType, detail::json_ref<json>>
::value and
4609 not std::is_same<ValueType, std::string::value_type>::value and
4611 #ifndef _MSC_VER // fix for issue #167 operator<< ambiguity under VS2015
4612 and not std::is_same<ValueType, std::initializer_list<std::string::value_type>>
::value
4614 and not std::is_same<ValueType, typename std::string_view>::value
4616 operator ValueType()
const
4619 return get<ValueType>();
4889 template<
typename T>
4903 return m_value.object->operator[](key);
4906 JSON_THROW(type_error::create(305,
"cannot use operator[] with " +
Twine(
type_name())));
4939 template<
typename T>
4945 assert(m_value.object->find(key) != m_value.object->end());
4946 return m_value.object->find(key)->second;
4949 JSON_THROW(type_error::create(305,
"cannot use operator[] with " +
Twine(
type_name())));
5000 template<
class ValueType,
typename std::enable_if<
5001 std::is_convertible<json_t, ValueType>::value,
int>
::type = 0>
5008 const auto it =
find(key);
5014 return default_value;
5017 JSON_THROW(type_error::create(306,
"cannot use value() with " +
Twine(
type_name())));
5026 return value(key, std::string(default_value));
5070 template<
class ValueType,
typename std::enable_if<
5071 std::is_convertible<json_t, ValueType>::value,
int>
::type = 0>
5080 return ptr.get_checked(
this);
5084 return default_value;
5088 JSON_THROW(type_error::create(306,
"cannot use value() with " +
Twine(
type_name())));
5097 return value(ptr, std::string(default_value));
5230 template<
class IteratorType,
typename std::enable_if<
5231 std::is_same<IteratorType, typename json_t::iterator>::value or
5232 std::is_same<IteratorType, typename json_t::const_iterator>::value,
int>
::type
5237 if (JSON_UNLIKELY(
this != pos.m_object))
5239 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value"));
5250 if (JSON_UNLIKELY(not pos.m_it.primitive_iterator.is_begin()))
5252 JSON_THROW(invalid_iterator::create(205,
"iterator out of range"));
5257 std::allocator<std::string> alloc;
5258 std::allocator_traits<decltype(alloc)>::destroy(alloc, m_value.string);
5259 std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_value.string, 1);
5260 m_value.string =
nullptr;
5263 m_type = value_t::null;
5270 m_value.object->erase(pos.m_it.object_iterator);
5276 m_value.array->erase(pos.m_it.array_iterator);
5281 JSON_THROW(type_error::create(307,
"cannot use erase() with " +
Twine(
type_name())));
5331 template<
class IteratorType,
typename std::enable_if<
5332 std::is_same<IteratorType, typename json_t::iterator>::value or
5333 std::is_same<IteratorType, typename json_t::const_iterator>::value,
int>
::type
5335 IteratorType
erase(IteratorType first, IteratorType last)
5338 if (JSON_UNLIKELY(
this != first.m_object or
this != last.m_object))
5340 JSON_THROW(invalid_iterator::create(203,
"iterators do not fit current value"));
5343 IteratorType result =
end();
5353 if (JSON_LIKELY(not first.m_it.primitive_iterator.is_begin()
5354 or not last.m_it.primitive_iterator.is_end()))
5356 JSON_THROW(invalid_iterator::create(204,
"iterators out of range"));
5361 std::allocator<std::string> alloc;
5362 std::allocator_traits<decltype(alloc)>::destroy(alloc, m_value.string);
5363 std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_value.string, 1);
5364 m_value.string =
nullptr;
5367 m_type = value_t::null;
5374 result.m_it.array_iterator = m_value.array->erase(first.m_it.array_iterator,
5375 last.m_it.array_iterator);
5380 JSON_THROW(type_error::create(307,
"cannot use erase() with " +
Twine(
type_name())));
5906 bool empty() const noexcept;
6040 void clear() noexcept;
6110 template<
typename T,
typename U>
6116 JSON_THROW(type_error::create(308,
"cannot use push_back() with " +
Twine(
type_name())));
6128 m_value.object->try_emplace(val.first, std::move(val.second));
6135 template<
typename T,
typename U>
6200 template<
class... Args>
6206 JSON_THROW(type_error::create(311,
"cannot use emplace_back() with " +
Twine(
type_name())));
6218 m_value.array->emplace_back(std::forward<Args>(args)...);
6248 template<
class... Args>
6254 JSON_THROW(type_error::create(311,
"cannot use emplace() with " +
Twine(
type_name())));
6266 auto res = m_value.object->try_emplace(key, std::forward<Args>(args)...);
6269 it.m_it.object_iterator = res.first;
6272 return {it, res.second};
6484 std::is_nothrow_move_constructible<value_t>::value and
6485 std::is_nothrow_move_assignable<value_t>::value and
6486 std::is_nothrow_move_constructible<json_value>::value and
6487 std::is_nothrow_move_assignable<json_value>::value
6490 std::swap(m_type, other.m_type);
6491 std::swap(m_value, other.m_value);
6520 std::swap(*(m_value.array), other);
6524 JSON_THROW(type_error::create(310,
"cannot use swap() with " +
Twine(
type_name())));
6553 std::swap(*(m_value.object), other);
6557 JSON_THROW(type_error::create(310,
"cannot use swap() with " +
Twine(
type_name())));
6586 std::swap(*(m_value.string), other);
6590 JSON_THROW(type_error::create(310,
"cannot use swap() with " +
Twine(
type_name())));
6649 template<
typename ScalarType,
typename std::enable_if<
6650 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6653 return (lhs ==
json(rhs));
6660 template<
typename ScalarType,
typename std::enable_if<
6661 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6664 return (
json(lhs) == rhs);
6687 return not (lhs == rhs);
6694 template<
typename ScalarType,
typename std::enable_if<
6695 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6698 return (lhs !=
json(rhs));
6705 template<
typename ScalarType,
typename std::enable_if<
6706 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6709 return (
json(lhs) != rhs);
6744 template<
typename ScalarType,
typename std::enable_if<
6745 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6748 return (lhs <
json(rhs));
6755 template<
typename ScalarType,
typename std::enable_if<
6756 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6759 return (
json(lhs) < rhs);
6783 return not (rhs < lhs);
6790 template<
typename ScalarType,
typename std::enable_if<
6791 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6794 return (lhs <=
json(rhs));
6801 template<
typename ScalarType,
typename std::enable_if<
6802 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6805 return (
json(lhs) <= rhs);
6829 return not (lhs <= rhs);
6836 template<
typename ScalarType,
typename std::enable_if<
6837 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6840 return (lhs >
json(rhs));
6847 template<
typename ScalarType,
typename std::enable_if<
6848 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6851 return (
json(lhs) > rhs);
6875 return not (lhs < rhs);
6882 template<
typename ScalarType,
typename std::enable_if<
6883 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6886 return (lhs >=
json(rhs));
6893 template<
typename ScalarType,
typename std::enable_if<
6894 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6897 return (
json(lhs) >= rhs);
7016 const bool allow_exceptions =
true);
7020 const bool allow_exceptions =
true);
7027 const bool allow_exceptions =
true);
7107 value_t m_type = value_t::null;
7110 json_value m_value = {};
7208 static std::vector<uint8_t>
to_cbor(
const json& j);
7209 static ArrayRef<uint8_t>
to_cbor(
const json& j, std::vector<uint8_t>& buf);
7210 static ArrayRef<uint8_t>
to_cbor(
const json& j, SmallVectorImpl<uint8_t>& buf);
7211 static void to_cbor(raw_ostream& os,
const json& j);
7294 static ArrayRef<uint8_t>
to_msgpack(
const json& j, std::vector<uint8_t>& buf);
7295 static ArrayRef<uint8_t>
to_msgpack(
const json& j, SmallVectorImpl<uint8_t>& buf);
7379 const bool use_size =
false,
7380 const bool use_type =
false);
7381 static ArrayRef<uint8_t>
to_ubjson(
const json& j, std::vector<uint8_t>& buf,
7382 const bool use_size =
false,
const bool use_type =
false);
7383 static ArrayRef<uint8_t>
to_ubjson(
const json& j, SmallVectorImpl<uint8_t>& buf,
7384 const bool use_size =
false,
const bool use_type =
false);
7386 const bool use_size =
false,
const bool use_type =
false);
7482 const bool strict =
true);
7487 static json from_cbor(ArrayRef<uint8_t> arr,
const bool strict =
true);
7563 const bool strict =
true);
7624 const bool strict =
true);
7626 static json from_ubjson(ArrayRef<uint8_t> arr,
const bool strict =
true);
7672 return ptr.get_unchecked(
this);
7700 return ptr.get_unchecked(
this);
7743 return ptr.get_checked(
this);
7786 return ptr.get_checked(
this);
7814 json_pointer::flatten(
"", *
this, result);
7850 return json_pointer::unflatten(*
this);
7945 const std::string& path =
"");
8017 inline void swap<wpi::json>(
wpi::json& j1,
8019 is_nothrow_move_constructible<wpi::json>::value and
8020 is_nothrow_move_assignable<wpi::json>::value
8038 const auto& h = hash<std::string>();
8075 inline wpi::json operator "" _json(
const char* s, std::size_t n)
8098 #ifndef WPI_JSON_IMPLEMENTATION
8101 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
8102 #pragma GCC diagnostic pop
8104 #if defined(__clang__)
8105 #pragma GCC diagnostic pop
8113 #undef JSON_UNLIKELY
8114 #undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
8115 #undef NLOHMANN_BASIC_JSON_TPL
8116 #undef NLOHMANN_JSON_HAS_HELPER
8118 #endif // WPI_JSON_IMPLEMENTATION