Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why was the swap operator proposal shot down?

Proposal

I read this a while ago and it sounds like an incredible idea. But, obviously, it hasn't made it into C++14, and it doesn't even seem to be coming to C++17. What's the reasoning?

like image 381
Brian Rodriguez Avatar asked Jan 02 '15 21:01

Brian Rodriguez


1 Answers

For background, the paper you've linked to proposes adding operator:=: to the language to accomplish what the following does today

using std::swap;
swap(a, b);

Instead you'd write,

a :=: b;

This is tracked by EWG issue 54 and was rejected as not a defect because the technique of using unqualified calls to swap will persist despite the new operator because without it, all user defined swap functions will be rendered useless. Moreover, adding the operator does not remove the need for having to rely on ADL to find the type specific swap implementation, if one exists.

Quoting Bjarne from the link above:

But swap() isn't going away because of backward compatibility, so now we'll have swap() and operator:=:. "Probably a good idea if we had a time machine". Introducing a new operator, it has to be really central and helpful. If it got us out of our swap problem it might be good enough, but it isn't. Libraries aren't going to stop calling swap and if they did then all the specialized swap functions people have written wouldn't get invoked. Problems are real, but the benefits it would have (i.e. what problem it would actually solve) aren't sufficiently explained. Too likely that swap and :=: would coexist indefinitely and that all the problems of swap would persist.

General agreement that this is a real problem but that it's not clear why this would solve them. We will not proceed with this.

No recommendation to move forward, considered NAD.

like image 193
Praetorian Avatar answered Oct 22 '22 17:10

Praetorian