Someone on the cpplang Slack asks: How can I view a std::pair<T, T> as if it were a range of two Ts? That is, fill in the blank in this sample program: template<std::ranges::range R> void increment_all(R&& rg) { for (auto&& elt : rg) { elt = elt + 1; } } template<class T> auto F(std::pair<T, T>& kv) { ~~~~ } int main() { std::pair<int, int> kv = {1, 2}; increment_all(F(kv)); assert(kv.first == 2 && kv.second == 3); std::ranges::fill(F(kv), 4); assert(kv.first == 4 && kv.second == 4); }| Arthur O’Dwyer
In C++, there’s often multiple ways to refer to the same entity: aliases, inherited names, injected names, names that differ in qualification… Usually, if an entity has multiple names, which one you use won’t matter: you can use any of those synonymous names and the compiler won’t care. But each entity always has a uniquely “truest” name, privileged above all the other ways to refer to it. In some situations, in order to do a thing with an entity, you do actually need to call it b...| Arthur O’Dwyer