Boost logo

Boost Users :

Subject: Re: [Boost-users] [fusion] Compile Error using BOOST_FUSION_DEFINE_STRUCT_INLINE with VC10 and GCC 4.2.1
From: Oswin Krause (Oswin.Krause_at_[hidden])
Date: 2012-10-24 03:21:33


Hi,

thanks for the reply!

On 2012-10-24 04:45, Nathan Ridge wrote:
> For MSVC, this is caused by a bug that seems to be triggered when a
> triply
> nested template class (i.e. a nested template class inside a nested
> template class inside a template class) is partially specialized. I
> reported
> the bug to Microsoft [1], but haven't heard back from them.
So this bug is known. Could a warning be added to the documentation
until this is fixed? (if it is possible at all?). At last for the
compilers which are officially supported by boost.

> GCC 4.2 seems to be suffering from a similar bug. Your example code
> works
> with GCC 4.5 and higher, and fails to compile with GCC 4.4 and lower.
> There's
> not much to do in terms of reporting this bug, since 4.4 and earlier
> are no
> longer maintained.
Good to know. So either I workaround/disable the feature on my side on
VC or GCC<4.5 or we find a workaround. OK, let's try the latter first,
since i honestly don't know how to to workaround it on my side ;)

> If anyone can suggest a workaround for these compiler bugs, I am
> happy to
> implement them.
I have tried to understand what the macro generates and maybe we can
fix it by using fusion/mpl instead of partial template specialization. I
don't fully understand the macro, but maybe i am not too far off, so
that my solution might still work.

the need for partial template spcialization arised because basically
the type/member list (A1, a1)(A2,a2)... is translated into

typedef A1 t1_type;
typedef A2 t2_type;
...
t1_type& t1;//linked to a1
t2_type& t2;//linked to a2
...

or something very similar to it.

thus you need to specialize deref to do something roughly like( i
simplyfy here because i am too lazy to look up the original solution):

template<int>
struct deref{};
template<>
struct deref<1>{
     typedef t1_type& type;
     type call(Sequence& seq){
         return seq.t1;
     }
};
...

now think about the following:
typedef boost::fusion::vector<A1&,A2&,...AN&> t_seq;
t_seq t;//tied to a1...an
template<int N>
struct deref{
     typedef result_of::at_c<t_types,N> type;
     type call(Sequence& seq){
         return at_c<N>(seq.t);
     }
};

could this work? Of course this is detrimental to the compil times
since fusion::vector needs to be itnroduced and instantiated. However
this might just be the solution used for GCC<4.5 and MSVC, in this cas
"slow" is better than "compiler gives up".

Gretings,
Oswin


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