Здравствуйте, Draconus, Вы писали:
D>Здравствуйте, LaptevVV, Вы писали:
D>>>тогда write просто выбросит в поток содержимое класса vector вместо данных которые он содержал.
LVV>>Так надо ж по-другому перегрузить! В двукратном цикле.
LVV>>Или ты хочешь единственной перегрузкой обрабатывать все, что угодно????
D>в данном случае — не все что угодно, а любой вектор (в том числе и вектор векторов). А иначе какой смысл писать типизируемую операцию <<?
// для любых итераторов
template<class FwdIt>
void dump(ostream& ostr, const FwdIt& iter, const FwdIt& end)
{
std::copy(iter, end, ostream_iterator(ostr, ", "));
}
// для STL-контейнеров
template<class Cont>
void dump(ostream& ostr, const Cont& cont)
{
dump(ostr, cont.begin(), cont.end();
}
template<class E>
ostream& operator << (ostream& ostr, std::vector<E> const& cont)
{
dump(ostr, cont); return ostr;
}
template<class E>
ostream& operator << (ostream& ostr, std::list<E> const& cont)
{
dump(ostr, cont); return ostr;
}
template<class E>
ostream& operator << (ostream& ostr, std::set<E> const& cont)
{
dump(ostr, cont); return ostr;
}
template<class E>
ostream& operator << (ostream& ostr, std::deque<E> const& cont)
{
dump(ostr, cont); return ostr;
}
Ы?