Commit a9d5ae4f authored by Théo DELRIEU's avatar Théo DELRIEU

put back a specialization for containers with a reserve method

parent e247e01a
...@@ -642,6 +642,41 @@ void from_json(Json const&j, std::forward_list<T, Allocator>& l) ...@@ -642,6 +642,41 @@ void from_json(Json const&j, std::forward_list<T, Allocator>& l)
l.push_front(it->template get<T>()); l.push_front(it->template get<T>());
} }
template <typename Json, typename CompatibleArrayType>
void from_json_array_impl(Json const &j, CompatibleArrayType &arr, long)
{
using std::begin;
using std::end;
std::transform(
j.begin(), j.end(), std::inserter(arr, end(arr)), [](Json const &i)
{
// get<Json>() returns *this, this won't call a from_json method when
// value_type is Json
return i.template get<typename CompatibleArrayType::value_type>();
});
}
template <typename Json, typename CompatibleArrayType>
auto from_json_array_impl(Json const &j, CompatibleArrayType &arr, int)
-> decltype(
arr.reserve(std::declval<typename CompatibleArrayType::size_type>()),
void())
{
using std::begin;
using std::end;
arr.reserve(j.size());
std::transform(
j.begin(), j.end(), std::inserter(arr, end(arr)), [](Json const &i)
{
// get<Json>() returns *this, this won't call a from_json method when
// value_type is Json
return i.template get<typename CompatibleArrayType::value_type>();
});
}
template < template <
typename Json, typename CompatibleArrayType, typename Json, typename CompatibleArrayType,
enable_if_t<is_compatible_array_type<Json, CompatibleArrayType>::value and enable_if_t<is_compatible_array_type<Json, CompatibleArrayType>::value and
...@@ -658,16 +693,7 @@ void from_json(Json const &j, CompatibleArrayType &arr) ...@@ -658,16 +693,7 @@ void from_json(Json const &j, CompatibleArrayType &arr)
if (!j.is_array()) if (!j.is_array())
throw std::domain_error("type must be array, but is " + type_name(j)); throw std::domain_error("type must be array, but is " + type_name(j));
} }
from_json_array_impl(j, arr, 0);
using std::begin;
using std::end;
std::transform(
j.begin(), j.end(), std::inserter(arr, end(arr)), [](Json const &i)
{
// get<Json>() returns *this, this won't call a from_json method when
// value_type is Json
return i.template get<typename CompatibleArrayType::value_type>();
});
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment