Jon Stewart on 15 Aug 2003 18:44:29 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [ALACPP] correction to ostream_iterator


> Cool!
> 
> Other random notes:
> 
> boost::lambda actually makes the following function compile. Astounding:
> 
> 
> ostream& operator << (ostream& str, const vector<string> & rhs)
> {
>     for_each(rhs.begin(), rhs.end(), str << _1 << "\n");
>     return str;
> }
> 
> 
> HOWEVER, if I change the function to this:
> 
> ostream& operator << (ostream& str, const vector<string> & rhs)
> {
>     for_each(rhs.begin(), rhs.end(), str << _1 << ends);
>     return str;
> }


Wow, I'm a moron today.

ends is NOT what you want. In addition to flushing, it outputs NULL.

As to why it won't compile, it's a template function and I bet that the 
lambda black magic delays type deduction, so ends can't figure out that 
it's supposed to be templated off of ostream.

But, yeah, you DON'T want std::ends. You're best off with "\n".

Sorry about that.



Jon
-- 
Jon Stewart                                 Advanced Los Angeles C++
stew1@xxxxxxxxxxx                           http://www.alacpp.org
_______________________________________________
alacpp mailing list
alacpp@xxxxxxxxxxx
http://lists.ellipsis.cx/mailman/listinfo/alacpp