Gmane
From: Eric Niebler <eric <at> boost-consulting.com>
Subject: segmented fusion - a-ha!
Newsgroups: gmane.comp.parsers.spirit.devel
Date: 2006-05-05 16:43:14 GMT (2 years, 30 weeks, 2 days, 22 hours and 42 minutes ago)

I just had an a-ha! moment. Segmentation in Fusion is *so* much simpler 
than I was making it. Fusion doesn't need segmented iterators, it needs 
segmented sequences! Fusion's algorithms don't take iterators like the 
std algorithms do -- they take sequences. I was trying to shoe-horn Matt 
Austern's formulation into Fusion, but that's the wrong approach.

Consider the joint_view. It should advertise itself as a segmented view. 
Then, the only thing it needs to provide is a way to step through the 
internal segments -- which are Fusion sequences that may or may not be 
segmented. What you get, essentially, is:

void for_each( join_view<First, Second> view, F f )
{
     for_each( view.first, f );
     for_each( view.second, f );
}

or, implemented generically, more like:

// for_each for segmented sequences ...
void for_each( SegmentedSequence & seq, f )
{
     detail::segmented_for_each(
         fusion::begin(seq)
       , fusion::end(seq)
       , f, mpl::false_());
}

where detail::segmented_for_each looks like:

void segmented_for_each(
     SBegin const &sbegin
   , SEnd const &send
   , F f, mpl::false_)
{
     fusion::for_each(
         fusion::deref(sbegin)
       , f);

     fusion::segmented_for_each(
         fusion::next(seq)
       , send
       , f, result_of::equal_to<
               typename result_of::next<SBegin>::type
             , SEnd>());
}

No new Fusion primimtives are need! And we can get better perf by doing 
loop unrolling in segmented_for_each.

Much simpler.

-- 
Eric Niebler
Boost Consulting
www.boost-consulting.com

-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642