Fusion transform question
I started porting over some old codes that used hand-made MPL<->concrete
object code to Fusion.
I'm currently trying to have the following to work with no results so far :
struct make_arg
{
template<class Type> struct result
{
typedef typename boost::add_reference
AMDG Joel FALCOU wrote:
I started porting over some old codes that used hand-made MPL<->concrete object code to Fusion. I'm currently trying to have the following to work with no results so far :
Strange as it may seem, fusion::transform is not
the right tool in this case, mpl::transform is what you
want. fusion::transform is lazy. It returns a transform_view.
mpl::transform works because fusion sequences /are/ mpl
sequences. The default behavior of mpl::transform
is to preserve the input sequence type. i.e. transforming
an mpl::vector gives an mpl::vector, transforming an mpl::list
gives an mpl::list, and transforming a fusion::vector gives
a fusion::vector.
#include
Steven Watanabe a écrit :
Strange as it may seem, fusion::transform is not the right tool in this case, mpl::transform is what you want. fusion::transform is lazy. It returns a transform_view. mpl::transform works because fusion sequences /are/ mpl sequences. The default behavior of mpl::transform is to preserve the input sequence type. i.e. transforming an mpl::vector gives an mpl::vector, transforming an mpl::list gives an mpl::list, and transforming a fusion::vector gives a fusion::vector.
I just read the parts about the lazyness of fusion transformation. It indeed escpaed me for a few seconds. So basically the fusion transform are more suited for the runtime aprt of the code rather than the compile-time one ? -- Joel FALCOU Research Engineer @ Institut d'Electronique Fondamentale Université PARIS SUD XI France
AMDG Joel FALCOU wrote:
I just read the parts about the lazyness of fusion transformation. It indeed escpaed me for a few seconds. So basically the fusion transform are more suited for the runtime aprt of the code rather than the compile-time one ?
Right, fusion::transform is appropriate for mixed compile-time/run-time calculations. MPL is more appropriate for purely compile time constructs. In Christ, Steven Watanabe
2008/7/19 Steven Watanabe
AMDG
Joel FALCOU wrote:
I just read the parts about the lazyness of fusion transformation. It indeed escpaed me for a few seconds. So basically the fusion transform are more suited for the runtime aprt of the code rather than the compile-time one ?
Right, fusion::transform is appropriate for mixed compile-time/run-time calculations. MPL is more appropriate for purely compile time constructs.
Maybe this could be stated more clearly in the docs? The last part of fusion introduction section says: "For example, there are times when it is convenient to work solely on MPL using pure MPL sequences, then, convert them to Fusion sequences as a final step before actual instantiation of real runtime objects with data" This little line got stuck into my head, and at least in my experience using mpl algorithms&sequences is not only more convenient but also required most of the time, prior to instantiate any fusion sequence to do the runtime part. Adding something like: ! 'Choose MPL over fusion when doing pure type calculations. Once the static type calculation is finished, you can instantiate a fusion sequence (link to result_of::as_vector<S>') for the runtime part.' My 2 c.., / Christian Holmquist
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Christian Holmquist a écrit :
Adding something like: ! 'Choose MPL over fusion when doing pure type calculations. Once the static type calculation is finished, you can instantiate a fusion sequence (link to result_of::as_vector<S>') for the runtime part.'
This or a non-trivial exampel of MPL<->Fusion interaction that cover more than the MPl "adapted" page. -- Joel FALCOU Research Engineer @ Institut d'Electronique Fondamentale Université PARIS SUD XI France
Joel FALCOU wrote:
Christian Holmquist a écrit :
Adding something like: ! 'Choose MPL over fusion when doing pure type calculations. Once the static type calculation is finished, you can instantiate a fusion sequence (link to result_of::as_vector<S>') for the runtime part.'
This or a non-trivial exampel of MPL<->Fusion interaction that cover more than the MPl "adapted" page.
I think it is also confusing that fusion sequences are mpl sequences IF you include 'fusion/mpl.hpp', but not if you include 'fusion/adapted/mpl.hpp'. I would like to see that in the docs please (it took me some time to figure out). --John
John C. Femiani wrote:
Joel FALCOU wrote:
Christian Holmquist a écrit :
Adding something like: ! 'Choose MPL over fusion when doing pure type calculations. Once the static type calculation is finished, you can instantiate a fusion sequence (link to result_of::as_vector<S>') for the runtime part.'
This or a non-trivial exampel of MPL<->Fusion interaction that cover more than the MPl "adapted" page.
I think it is also confusing that fusion sequences are mpl sequences IF you include 'fusion/mpl.hpp', but not if you include 'fusion/adapted/mpl.hpp'. I would like to see that in the docs please (it took me some time to figure out).
Will do. Just out of curiosity, how did you figure it out? Which section in the docs did you look into first? Thanks! Regards, -- Joel de Guzman http://www.boostpro.com http://spirit.sf.net
Joel de Guzman wrote:
John C. Femiani wrote: <snip>
I think it is also confusing that fusion sequences are mpl sequences IF you include 'fusion/mpl.hpp', but not if you include 'fusion/adapted/mpl.hpp'. I would like to see that in the docs please (it took me some time to figure out).
Will do. Just out of curiosity, how did you figure it out? Which section in the docs did you look into first? Thanks! I'll answer in reverse order.
Which section in the docs did you look into first? First, I wanted the types in a fusion sequence as an mpl sequence. I googled, and found the introduction of the Fusion library, (which I had read before) :
Just out of curiosity, how did you figure it out? The concept assert failed because some MPL meta functions were missing. I realized that the fusion sequence could not be an mpl sequence, and
"""
Fusion provides full round compatibility with MPL. Fusion sequences are
fully conforming MPL sequences and MPL sequences are fully compatible
with Fusion. You can work with Fusion sequences on MPL if you wish to
work solely on types. In MPL, Fusion sequences follow MPL's
sequence-type preserving semantics (i.e. algorithms preserve the
original sequence type. e.g. transforming a vector returns a vector).
You can also convert from an MPL sequence to a Fusion sequence. For
example, there are times when it is convenient to work solely on MPL
using pure MPL sequences, then, convert them to Fusion sequences as a
final step before actual instantiation of real runtime objects with
data. You have the best of both worlds.
""""
which led me to think I could just plunk a fusion sequence in wherever
an MPL sequence already worked. I wanted to make sure every element in
the fusion sequence passed a concept check, so I did this:
//---------------------------
//in a header, in a detail namespace with some 'using mpl::' statements.
template
John C. Femiani wrote:
Joel de Guzman wrote:
John C. Femiani wrote: <snip>
I think it is also confusing that fusion sequences are mpl sequences IF you include 'fusion/mpl.hpp', but not if you include 'fusion/adapted/mpl.hpp'. I would like to see that in the docs please (it took me some time to figure out).
Will do. Just out of curiosity, how did you figure it out? Which section in the docs did you look into first? Thanks! I'll answer in reverse order.
Which section in the docs did you look into first? First, I wanted the types in a fusion sequence as an mpl sequence. I googled, and found the introduction of the Fusion library, (which I had read before) :
[snip long story]
to the header for FusedConcept, everything worked.
Ok, sorry for the troubles. I'll improve the docs to make this info easier to find. It is indeed lacking. Thanks for your support. Regards, -- Joel de Guzman http://www.boostpro.com http://spirit.sf.net
Joel de Guzman wrote:
John C. Femiani wrote:
Joel de Guzman wrote:
John C. Femiani wrote: <snip>
I think it is also confusing that fusion sequences are mpl sequences IF you include 'fusion/mpl.hpp', but not if you include 'fusion/adapted/mpl.hpp'. I would like to see that in the docs please (it took me some time to figure out).
Will do. Just out of curiosity, how did you figure it out? Which section in the docs did you look into first? Thanks! I'll answer in reverse order.
Which section in the docs did you look into first? First, I wanted the types in a fusion sequence as an mpl sequence. I googled, and found the introduction of the Fusion library, (which I had read before) :
[snip long story]
to the header for FusedConcept, everything worked.
Ok, sorry for the troubles. I'll improve the docs to make this info easier to find. It is indeed lacking. Thanks for your support.
Ok, done. I added this to the adapted docs:
[heading Header]
#include
Joel de Guzman wrote:
Ok, done. I added this to the adapted docs:
[heading Header]
#include
#include Fusion sequences may also be adapted as fully conforming __mpl__ sequences (see __intrinsics__). That way, we can have 2-way adaptation to and from __mpl__ and Fusion. To make Fusion sequences fully conforming __mpl__ sequences, include:
#include
If you want bi-directional adaptation to and from __mpl__ and Fusion, simply include:
#include
The header includes all the necessary headers. Great! Thanks, that definitely would have helped me out.
--John
Christian Holmquist wrote:
This little line got stuck into my head, and at least in my experience using mpl algorithms&sequences is not only more convenient but also required most of the time, prior to instantiate any fusion sequence to do the runtime part.
Adding something like: ! 'Choose MPL over fusion when doing pure type calculations. Once the static type calculation is finished, you can instantiate a fusion sequence (link to result_of::as_vector<S>') for the runtime part.'
Done. Added that to the docs as a footnote. Cheers, -- Joel de Guzman http://www.boostpro.com http://spirit.sf.net
participants (5)
-
Christian Holmquist
-
Joel de Guzman
-
Joel FALCOU
-
John C. Femiani
-
Steven Watanabe