[Bug libstdc++/78231] Should std::sort use unqualifed iter_swap?
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78231 --- Comment #8 from Jonathan Wakely --- Also 17.6.5.4 [global.functions] p4.
[Bug libstdc++/78231] Should std::sort use unqualifed iter_swap?
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78231 --- Comment #7 from Jonathan Wakely --- (In reply to Eric Niebler from comment #6) > Jonathan, the wording for std::reverse mentions iter_swap and doesn't seem > to say whether it is called qualified or unqualified. 17.6.1.1 [contents] means it calls it qualified as ::std::iter_swap, unless otherwise specified. AFAICS it isn't otherwise specified. > AFAIK, it is the only > algorithm that is required to use iter_swap. It seems to be a hold-over from > a time before time. The requires clause says that *value must be swappable, Which does mean an unqualified call to swap happens, as per 17.6.3.2 [swappable.requirements]. > but it doesn't *exactly* say that the call to iter_swap must resolve to the > version in namespace std that does swap(*a,*b). Please forgive me if I'm > misreading the standard. The standard library always assumes qualified calls to avoid ADL, unless otherwise specified (as done for swap in [swappable.requirements]).
[Bug libstdc++/78231] Should std::sort use unqualifed iter_swap?
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78231 Eric Niebler changed: What|Removed |Added CC||eric.niebler at gmail dot com --- Comment #6 from Eric Niebler --- Jonathan, the wording for std::reverse mentions iter_swap and doesn't seem to say whether it is called qualified or unqualified. AFAIK, it is the only algorithm that is required to use iter_swap. It seems to be a hold-over from a time before time. The requires clause says that *value must be swappable, but it doesn't *exactly* say that the call to iter_swap must resolve to the version in namespace std that does swap(*a,*b). Please forgive me if I'm misreading the standard.
[Bug libstdc++/78231] Should std::sort use unqualifed iter_swap?
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78231 --- Comment #5 from Jonathan Wakely --- The correct way to implement swap for your own type is to overload it in your type's namespace, and it will be found by ADL. http://stackoverflow.com/questions/11562/how-to-overload-stdswap http://stackoverflow.com/questions/6380862/how-to-provide-a-swap-function-for-my-class http://stackoverflow.com/questions/11635172/how-to-implement-swap That doesn't work for iter_swap, for the reasons stated above: calls to iter_swap do not use ADL. It is not valid to add overloads of std::iter_swap, you can't add overloads to namespace std. You can specialize it as long as the specialization depends on at least one program-defined type. Please follow up in a more appropriate forum. GCC's library is doing the right thing, so this is not a bug. "How do I do ...?" does not belong in GCC's bugzilla.
[Bug libstdc++/78231] Should std::sort use unqualifed iter_swap?
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78231 --- Comment #4 from Alfredo --- ok, thanks for the clarification. So algorithms on iterators that swap use `::std::iter_swap`? (I didn't know that.) That is step forward. Is then one allowed to overload/specialize `std::iter_swap`? Just like one does with `swap`?
[Bug libstdc++/78231] Should std::sort use unqualifed iter_swap?
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78231 --- Comment #3 from Jonathan Wakely --- See 17.6.3.2 [swappable.requirements]. ValueSwappable is defined in terms of swappable, which is defined in terms of swappable with, which is defined in terms of an unqualified call to swap. It has nothing to do with std::iter_swap. This is a special rule for "swap" that doesn't apply to other functions. 17.6.1.1 [contents] says all references to iter_swap in the Standard Library refer to ::std::iter_swap, i.e. any function specified to call iter_swap must call ::std::iter_swap not some other function found by ADL.
[Bug libstdc++/78231] Should std::sort use unqualifed iter_swap?
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78231 --- Comment #2 from Alfredo --- @Jonathan, Can you link to the part of the line in the standard? I found that standard to be very vague, for example in defining ValueSwappable. Is ValueSwappable something that can be called with `std::iter_swap`, or just `iter_swap` or is only defined through `(std::)swap`? (plus the semantics). Also, When you said "customization point" I searched for it, and I found this http://ericniebler.com/2014/10/21/customization-point-design-in-c11-and-beyond/ It seems that I am not the first to point this out, and also seems that Eric has the same opinion "... iter_swap may also be a customization point. (I think it is, or that it should be.) ..."
[Bug libstdc++/78231] Should std::sort use unqualifed iter_swap?
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78231 Jonathan Wakely changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #1 from Jonathan Wakely --- No, iter_swap is not a customization point. The standard seems clear to me.