ericniebler / range-v3

Range library for C++14/17/20, basis for C++20's std::ranges
Other
4.06k stars 437 forks source link

Fixing ranges::to<std::map>(v) #1700

Closed brevzin closed 2 years ago

brevzin commented 2 years ago

The current overload set is inconsistent:

std::vector<std::pair<int, int>> v = {{1, 2}, {3, 4}};

auto m1 = ranges::to<std::map<int, int>>(v); // ok
auto m2 = v | ranges::to<std::map<int, int>>(); // ok
auto m3 = ranges::to<std::map>(v); // compile error
auto m4 = v | ranges::to<std::map>(); // ok

m3 fails because the logic here tries to instantiate std::map<std::pair<int, int>> (specifically, Cont<range_value_t<Rng>>) instead of actually using the existing deduction machinery (which is what the m4 overload correctly uses).

ericniebler commented 2 years ago

Thanks @brevzin. Can you look into the test regressions?

brevzin commented 2 years ago

Thanks @brevzin. Can you look into the test regressions?

Yeah, looks like this was cause of some implementations not having the std::map deduction guide (that we technically have a feature test macro for, that nobody actually defines, oh well). You worked around this one clever way with test_zip_to_map, I just muscled through making a std::map-equivalent. This should work 🤞.

brevzin commented 2 years ago

Okay now everything passes, except the windows ones where it just looks like the CI setup is broken.