Boost logo

Boost Users :

From: Andreas Huber (ahd6974-spamgroupstrap_at_[hidden])
Date: 2006-02-28 19:02:30


Hi Dave

The problem you stumbled upon is (or was :-() 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>

namespace sc = boost::statechart;
namespace mpl = boost::mpl;

template< typename Type > struct NormalMode;
struct Switch : sc::state_machine< Switch, NormalMode< int > > {};

template< typename Type > struct Off;
template< typename Type >
struct NormalMode : sc::simple_state<
  // Note that Off< Type > is wrapped into an mpl::list
  NormalMode< Type >, Switch, mpl::list< Off< Type > > >
{
};

template< typename Type >
struct Off : sc::simple_state< Off< Type >, NormalMode< Type > >
{
};

int main()
{
  Switch machine;
  machine.initiate();
  return 0;
}

HTH,

-- 
Andreas Huber
When replying by private email, please remove the words spam and trap
from the address shown in the header.

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