Gavin Doughtie on 15 Aug 2003 18:22: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;
}

I get the following turgid compile error: (gcc 3.2.2)

transform_test.cc:26: no match for `const 
   boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::bitwise_action<boost::lambda::leftshift_action>,
   boost::tuples::tuple<std::basic_ostream<char, std::char_traits<char> >&, 
   boost::lambda::lambda_functor<boost::lambda::placeholder<1> >, 
   boost::tuples::null_type, boost::tuples::null_type, 
   boost::tuples::null_type, boost::tuples::null_type, 
   boost::tuples::null_type, boost::tuples::null_type, 
   boost::tuples::null_type, boost::tuples::null_type> > > << <unknown type>' 
   operator
transform_test.cc:25: candidates are: std::ostream& operator<<(std::ostream&, 
   const std::vector<std::string, std::allocator<std::string> >&)

Why doesn't it understand "ends" ? (endl doesn't work either)

Gavin


On Fri, Aug 15, 2003 at 10:53:39AM -0700, Jon Stewart wrote:
> So I found the SGI docs online:
> 
> http://www.sgi.com/tech/stl/ostream_iterator.html
> 
> This is what you want Gavin, if, y'know, boost::lambda doesn't work out...
> 
> 
> ostream& operator<<(ostream& str, const vector<string>& rhs)
> {
> 	copy(rhs.begin(), rhs.end(),
> 		ostream_iterator<string>(rhs, "\n"));
> 	return str;
> }
> 
> It definitely pays to browse through Josuttis. for_each and boost::bind 
> are powerful, but they can be a kind of crutch, too.
> 
> 
> 
> 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
_______________________________________________
alacpp mailing list
alacpp@xxxxxxxxxxx
http://lists.ellipsis.cx/mailman/listinfo/alacpp