 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Eric B Guest
|
Posted: Wed Dec 21, 2005 5:13 pm Post subject: swap question |
|
|
In Effective C++ 3rd ed. Item 25, it says not to specialize std::swap
if you have a class template but there is a reason for doing it for
classes (but never describes the reason). Could someone clarify why
there is a difference, and what the correct course of action is?
Eric Beyeler
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Chris Uzdavinis Guest
|
Posted: Fri Dec 23, 2005 3:25 am Post subject: Re: swap question |
|
|
Eric B wrote:
| Quote: | In Effective C++ 3rd ed. Item 25, it says not to specialize std::swap
if you have a class template but there is a reason for doing it for
classes (but never describes the reason). Could someone clarify why
there is a difference, and what the correct course of action is?
|
For a class, you can specialize the existing std::swap function without
any problem.
For a class template, because C++ does not allow partial
specializations on function templates, in order for it to work you
would have to _overload_ the std::swap function with your own version.
Unfortunately, the standard only allows you to specialize existing
templates in the std namespace, not add new items. Providing such an
overload results in undefined behavior, but in practice it generally
works ok.)
I haven't followed this issue closely and am not aware if they (the
committee) are addressing it or not, but I would hope so. It makes it
very difficult to write your own STL compliant container that is on
equal terms with the standard containers.
--
Chris
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Carlos Moreno Guest
|
Posted: Fri Dec 23, 2005 6:41 pm Post subject: Re: swap question |
|
|
Chris Uzdavinis wrote:
| Quote: | [...]
I haven't followed this issue closely and am not aware if they (the
committee) are addressing it or not, but I would hope so. It makes it
very difficult to write your own STL compliant container that is on
equal terms with the standard containers.
|
Which is quite ironic, seeing how one of the "big points of sale"
of the STL is how it provides an *extensible* framework :-(
Carlos
--
PS: Long time no read, Chris! Glad to see you around here!
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|