in nest/nest/nest.h [284:324]
static void for_each(Function f, Nest<T1> &nest1, const Nest<T2> &nest2) {
return std::visit(
overloaded{
[&f](T1 &t1, const T2 &t2) { f(t1, t2); },
[&f](std::vector<Nest<T1>> &v1, const std::vector<Nest<T2>> &v2) {
auto size = v1.size();
if (size != v2.size()) {
throw std::invalid_argument(
"Expected vectors of same length but got " +
std::to_string(size) + " vs " + std::to_string(v2.size()));
}
auto it1 = v1.begin();
auto it2 = v2.begin();
for (; it1 != v1.end(); ++it1, ++it2) {
for_each(f, *it1, *it2);
}
},
[&f](std::map<std::string, Nest<T1>> &m1,
const std::map<std::string, Nest<T2>> &m2) {
auto size = m1.size();
if (size != m2.size()) {
throw std::invalid_argument(
"Expected maps of same length but got " +
std::to_string(size) + " vs " + std::to_string(m2.size()));
}
auto it1 = m1.begin();
auto it2 = m2.begin();
for (; it1 != m1.end(); ++it1, ++it2) {
if ((*it1).first != (*it2).first) {
throw std::invalid_argument(
"Expected maps to have same keys but found '" +
(*it1).first + "' vs '" + (*it2).first + "'");
}
for_each(f, (*it1).second, (*it2).second);
}
},
[](auto &&arg1, auto &&arg2) {
throw std::invalid_argument("nests don't match");
}},
nest1.value, nest2.value);
}