Re: cout << vector<strin g>
On Nov 7, 12:17 pm, Pete Becker <p...@versatile coding.comwrote :
Formally true.
On practice it works just fine as long as One Definition Rule is not
violated.
--
Max
On Nov 7, 12:17 pm, Pete Becker <p...@versatile coding.comwrote :
On 2008-11-07 06:03:15 -0500, Maxim Yegorushkin
<maxim.yegorush ...@gmail.comsa id:
>
>
>
>
>
>
>
>
>
>
Which has undefined behavior. You can only add template specializations
to namespace std when they depend on user-defined types.
<maxim.yegorush ...@gmail.comsa id:
>
>
>
>
>
The example probably assumes there is an overloaded operator<<() for
std::ostream and std::vector<>, something like this:
std::ostream and std::vector<>, something like this:
#include <ostream>
#include <iterator>
#include <algorithm>
#include <iterator>
#include <algorithm>
namespace std {
template<class A1, class A2>
ostream& operator<<(ostr eam& s, vector<A1, A2const& vec)
{
copy(vec.begin( ), vec.end(), ostream_iterato r<A1>(s, "
"));
return s;
}
ostream& operator<<(ostr eam& s, vector<A1, A2const& vec)
{
copy(vec.begin( ), vec.end(), ostream_iterato r<A1>(s, "
"));
return s;
}
}
Which has undefined behavior. You can only add template specializations
to namespace std when they depend on user-defined types.
On practice it works just fine as long as One Definition Rule is not
violated.
--
Max
Comment