Change Json map/vector conversions to invoke begin() directly (#110)

... instead of using key_type/value_type/mapped_type. Because this could
otherwise false-positive on things like std::optional, which has a value_type
member type, but is not a container.

Fixes #109.
This commit is contained in:
j4cbo 2017-06-20 16:48:22 -07:00 committed by Andrew Twyman
parent ed35a09c04
commit ec4e45219a

View File

@ -107,14 +107,14 @@ public:
// Implicit constructor: map-like objects (std::map, std::unordered_map, etc)
template <class M, typename std::enable_if<
std::is_constructible<std::string, typename M::key_type>::value
&& std::is_constructible<Json, typename M::mapped_type>::value,
std::is_constructible<std::string, decltype(std::declval<M>().begin()->first)>::value
&& std::is_constructible<Json, decltype(std::declval<M>().begin()->second)>::value,
int>::type = 0>
Json(const M & m) : Json(object(m.begin(), m.end())) {}
// Implicit constructor: vector-like objects (std::list, std::vector, std::set, etc)
template <class V, typename std::enable_if<
std::is_constructible<Json, typename V::value_type>::value,
std::is_constructible<Json, decltype(*std::declval<V>().begin())>::value,
int>::type = 0>
Json(const V & v) : Json(array(v.begin(), v.end())) {}