[Solution] Re: [statechart] Template States, Compile Error
2006-03-01 00:02:30 GMT
Hi Dave The problem you stumbled upon is (or was(Continue reading)) well known. It was discussed during review and I even tried to find a workaround for it not too long ago. The solution is very simple and is even described in the reference manual under the requirements for the InnerInitial parameter: <quote> An mpl::list<> containing models of the SimpleState or State concepts or instantiations of the shallow_history or deep_history class templates. If there is only a single inner initial state _that_is_not_a_template_instantiation_ then it can also be passed directly, without wrapping it into an mpl::list<>. [...] </quote> (_Note_the_underlined_part_). So, the only thing you need to do is to wrap every templated InnerInitial parameter into an mpl::list and everything will work as expected (see attached example). The reason why compilers rightly choke on the code lies in the fact that simple_state internally checks whether the InnerInitial parameter already is an mpl::list. This check works perfectly even on forward-declared classes. However, as soon as InnerInitial is a class template instantiation, for some reason that template needs to be fully instantiated. The problem is described in more detail here: <http://article.gmane.org/gmane.comp.lib.boost.devel/128741> I guess it was simply a little too late yesterday, sorry... #include <boost/statechart/state_machine.hpp> #include <boost/statechart/simple_state.hpp> #include <boost/mpl/list.hpp>
) well known. It was
discussed during review and I even tried to find a workaround for it not
too long ago. The solution is very simple and is even described in the
reference manual under the requirements for the InnerInitial parameter:
<quote>
An mpl::list<> containing models of the SimpleState or State concepts or
instantiations of the shallow_history or deep_history class templates.
If there is only a single inner initial state
_that_is_not_a_template_instantiation_ then it can also be passed
directly, without wrapping it into an mpl::list<>. [...]
</quote>
(_Note_the_underlined_part_). So, the only thing you need to do is to
wrap every templated InnerInitial parameter into an mpl::list and
everything will work as expected (see attached example). The reason why
compilers rightly choke on the code lies in the fact that simple_state
internally checks whether the InnerInitial parameter already is an
mpl::list. This check works perfectly even on forward-declared classes.
However, as soon as InnerInitial is a class template instantiation, for
some reason that template needs to be fully instantiated. The problem is
described in more detail here:
<
RSS Feed