[fusion] flatten/flatten_view Proposal
Hi there, I've created the ticket, doc&test included https://svn.boost.org/trac/boost/ticket/9294 'flatten' is an algorithm which returns a view that allows you to go through the leaf elems sequentially. For example: flatten(make_vector(1, make_vector(2, 3))) == make_vector(1, 2, 3) This is developed when I use Fusion to work with SQL for simple data mapping. In addition to 'flatten', 'support/ref' is also provided in this patch for working with mutable sequence, which I had talked with Joel sometime ago. BTW, I think the ticket below is OK to close (the patch seem applied): https://svn.boost.org/trac/boost/ticket/8270 Thanks,
On 10/23/2013 7:30 AM, TONGARI J wrote:
Hi there,
I've created the ticket, doc&test included https://svn.boost.org/trac/boost/ticket/9294
'flatten' is an algorithm which returns a view that allows you to go through the leaf elems sequentially.
For example:
flatten(make_vector(1, make_vector(2, 3))) == make_vector(1, 2, 3)
This is developed when I use Fusion to work with SQL for simple data mapping.
You have duplicated a *huge* amount of work already in Fusion for supporting segmented sequences. If your Fusion sequence is logically a sequence of sequences, you just have to implement extension::is_segmented_impl and extension::segments_impl to make your type a valid Fusion sequence that has "flat" Fusion iterators. extension::segments_impl just has to return a Fusion sequence of Fusion sequences. See libs/fusion/test/sequence/tree.hpp for an example. Sorry this isn't documented. That's my fault. I'm doubly sorry that you went to the trouble of implementing this. Adding support to Fusion for segmented sequences is one of the reasons why I have no hair today. ;-) -- Eric Niebler Boost.org http://www.boost.org
Hi Eric,
2013/10/24 Eric Niebler
On 10/23/2013 7:30 AM, TONGARI J wrote:
Hi there,
I've created the ticket, doc&test included https://svn.boost.org/trac/boost/ticket/9294
'flatten' is an algorithm which returns a view that allows you to go through the leaf elems sequentially.
For example:
flatten(make_vector(1, make_vector(2, 3))) == make_vector(1, 2, 3)
This is developed when I use Fusion to work with SQL for simple data mapping.
You have duplicated a *huge* amount of work already in Fusion for supporting segmented sequences. If your Fusion sequence is logically a sequence of sequences, you just have to implement extension::is_segmented_impl and extension::segments_impl to make your type a valid Fusion sequence that has "flat" Fusion iterators. extension::segments_impl just has to return a Fusion sequence of Fusion sequences. See libs/fusion/test/sequence/tree.hpp for an example.
Sorry this isn't documented. That's my fault. I'm doubly sorry that you went to the trouble of implementing this. Adding support to Fusion for segmented sequences is one of the reasons why I have no hair today. ;-)
I just tried to re-implement it by segments_impl, but seems to cause memory violation. Code is attached. Could you shed some light on this? (note: flatten_view should be writable if the underlying sequence is writable) Thanks,
On 10/23/2013 8:35 PM, TONGARI J wrote:
I just tried to re-implement it by segments_impl, but seems to cause memory violation.
Code is attached. Could you shed some light on this? (note: flatten_view should be writable if the underlying sequence is writable)
I'm afraid I really can't tell by looking at the code. -- Eric Niebler Boost.org http://www.boost.org
2013/10/24 Eric Niebler
On 10/23/2013 8:35 PM, TONGARI J wrote:
I just tried to re-implement it by segments_impl, but seems to cause
memory
violation.
Code is attached. Could you shed some light on this? (note: flatten_view should be writable if the underlying sequence is writable)
I'm afraid I really can't tell by looking at the code.
I still can't figure out what went wrong with the simple segmented one. If somebody can make it work, I'd like to compare both implementations. Joel?
On 10/25/2013 2:40 AM, TONGARI J wrote:
2013/10/24 Eric Niebler
On 10/23/2013 8:35 PM, TONGARI J wrote:
I just tried to re-implement it by segments_impl, but seems to cause
memory
violation.
Code is attached. Could you shed some light on this? (note: flatten_view should be writable if the underlying sequence is writable)
I'm afraid I really can't tell by looking at the code.
I still can't figure out what went wrong with the simple segmented one. If somebody can make it work, I'd like to compare both implementations.
Joel?
You haven't yet posted the code that reproduces the crash. -- Eric Niebler Boost.org http://www.boost.org
Hi Eric,
2013/10/26 Eric Niebler
On 10/25/2013 2:40 AM, TONGARI J wrote:
2013/10/24 Eric Niebler
On 10/23/2013 8:35 PM, TONGARI J wrote:
I just tried to re-implement it by segments_impl, but seems to cause
memory
violation.
Code is attached. Could you shed some light on this? (note: flatten_view should be writable if the underlying sequence is writable)
I'm afraid I really can't tell by looking at the code.
I still can't figure out what went wrong with the simple segmented one. If somebody can make it work, I'd like to compare both implementations.
Joel?
You haven't yet posted the code that reproduces the crash.
It's so simple to reproduce the crash. Sample code attached. If you debug with MSVC, you'll see access violation. With GCC you might get weird results and it probably crashes. Thanks,
On 10/23/2013 8:35 PM, TONGARI J wrote:
I just tried to re-implement it by segments_impl, but seems to cause memory violation.
Code is attached. Could you shed some light on this? (note: flatten_view should be writable if the underlying sequence is writable)
OK, I see what the problem is. It's a very general problem. When you have a "sequence" that is really generating other sequences on the fly, and you try to iterate over that, the temporary sequences go out of scope before the iteration succeeds. That is, begin() of a flatten_view internally stores a cons list of iterators to (temporary) sequences. By the time begin() returns, those sequences are gone, and the iterators are invalid. Hence the crash. I see in your code, you're also building a cons list of iterators, but those are iterators to real sequences, not temporaries. So your code doesn't exhibit the problem, at least not for your example. If you changed your example such that the sequence was a transform_view that generated other sequences on the fly, I'm pretty sure you'd hit the same problem. So, what's the answer? I haven't spent a lot of time thinking about it. My gut reaction is: don't do that. But flattening a tree by generating flattened views on the fly would be *really* useful. In fact, Proto needs this. But I don't know. -- Eric Niebler Boost.org http://www.boost.org
participants (2)
-
Eric Niebler
-
TONGARI J