update specs for swap()#42
Conversation
Please, do not just apply this change. I just want to discuss this, as I am not sure myself what your goals are. When you only hide this overload of `std::swap` in cases where `T` is not swappable the effect will be that the generic version of `std::swap` will become a viable candidate, and this generic `swap` does not require the `T` to be swappable. So instead, maybe you just want a hard error? If so, you can apply this commit. The note is taken from the specification of `swap` for `std::array`: http://eel.is/c++draft/array#members-5 The constraints for the member `swap` can be left as they are: there is no interaction with other overloads.
|
cc @CaseyCarter |
CaseyCarter
left a comment
There was a problem hiding this comment.
When you only hide this overload of
std::swapin cases whereTis not swappable the effect will be that the generic version ofstd::swapwill become a viable candidate, and this generic swap does not require theTto be swappable.
The default implementation of std::swap is viable only if static_vector<T, N> is both move constructible and move assignable, which presumably will only be the case when T is both move constructible and move assignable. I can't be bothered to care about move constructible, move assignable, yet non-swappable types which I've only ever observed in the libc++ test suite. (std::ranges::swap, for example, never sees deleted swap overloads found via ADL. If your type is move constructible and move assignable, it's going to get swapped.)
Please, do not just apply this change. I just want to discuss this, as I am not sure myself what your goals are.
When you only hide this overload of
std::swapin cases whereTis not swappable the effect will be that the generic version ofstd::swapwill become a viable candidate, and this genericswapdoes not require theTto be swappable. So instead, maybe you just want a hard error? If so, you can apply this commit. The note is taken from the specification ofswapforstd::array: http://eel.is/c++draft/array#members-5The constraints for the member
swapcan be left as they are: there is no interaction with other overloads.