0

I know that std::swap requires MoveAssignable (which iterswap does not) but why does it require something different than std::iterswap when they really are almost identical? I mean, I cannot see why they have different requirements - what makes up the need for this difference?

I have read this and this, however, they did not yield an answer to this question (at least not to me).

Jive Dadson
  • 16,680
  • 9
  • 52
  • 65
  • It might be helpful to remind people what those different requirements are... – Marc Glisse Dec 02 '17 at 23:10
  • std::swap is **the** standard swap function, while std::iter_swap may call either the standard swap or some user's overload, is that the part that's confusing you? There have been discussions of making std::swap call user's overload if it exists, but that's complicated and not necessarily that intuitive either. – Marc Glisse Dec 02 '17 at 23:14
  • *"The dereferenced values `*a` and `*b` must be "swappable", which implies that `swap(*a, *b)` must be valid,"* sounds pretty clear to me. – Baum mit Augen Dec 02 '17 at 23:40
  • @BaummitAugen can you then please elaborate? How does this explain why std::swap requires MoveAssignable and iterswap does not? –  Dec 02 '17 at 23:56
  • @step As I quoted, `iter_swap` requires "swappable". As you could have easily looked up, that means that `using std::swap; swap(*a, *b); ` must be valid, which either requires MoveAssignable indirectly if `std::swap` is chosen or whatever requirements the user-provided overload of `swap` imposes otherwise. – Baum mit Augen Dec 02 '17 at 23:59

0 Answers0