[lambda] Making my expression less complicated
Hello,
In my test program below, I have a container of columns and want to output the column headers into a string separated by a tab. The lambda expression is looking fairly complicated so I wonder if it could be made simpler or if there's any other algorithm I should've used to put a separator between the elements?
Regards,
Pete
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include
AMDG Peter Barker wrote:
Hello,
In my test program below, I have a container of columns and want to output the column headers into a string separated by a tab. The lambda expression is looking fairly complicated so I wonder if it could be made simpler or if there's any other algorithm I should've used to put a separator between the elements?
How about, std::size_t i = 0; //... ( if_(var(i)++) [ var(outputText) += constant(fieldSeparator) ], var(outputText) += bind(&Column::getColumnText,_1) ) In Christ, Steven Watanabe
--- On Fri, 5/9/08, Steven Watanabe
From: Steven Watanabe
Subject: Re: [Boost-users] [lambda] Making my expression less complicated To: boost-users@lists.boost.org Date: Friday, 5 September, 2008, 5:44 PM AMDG Peter Barker wrote:
Hello,
In my test program below, I have a container of
columns and want to output the column headers into a string separated by a tab. The lambda expression is looking fairly complicated so I wonder if it could be made simpler or if there's any other algorithm I should've used to put a separator between the elements? >
How about,
std::size_t i = 0;
//... ( if_(var(i)++) [ var(outputText) += constant(fieldSeparator) ], var(outputText) += bind(&Column::getColumnText,_1) )
That's much nicer and works very well, thanks :) By the way, do you know if there's something in Boost that works like std::ostream_iterator but does what I'm doing - putting the delimiter between the elements, not after each element? Some Googling tells me that there was an "Output Formatter" Boost library submitted with a range_streamer class to do it but the looks like that library was rejected. See http://lists.boost.org/Archives/boost/2004/09/71875.php Regards, Pete
participants (2)
-
Peter Barker
-
Steven Watanabe