Skip to content

Commit bfd9fd9

Browse files
author
Peter Spiess-Knafl
committed
Update Catch to 2.13.2 and nlohmann_json to 3.9.1
1 parent 459a22a commit bfd9fd9

30 files changed

+16347
-10149
lines changed

vendor/catch/catch.hpp

Lines changed: 12472 additions & 8342 deletions
Large diffs are not rendered by default.

vendor/nlohmann/LICENSE.MIT

Lines changed: 0 additions & 21 deletions
This file was deleted.

vendor/nlohmann/adl_serializer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct adl_serializer
3737
@param[in,out] j JSON value to write to
3838
@param[in] val value to read from
3939
*/
40-
template <typename BasicJsonType, typename ValueType>
40+
template<typename BasicJsonType, typename ValueType>
4141
static auto to_json(BasicJsonType& j, ValueType&& val) noexcept(
4242
noexcept(::nlohmann::to_json(j, std::forward<ValueType>(val))))
4343
-> decltype(::nlohmann::to_json(j, std::forward<ValueType>(val)), void())

vendor/nlohmann/detail/conversions/from_json.hpp

Lines changed: 85 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include <algorithm> // transform
44
#include <array> // array
5-
#include <ciso646> // and, not
65
#include <forward_list> // forward_list
76
#include <iterator> // inserter, front_inserter, end
87
#include <map> // map
@@ -26,18 +25,18 @@ namespace detail
2625
template<typename BasicJsonType>
2726
void from_json(const BasicJsonType& j, typename std::nullptr_t& n)
2827
{
29-
if (JSON_UNLIKELY(not j.is_null()))
28+
if (JSON_HEDLEY_UNLIKELY(!j.is_null()))
3029
{
3130
JSON_THROW(type_error::create(302, "type must be null, but is " + std::string(j.type_name())));
3231
}
3332
n = nullptr;
3433
}
3534

3635
// overloads for basic_json template parameters
37-
template<typename BasicJsonType, typename ArithmeticType,
38-
enable_if_t<std::is_arithmetic<ArithmeticType>::value and
39-
not std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
40-
int> = 0>
36+
template < typename BasicJsonType, typename ArithmeticType,
37+
enable_if_t < std::is_arithmetic<ArithmeticType>::value&&
38+
!std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
39+
int > = 0 >
4140
void get_arithmetic_value(const BasicJsonType& j, ArithmeticType& val)
4241
{
4342
switch (static_cast<value_t>(j))
@@ -66,7 +65,7 @@ void get_arithmetic_value(const BasicJsonType& j, ArithmeticType& val)
6665
template<typename BasicJsonType>
6766
void from_json(const BasicJsonType& j, typename BasicJsonType::boolean_t& b)
6867
{
69-
if (JSON_UNLIKELY(not j.is_boolean()))
68+
if (JSON_HEDLEY_UNLIKELY(!j.is_boolean()))
7069
{
7170
JSON_THROW(type_error::create(302, "type must be boolean, but is " + std::string(j.type_name())));
7271
}
@@ -76,7 +75,7 @@ void from_json(const BasicJsonType& j, typename BasicJsonType::boolean_t& b)
7675
template<typename BasicJsonType>
7776
void from_json(const BasicJsonType& j, typename BasicJsonType::string_t& s)
7877
{
79-
if (JSON_UNLIKELY(not j.is_string()))
78+
if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
8079
{
8180
JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name())));
8281
}
@@ -86,13 +85,13 @@ void from_json(const BasicJsonType& j, typename BasicJsonType::string_t& s)
8685
template <
8786
typename BasicJsonType, typename ConstructibleStringType,
8887
enable_if_t <
89-
is_constructible_string_type<BasicJsonType, ConstructibleStringType>::value and
90-
not std::is_same<typename BasicJsonType::string_t,
91-
ConstructibleStringType>::value,
88+
is_constructible_string_type<BasicJsonType, ConstructibleStringType>::value&&
89+
!std::is_same<typename BasicJsonType::string_t,
90+
ConstructibleStringType>::value,
9291
int > = 0 >
9392
void from_json(const BasicJsonType& j, ConstructibleStringType& s)
9493
{
95-
if (JSON_UNLIKELY(not j.is_string()))
94+
if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
9695
{
9796
JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name())));
9897
}
@@ -129,13 +128,14 @@ void from_json(const BasicJsonType& j, EnumType& e)
129128

