void traverse(const value& tree, const std::function<void (const path&, const value&)>& func, const path& base_path, bool leafs_only ) { if (!leafs_only || tree.empty() || (tree.kind() != kind::array && tree.kind() != kind::object)) func(base_path, tree); if (tree.kind() == kind::object) { for (const auto& field : tree.as_object()) { traverse(field.second, func, base_path + field.first, leafs_only ); } } else if (tree.kind() == kind::array) { for (value::size_type idx = 0; idx < tree.size(); ++idx) traverse(tree[idx], func, base_path + idx, leafs_only ); } }