i wrote a template(like below) but it fails to compile
template class iterable>
Json::Value iterable2json(const itera
The problem is that compiler can't deduce the type t
as it is indirectly determined through the template template parameter. However, there is actually no need to do anything like that in the first place! The following works just fine:
template <typename Iterable>
Json::Value iterable2json(Iterable const& cont) {
Json::Value v;
for (auto&& element: cont) {
v.append(element);
}
return v;
}
(well, since I don't have the Json
library you are using I havn't tried to compile it but I'd think it should be fine).