Skip to content
This repository was archived by the owner on Mar 26, 2020. It is now read-only.

Commit ec4e452

Browse files
j4cboartwyman
authored andcommitted
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.
1 parent ed35a09 commit ec4e452

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

json11.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ class Json final {
107107

108108
// Implicit constructor: map-like objects (std::map, std::unordered_map, etc)
109109
template <class M, typename std::enable_if<
110-
std::is_constructible<std::string, typename M::key_type>::value
111-
&& std::is_constructible<Json, typename M::mapped_type>::value,
110+
std::is_constructible<std::string, decltype(std::declval<M>().begin()->first)>::value
111+
&& std::is_constructible<Json, decltype(std::declval<M>().begin()->second)>::value,
112112
int>::type = 0>
113113
Json(const M & m) : Json(object(m.begin(), m.end())) {}
114114

115115
// Implicit constructor: vector-like objects (std::list, std::vector, std::set, etc)
116116
template <class V, typename std::enable_if<
117-
std::is_constructible<Json, typename V::value_type>::value,
117+
std::is_constructible<Json, decltype(*std::declval<V>().begin())>::value,
118118
int>::type = 0>
119119
Json(const V & v) : Json(array(v.begin(), v.end())) {}
120120

0 commit comments

Comments
 (0)