|
|
@ -4,16 +4,24 @@ |
|
|
|
|
|
|
|
struct Identity{ |
|
|
|
template <typename T> |
|
|
|
T operator()(T t){ |
|
|
|
T operator()(T t) const { |
|
|
|
return t; |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
template <typename C, typename F = Identity> |
|
|
|
inline js::Value vector_to_json(C const & container, F f = Identity()){ |
|
|
|
struct All{ |
|
|
|
template <typename T> |
|
|
|
bool operator()(T const & t) const { |
|
|
|
return true; |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
template <typename C, typename F1 = Identity, typename F2 = All> |
|
|
|
inline js::Value vector_to_json(C const & container, F1 const & transform = Identity(), F2 const & filter = All()){ |
|
|
|
js::Array array; |
|
|
|
for(auto x : container){ |
|
|
|
array.push_back(to_json(f(x))); |
|
|
|
if(!filter(x)) continue; |
|
|
|
array.push_back(to_json(transform(x))); |
|
|
|
} |
|
|
|
return array; |
|
|
|
} |
|
|
|