Skip to content

update specs for swap()#42

Open
akrzemi1 wants to merge 1 commit intognzlbg:masterfrom
akrzemi1:patch-2
Open

update specs for swap()#42
akrzemi1 wants to merge 1 commit intognzlbg:masterfrom
akrzemi1:patch-2

Conversation

@akrzemi1
Copy link
Copy Markdown

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.

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.
@gnzlbg
Copy link
Copy Markdown
Owner

gnzlbg commented Mar 25, 2019

cc @CaseyCarter

Copy link
Copy Markdown

@CaseyCarter CaseyCarter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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.)

Comment thread README.md
Comment thread README.md
Comment thread README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants