Boost logo

Boost Users :

Subject: Re: [Boost-users] Binding operator <<
From: Robert Jones (robertgbjones_at_[hidden])
Date: 2009-07-11 13:15:55


On Sat, Jul 11, 2009 at 1:01 PM, Archie14 <admin_at_[hidden]> wrote:

> Can't figure out the proper sintax for binding <<.
>
> class A
> {
> public:
> friend std::ostream& operator << (std::ostream& stream, A& a);
> };
>
> class B : boost::ptr_vector<A>
> {
> public:
> friend std::ostream& operator << (std::ostream& stream, B& b);
> }
>
> std::ostream& operator << (std::ostream& stream, B& b)
> {
> std::for_each(begin(),
> end(),
> boost::bind(&operator<<, ref(stream), ref(_1)); ???
> return stream;
> }
>

Is that code snippet real code? Or did you mean

std::ostream& operator << (std::ostream& stream, B& b)
{
 std::for_each(b.begin(),
               b.end(),
               boost::bind(&operator<<, ref(stream), ref(_1)); ???
 return stream;
}

Also, deriving from std containersis not a good move as they aren't dsigned
for it. I presume
the same is true for boost::ptr_vector.

- Rob.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net