* Noah Roberts -ma740988, about algorithmic complexity:
>
You are not using std::swap() you are using std::vector::swap. There
is a significant difference.
Uh, no, except possibly for notation and clarity.
Consider this overload of std::swap, from the MSVC 7.1 standard library
implementation:
template<class _Ty, class _Allocinline
void swap(vector<_Ty, _Alloc>& _Left, vector<_Ty, _Alloc>& _Right)
{ // swap _Left and _Right vectors
_Left.swap(_Right);
}
This is not a partial specialization of a function template (which for
some unfathomable reason isn't allowed[1]), it's an overload, and its
existence is specified or at least implied by the general library
container requirements listed in §23.1/5.
The only catch is that swap only /should/ have constant time complexity
for a standard container, but whether it actually has is up to the
implementor.
In practice, though, a C++ implementation where swap didn't have
constant time complexity for standard containers, would be one not used.
Cheers,
- Alf
Notes:
[1] An article in DDJ, whose author may well be the author of the code
snippet above, stated that this is a partial specialization; it's not.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?