Boost logo

Boost :

From: Terje Slettebø (tslettebo_at_[hidden])
Date: 2003-02-04 01:09:20


>From: "Glenn G. Chappell" <ggchappell_at_[hidden]>

> Vladimir Prus wrote:
> > after having to output std::vector to stream again and again using
> > custom
> > solution, I started to wonder why we don't have a solution in boost.
> > Does it makes sense to include operators<< for vectors, sets, etc?
> ...
> > std::cout << "new path is " << v << "\n";
>
> The philosophy behind the STL would suggest accessing containers
> through their iterators. Something like
>
> std::cout << "new path is "
> << Foo(v.begin(), v.end())
> << "\n";
>
> would not be too bad (and it would be even better if it were called
> something besides "Foo"). This would be very general, while
> remaining quite readble, I think.
>
> Delimiters could be set using optional parameters, among other
> methods.
>
> std::cout << "new path is "
> << Foo(v.begin(), v.end(), "[", ",", "]")
> << "\n";

You then still have the issue of what to do with the element types. For
example:

std::vector<std::pair<char,int> > v;

std::cout << Foo(v.begin(),v.end(),"[",",","]") << '\n';

How to print each element, and what if you want different delimiters for the
elements?

Regards,

Terje


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk