|
Boost Users : |
From: John C. Femiani (john.femiani_at_[hidden])
Date: 2008-07-20 20:47:17
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) :
"""
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<class Seq, class Op>
struct FusedConcept: inherit_linearly<typename transform<Seq,
Op>::type, inherit<_1, _2> >::type
{};
//in a test function, with some 'using' statements.
//This works
BOOST_CONCEPT_ASSERT((FusedConcept<mpl::vector<int, long>,
Integer<_1> >));
//This fails
BOOST_CONCEPT_ASSERT((FusedConcept< fusion::vector<int, long>,
Integer<_1> >));
//-----------------------------
> 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
that the mpl specializations must be added in some header I had not yet
included.
I knew already about adapted/mpl, and the documentation for that really
only showed how I could use mpl from fusion. Including 'adapted/mpl.hpp'
did not work.
I did a 'Find in files' for "namespace mpl{", and I found that you were
adding to the namespace from files in an 'mpl' directory directly under
fusion (i.e. not just under fusion/adapted). Then I noticed another
'mpl.hpp' file sitting right there and I realized what it must be for.
Once I added the line:
#include <boost/fusion/mpl.hpp>
to the header for FusedConcept, everything worked.
--John
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net