I don't have a good C++ book on hand and google pulls ups nothing useful.
How does this work? Conceptually what is going on here? Technically, is the prototype for operator<<() predefined, how did the writer of this know how to write it so that << is overloaded to output Container values?
Where can I go to look at the operator<<()
so that I can overload it?
Also for an input you need a start and an end "place" c.begin()
, c.end()
...but for output you need one "place" ostream_iterator
. This seems a bit asymmetrical.
template <typename Container>
std::ostream& operator<<(std::ostream& os, const Container& c)
{
std::copy(c.begin(), c.end(),
std::ostream_iterator<typename Container::value_type>(os, " "));
return os;
}