[RFA] Removing const from std::swap

Gabriel Dos Reis gdr@integrable-solutions.net
Thu May 19 16:10:00 GMT 2005


Paolo Carlini <pcarlini@suse.de> writes:

| Hi everyone,
| 
| some time ago, in an overzealous (it seems ;) series of const- tweaks to
| the algorithms, I touched std::swap too, adding a const to the temporary
| __tmp:
| 
|   template<typename _Tp>
|     inline void
|     swap(_Tp& __a, _Tp& __b)
|     {
|       // concept requirements
|       __glibcxx_function_requires(_SGIAssignableConcept<_Tp>)
| 
|       const _Tp __tmp = __a;
|       __a = __b;
|       __b = __tmp;
|     }
| 
| This is strictly speaking absolutely legal, as the concept check also
| demonstrates, but now people on the c++.moderated list, Howard Hinnant
| for example, believe that this is "overly pedantic" ;) ... Shall I
| remove it? 

I'll look at it differently: Does the const buy us anything?  If not,
it should be removed.

| If we keep it, auto_ptrs cannot be swapped, as an extension,
| indeed...

I do not follow here.

-- Gaby



More information about the Libstdc++ mailing list