in nest/nest/nest.h [217:261]
return std::visit(
overloaded{
[&f](const T1 &t1, const T2 &t2) { return Nest<S>(f(t1, t2)); },
[&f](const 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()));
}
std::vector<Nest<S>> result;
result.reserve(size);
auto it1 = v1.begin();
auto it2 = v2.begin();
for (; it1 != v1.end(); ++it1, ++it2) {
result.emplace_back(map2(f, *it1, *it2));
}
return Nest<S>(result);
},
[&f](const 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()));
}
std::map<std::string, Nest<S>> result;
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 + "'");
}
result.emplace_hint(result.end(), (*it1).first,
map2(f, (*it1).second, (*it2).second));
}
return Nest<S>(result);
},
[](auto &&arg1, auto &&arg2) -> Nest<S> {
throw std::invalid_argument("nests don't match");
}},