[fusion] mpl::clear doesn't work on fusion views

Today I ran into a limitation in Fusion/MPL interoperability. I couldn't use an mpl algorithm on a Fusion sequence because mpl::clear wasn't defined on it. The sequence was a joint_view. I see that fusion::detail::clear is only defined for Fusion cons, map, set, vector and deque. Can we get it defined for all Fusion sequences? I think for everything else, an empty Fusion vector would do. That is all fusion::clear does, btw. (Aside: it seems strange to me that mpl::clear of a fusion::set gives an empty set, but that fusion::clear of an empty set gives an empty vector. This should probably be made consistent.) -- Eric Niebler BoostPro Computing http://www.boostpro.com

On Fri, Jul 29, 2011 at 12:52 PM, Eric Niebler <eric@boostpro.com> wrote:
Today I ran into a limitation in Fusion/MPL interoperability. I couldn't use an mpl algorithm on a Fusion sequence because mpl::clear wasn't defined on it. The sequence was a joint_view. I see that fusion::detail::clear is only defined for Fusion cons, map, set, vector and deque. Can we get it defined for all Fusion sequences? I think for everything else, an empty Fusion vector would do. That is all fusion::clear does, btw.
(Aside: it seems strange to me that mpl::clear of a fusion::set gives an empty set, but that fusion::clear of an empty set gives an empty vector. This should probably be made consistent.)
I'm confused. Why would fusion::detail::clear (which I presume is associated with fusion::clear) have anything to do with mpl::clear? Also, mpl::clear requires an MPL Extensible Sequence, which...I'm guessing fusion::joint_view doesn't satisfy...? So either make fusion::joint_view an MPL Extensible Sequence, or relax the requirements on mpl::clear...? I'm not sure either make sense, really. I guess there's some reason you don't want to or can't copy the types in the joint_view into an mpl::vector and operate on that instead? - Jeff

On 7/29/2011 1:36 PM, Jeffrey Lee Hellrung, Jr. wrote:
On Fri, Jul 29, 2011 at 12:52 PM, Eric Niebler <eric@boostpro.com> wrote:
Today I ran into a limitation in Fusion/MPL interoperability. I couldn't use an mpl algorithm on a Fusion sequence because mpl::clear wasn't defined on it. The sequence was a joint_view. I see that fusion::detail::clear is only defined for Fusion cons, map, set, vector and deque. Can we get it defined for all Fusion sequences? I think for everything else, an empty Fusion vector would do. That is all fusion::clear does, btw.
(Aside: it seems strange to me that mpl::clear of a fusion::set gives an empty set, but that fusion::clear of an empty set gives an empty vector. This should probably be made consistent.)
I'm confused. Why would fusion::detail::clear (which I presume is associated with fusion::clear) have anything to do with mpl::clear?
Because all Fusion sequences are also MPL sequences.
Also, mpl::clear requires an MPL Extensible Sequence, which...I'm guessing fusion::joint_view doesn't satisfy...? So either make fusion::joint_view an MPL Extensible Sequence, or relax the requirements on mpl::clear...? I'm not sure either make sense, really.
Ah. Certainly a fusion::joint_view is not extensible. But that's a weak rationale because it's not how Fusion operates. A push_back on a Fusion vector yields a joint_view, not a Fusion vector. Clearing any Fusion sequence could just yield an empty vector, like fusion::clear does (with the caveat stated above).
I guess there's some reason you don't want to or can't copy the types in the joint_view into an mpl::vector and operate on that instead?
Because I'm lazy. And because Fusion can do this. And it's a reasonable thing to expect. And the patch would be about 3 lines, which I'm happy to provide. -- Eric Niebler BoostPro Computing http://www.boostpro.com

On 7/30/2011 5:45 AM, Eric Niebler wrote:
On 7/29/2011 1:36 PM, Jeffrey Lee Hellrung, Jr. wrote:
On Fri, Jul 29, 2011 at 12:52 PM, Eric Niebler <eric@boostpro.com> wrote:
Today I ran into a limitation in Fusion/MPL interoperability. I couldn't use an mpl algorithm on a Fusion sequence because mpl::clear wasn't defined on it. The sequence was a joint_view. I see that fusion::detail::clear is only defined for Fusion cons, map, set, vector and deque. Can we get it defined for all Fusion sequences? I think for everything else, an empty Fusion vector would do. That is all fusion::clear does, btw.
(Aside: it seems strange to me that mpl::clear of a fusion::set gives an empty set, but that fusion::clear of an empty set gives an empty vector. This should probably be made consistent.)
I'm confused. Why would fusion::detail::clear (which I presume is associated with fusion::clear) have anything to do with mpl::clear?
Because all Fusion sequences are also MPL sequences.
Also, mpl::clear requires an MPL Extensible Sequence, which...I'm guessing fusion::joint_view doesn't satisfy...? So either make fusion::joint_view an MPL Extensible Sequence, or relax the requirements on mpl::clear...? I'm not sure either make sense, really.
Ah. Certainly a fusion::joint_view is not extensible. But that's a weak rationale because it's not how Fusion operates. A push_back on a Fusion vector yields a joint_view, not a Fusion vector. Clearing any Fusion sequence could just yield an empty vector, like fusion::clear does (with the caveat stated above).
I guess there's some reason you don't want to or can't copy the types in the joint_view into an mpl::vector and operate on that instead?
Because I'm lazy. And because Fusion can do this. And it's a reasonable thing to expect. And the patch would be about 3 lines, which I'm happy to provide.
The issue is that fusion has 2 levels, one is the MPL level, which involve mpl interoperability and is only about types. The other is the type/data level. fusion::clear is not the same as mpl::clear. The former is non sequence-type preserving (by design) while the latter is (always, also by design). In the MPL level, we have to do as MPL sequences do. E.g. you cannot clear an mpl::joint_view. Surely, MPL can do that as well (return an mpl::vector<>, but it doesn't, by design. Regards, -- Joel de Guzman http://www.boostpro.com http://boost-spirit.com

On 7/30/2011 3:52 AM, Eric Niebler wrote:
Today I ran into a limitation in Fusion/MPL interoperability. I couldn't use an mpl algorithm on a Fusion sequence because mpl::clear wasn't defined on it. The sequence was a joint_view. I see that fusion::detail::clear is only defined for Fusion cons, map, set, vector and deque. Can we get it defined for all Fusion sequences? I think for everything else, an empty Fusion vector would do. That is all fusion::clear does, btw.
One major difference between MPL and Fusion is that operations like these in MPL preserve the original sequence type. E.g. clearing an mpl::vector will give you an empty mpl::vector. That is why it is only defined for those containers you mentioned. Clearly, clearing a joint_view will not be a sequence-type preserving operation. In the same vein all MPL 'views' cannot be cleared. Try mpl::clear on an mpl view, for example.
(Aside: it seems strange to me that mpl::clear of a fusion::set gives an empty set, but that fusion::clear of an empty set gives an empty vector. This should probably be made consistent.)
OK. It's been a while since I've touched the code. Feel free to commit a patch. It looks like bug. Regards, -- Joel de Guzman http://www.boostpro.com http://boost-spirit.com
participants (3)
-
Eric Niebler
-
Jeffrey Lee Hellrung, Jr.
-
Joel de Guzman