-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Avoid _Iter_diff_t in parameters of std function templates
#4249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
`_Iter_diff_t<T>` is `typename iterator_traits<T>::difference_type` in C++17-and-earlier, and `iter_difference_t<T>` in C++20-and-later. We use it for the parameter types of a few function templates that are specified to take the former. This is (1) nicely shorter to spell than the long `iterator_traits` type, and (2) possibly a bit cheaper to compile if we can avoid instantiating `iterator_traits`. I convinced myself the difference probably wasn't observable and we made this change hoping to at least see if it would break anything. Four years later, we now know what will break: subsumption. If I pull e.g. `std::next` into a namespace with a `using` declaration and overload it with constrained function template taking the standard-specified parameters I'll get overload ambiguity on our implementation. The parameter mapping (the transformation from the template parameters to the function parameter types) differs in the two overloads so the constrained overload isn't clearly more specialized. This PR changes all function template parameters `_Iter_diff_t<meow>` to `typename iterator_traits<meow>::difference_type`. I still believe that the difference isn't observable in return types, so I've left them alone. There are also some non-local clang-format changes in `<xutility>` that I won't try to explain.
|
Me: "There's some weird formatting changes, dunno why clang-format wants them." |
|
This seems tempting to regress during maintenance without test coverage - it's the sort of "why are we saying verbose thing when we could use fewer words" that seems good to cleanup. So I'd like to see test coverage added for this. |
|
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
|
Thanks for making a difference! 😹 🚀 🎉 |
_Iter_diff_t<T>istypename iterator_traits<T>::difference_typein C++17-and-earlier, anditer_difference_t<T>in C++20-and-later. We use it for the parameter types of a few function templates that are specified to take the former. This is (1) nicely shorter to spell than the longiterator_traitstype, and (2) possibly a bit cheaper to compile if we can avoid instantiatingiterator_traits. I convinced myself the difference probably wasn't observable and we made this change hoping to at least see if it would break anything.Four years later, we now know what will break: subsumption. If I pull e.g.
std::nextinto a namespace with ausingdeclaration and overload it with constrained function template taking the standard-specified parameters I'll get overload ambiguity on our implementation. The parameter mapping (the transformation from the template parameters to the function parameter types) differs in the two overloads so the constrained overload isn't clearly more specialized.This PR changes all function template parameters
_Iter_diff_t<meow>totypename iterator_traits<meow>::difference_type. I still believe that the difference isn't observable in return types, so I've left them alone. I don't think we're likely to regress this, so I've added no test coverage. Shout - or you know, leave a review comment - if you disagree.Fixes DevCom-10532126 / VSO-1925201 / AB#1925201.