130129
// forward_list doesn't have an insert method
131130
template<typename BasicJsonType, typename T, typename Allocator,
132-
enable_if_t<std::is_convertible<BasicJsonType, T>::value, int> = 0>
131+
enable_if_t<is_getable<BasicJsonType, T>::value, int> = 0>
133132
void from_json(const BasicJsonType& j, std::forward_list<T, Allocator>& l)
134133
{
135-
if (JSON_UNLIKELY(not j.is_array()))
134+
if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
136135
{
137136
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name())));
138137
}
138+
l.clear();
139139
std::transform(j.rbegin(), j.rend(),
140140
std::front_inserter(l), [](const BasicJsonType & i)
141141
{
@@ -145,15 +145,29 @@ void from_json(const BasicJsonType& j, std::forward_list<T, Allocator>& l)
145145

146146
// valarray doesn't have an insert method
147147
template<typename BasicJsonType, typename T,
148-
enable_if_t<std::is_convertible<BasicJsonType, T>::value, int> = 0>
148+
enable_if_t<is_getable<BasicJsonType, T>::value, int> = 0>
149149
void from_json(const BasicJsonType& j, std::valarray<T>& l)
150150
{
151-
if (JSON_UNLIKELY(not j.is_array()))
151+
if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
152152
{
153153
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name())));
154154
}
155155
l.resize(j.size());
156-
std::copy(j.m_value.array->begin(), j.m_value.array->end(), std::begin(l));
156+
std::transform(j.begin(), j.end(), std::begin(l),
157+
[](const BasicJsonType & elem)
158+
{
159+
return elem.template get<T>();
160+
});
161+
}
162+
163+
template<typename BasicJsonType, typename T, std::size_t N>
164+
auto from_json(const BasicJsonType& j, T (&arr)[N])
165+
-> decltype(j.template get<T>(), void())
166+
{
167+
for (std::size_t i = 0; i < N; ++i)
168+
{
169+
arr[i] = j.at(i).template get<T>();
170+
}
157171
}
158172

159173
template<typename BasicJsonType>
@@ -162,7 +176,7 @@ void from_json_array_impl(const BasicJsonType& j, typename BasicJsonType::array_
162176
arr = *j.template get_ptr<const typename BasicJsonType::array_t*>();
163177
}
164178

165-
template <typename BasicJsonType, typename T, std::size_t N>
179+
template<typename BasicJsonType, typename T, std::size_t N>
166180
auto from_json_array_impl(const BasicJsonType& j, std::array<T, N>& arr,
167181
priority_tag<2> /*unused*/)
168182
-> decltype(j.template get<T>(), void())
@@ -182,46 +196,50 @@ auto from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, p
182196
{
183197
using std::end;
184198

185-
arr.reserve(j.size());
199+
ConstructibleArrayType ret;
200+
ret.reserve(j.size());
186201
std::transform(j.begin(), j.end(),
187-
std::inserter(arr, end(arr)), [](const BasicJsonType & i)
202+
std::inserter(ret, end(ret)), [](const BasicJsonType & i)
188203
{
189204
// get<BasicJsonType>() returns *this, this won't call a from_json
190205
// method when value_type is BasicJsonType
191206
return i.template get<typename ConstructibleArrayType::value_type>();
192207
});
208+
arr = std::move(ret);
193209
}
194210

195-
template <typename BasicJsonType, typename ConstructibleArrayType>
211+
template<typename BasicJsonType, typename ConstructibleArrayType>
196212
void from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr,
197213
priority_tag<0> /*unused*/)
198214
{
199215
using std::end;
200216

217+
ConstructibleArrayType ret;
201218
std::transform(
202-
j.begin(), j.end(), std::inserter(arr, end(arr)),
219+
j.begin(), j.end(), std::inserter(ret, end(ret)),
203220
[](const BasicJsonType & i)
204221
{
205222
// get<BasicJsonType>() returns *this, this won't call a from_json
206223
// method when value_type is BasicJsonType
207224
return i.template get<typename ConstructibleArrayType::value_type>();
208225
});
226+
arr = std::move(ret);
209227
}
210228

211-
template <typename BasicJsonType, typename ConstructibleArrayType,
212-
enable_if_t <
213-
is_constructible_array_type<BasicJsonType, ConstructibleArrayType>::value and
214-
not is_constructible_object_type<BasicJsonType, ConstructibleArrayType>::value and
215-
not is_constructible_string_type<BasicJsonType, ConstructibleArrayType>::value and
216-
not is_basic_json<ConstructibleArrayType>::value,
217-
int > = 0 >
218-
229+
template < typename BasicJsonType, typename ConstructibleArrayType,
230+
enable_if_t <
231+
is_constructible_array_type<BasicJsonType, ConstructibleArrayType>::value&&
232+
!is_constructible_object_type<BasicJsonType, ConstructibleArrayType>::value&&
233+
!is_constructible_string_type<BasicJsonType, ConstructibleArrayType>::value&&
234+
!std::is_same<ConstructibleArrayType, typename BasicJsonType::binary_t>::value&&
235+
!is_basic_json<ConstructibleArrayType>::value,
236+
int > = 0 >
219237
auto from_json(const BasicJsonType& j, ConstructibleArrayType& arr)
220238
-> decltype(from_json_array_impl(j, arr, priority_tag<3> {}),
221239
j.template get<typename ConstructibleArrayType::value_type>(),
222240
void())
223241
{
224-
if (JSON_UNLIKELY(not j.is_array()))
242+
if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
225243
{
226244
JSON_THROW(type_error::create(302, "type must be array, but is " +
227245
std::string(j.type_name())));
@@ -230,38 +248,51 @@ void())
230248
from_json_array_impl(j, arr, priority_tag<3> {});
231249
}
232250

