10
10
#include < type_traits> // std::false_type, std::true_type, std::void_t, std::is_enum_v, std::underlying_type_t, std::is_same_v, std::is_base_of_v, std::remove_cvref_t
11
11
#include < utility> // std::pair
12
12
13
+ // Forward declarations (added as needed)
14
+ #ifndef DOXYGEN
15
+ namespace sourcemeta ::core {
16
+ template <typename L, typename R>
17
+ auto to_json (const std::pair<L, R> &value) -> JSON;
18
+ }
19
+ #endif
20
+
13
21
namespace sourcemeta ::core {
14
22
15
23
// / @ingroup json
@@ -107,13 +115,12 @@ auto to_json(const T &value) -> JSON {
107
115
template <typename T>
108
116
requires std::is_enum_v<T>
109
117
auto to_json (const T value) -> JSON {
110
- return to_json<std::underlying_type_t <T>>(
111
- static_cast <std::underlying_type_t <T>>(value));
118
+ return to_json (static_cast <std::underlying_type_t <T>>(value));
112
119
}
113
120
114
121
// / @ingroup json
115
122
template <typename T> auto to_json (const std::optional<T> &value) -> JSON {
116
- return value.has_value () ? to_json<T> (value.value ()) : JSON{nullptr };
123
+ return value.has_value () ? to_json (value.value ()) : JSON{nullptr };
117
124
}
118
125
119
126
// / @ingroup json
@@ -123,7 +130,7 @@ auto to_json(typename T::const_iterator begin, typename T::const_iterator end)
123
130
// TODO: Extend `make_array` to optionally take iterators, etc
124
131
auto result{JSON::make_array ()};
125
132
for (auto iterator = begin; iterator != end; ++iterator) {
126
- result.push_back (to_json< typename T::value_type> (*iterator));
133
+ result.push_back (to_json (*iterator));
127
134
}
128
135
129
136
return result;
@@ -164,8 +171,7 @@ auto to_json(typename T::const_iterator begin, typename T::const_iterator end)
164
171
-> JSON {
165
172
auto result{JSON::make_object ()};
166
173
for (auto iterator = begin; iterator != end; ++iterator) {
167
- result.assign (iterator->first ,
168
- to_json<typename T::mapped_type>(iterator->second ));
174
+ result.assign (iterator->first , to_json (iterator->second ));
169
175
}
170
176
171
177
return result;
0 commit comments