Skip to content
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

Tests for self-move #2

Open
Morwenn opened this issue Apr 4, 2019 · 0 comments
Open

Tests for self-move #2

Morwenn opened this issue Apr 4, 2019 · 0 comments

Comments

@Morwenn
Copy link

Morwenn commented Apr 4, 2019

I recently had an issue understanding what is expected from types and standard library algorithms when it comes to self-move and self-swap and arrived at the following conclusion:

  • using std::swap; swap(x, x); is required to leave x unchanged as per the Swappable concept. Therefore standard algorithms are allowed to perform unguarded self-swaps.
  • The standard makes no guarantee concerning x = std::move(x) and from what I gathered around the internet some committee members expect it to leave x in a valid but unspecified state, so standard library algorithms have to avoid performing self-moves if they don't want to accidentally destroy elements (some algorithms expect non-overlapping input and output ranges, so they at least don't have to check for that).

Accordingly I wrote a type which detects self-moves and allows self-swap to try to detect such issues in one of my libraries. Looking at libwaful again, it might also be a suitable type for the library. Here is the current implementation if you're interested, but it currently uses exceptions instead of asserts to report errors, and has some overlap with some of libawful existing types (notably tracked). Nonetheless, I believe that the self-move/self-swap guarantees enforcement might be a valuable addition to the library :)

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

No branches or pull requests

1 participant