251+
template<typename BasicJsonType>
252+
void from_json(const BasicJsonType& j, typename BasicJsonType::binary_t& bin)
253+
{
254+
if (JSON_HEDLEY_UNLIKELY(!j.is_binary()))
255+
{
256+
JSON_THROW(type_error::create(302, "type must be binary, but is " + std::string(j.type_name())));
257+
}
258+
259+
bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>();
260+
}
261+
233262
template<typename BasicJsonType, typename ConstructibleObjectType,
234263
enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value, int> = 0>
235264
void from_json(const BasicJsonType& j, ConstructibleObjectType& obj)
236265
{
237-
if (JSON_UNLIKELY(not j.is_object()))
266+
if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
238267
{
239268
JSON_THROW(type_error::create(302, "type must be object, but is " + std::string(j.type_name())));
240269
}
241270

271+
ConstructibleObjectType ret;
242272
auto inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
243273
using value_type = typename ConstructibleObjectType::value_type;
244274
std::transform(
245275
inner_object->begin(), inner_object->end(),
246-
std::inserter(obj, obj.begin()),
276+
std::inserter(ret, ret.begin()),
247277
[](typename BasicJsonType::object_t::value_type const & p)
248278
{
249279
return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
250280
});
281+
obj = std::move(ret);
251282
}
252283

253284
// overload for arithmetic types, not chosen for basic_json template arguments
254285
// (BooleanType, etc..); note: Is it really necessary to provide explicit
255286
// overloads for boolean_t etc. in case of a custom BooleanType which is not
256287
// an arithmetic type?
257-
template<typename BasicJsonType, typename ArithmeticType,
258-
enable_if_t <
259-
std::is_arithmetic<ArithmeticType>::value and
260-
not std::is_same<ArithmeticType, typename BasicJsonType::number_unsigned_t>::value and
261-
not std::is_same<ArithmeticType, typename BasicJsonType::number_integer_t>::value and
262-
not std::is_same<ArithmeticType, typename BasicJsonType::number_float_t>::value and
263-
not std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
264-
int> = 0>
288+
template < typename BasicJsonType, typename ArithmeticType,
289+
enable_if_t <
290+
std::is_arithmetic<ArithmeticType>::value&&
291+
!std::is_same<ArithmeticType, typename BasicJsonType::number_unsigned_t>::value&&
292+
!std::is_same<ArithmeticType, typename BasicJsonType::number_integer_t>::value&&
293+
!std::is_same<ArithmeticType, typename BasicJsonType::number_float_t>::value&&
294+
!std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
295+
int > = 0 >
265296
void from_json(const BasicJsonType& j, ArithmeticType& val)
266297
{
267298
switch (static_cast<value_t>(j))
@@ -310,37 +341,39 @@ void from_json(const BasicJsonType& j, std::tuple<Args...>& t)
310341
from_json_tuple_impl(j, t, index_sequence_for<Args...> {});
311342
}
312343

313-
template <typename BasicJsonType, typename Key, typename Value, typename Compare, typename Allocator,
314-
typename = enable_if_t<not std::is_constructible<
315-
typename BasicJsonType::string_t, Key>::value>>
344+
template < typename BasicJsonType, typename Key, typename Value, typename Compare, typename Allocator,
345+
typename = enable_if_t < !std::is_constructible <
346+
typename BasicJsonType::string_t, Key >::value >>
316347
void from_json(const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>& m)
317348
{
318-
if (JSON_UNLIKELY(not j.is_array()))
349+
if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
319350
{
320351
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name())));
321352
}
353+
m.clear();
322354
for (const auto& p : j)
323355
{
324-
if (JSON_UNLIKELY(not p.is_array()))
356+
if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
325357
{
326358
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(p.type_name())));
327359
}
328360
m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
329361
}
330362
}
331363

332-
template <typename BasicJsonType, typename Key, typename Value, typename Hash, typename KeyEqual, typename Allocator,
333-
typename = enable_if_t<not std::is_constructible<
334-
typename BasicJsonType::string_t, Key>::value>>
364+
template < typename BasicJsonType, typename Key, typename Value, typename Hash, typename KeyEqual, typename Allocator,
365+
typename = enable_if_t < !std::is_constructible <
366+
typename BasicJsonType::string_t, Key >::value >>
335367
void from_json(const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>& m)
336368
{
337-
if (JSON_UNLIKELY(not j.is_array()))
369+
if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
338370
{
339371
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name())));
340372
}
373+
m.clear();
341374
for (const auto& p : j)
342375
{
343-
if (JSON_UNLIKELY(not p.is_array()))
376+
if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
344377
{
345378
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(p.type_name())));
346379
}
@@ -367,4 +400,4 @@ namespace
367400
{
368401
constexpr const auto& from_json = detail::static_const<detail::from_json_fn>::value;
369402
} // namespace
370-
} // namespace nlohmann
403+
} // namespace nlohmann

0 commit comments

Comments
 (0)