Boost logo

Boost :

From: Andreas Huber (spam2002_at_[hidden])
Date: 2003-02-06 17:37:42


Aleksey,

The attached code works like a dream on MSVC 7.1, but MSVC 7.0 again has its
problems:

Problem No. 1: Expression 1 does not seem to work, because Derived is an
incomplete type:
To reproduce, you might want to comment-out expression 3 and uncomment
expression 4.

Problem No. 2: mpl::fold produces errors similar to the ones I had with
transform yesterday
In the original file, please comment out expression 1 and uncomment
expression 2 to reproduce.

Luckily, I can continue with MSVC7.1 now, so these bugs have low priority.

Thank you!

Best regards,

Andreas

#include <boost/mpl/placeholder.hpp>
#include <boost/mpl/apply_if.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/list.hpp>
#include <boost/mpl/front.hpp>
#include <boost/mpl/is_sequence.hpp>

#include <boost/mpl/transform.hpp>
#include <boost/mpl/fold.hpp>

template< class Event >
class event_handler
{
  protected:
    event_handler() {}
    ~event_handler() {}

  private:
    virtual bool handle_event( const Event & theEvent ) = 0;
};

template< class Derived, class Event, class Destination >
class transition_handler : public event_handler< Event >
{
  private:
    virtual bool handle_event( const Event & ) { /* */ }
};

template< class Event, class Destination >
struct transition
{
  template< class Derived >
  struct apply
  {
    typedef transition_handler< Derived, Event, Destination > type;
  };
};

namespace mpl = boost::mpl;

template< class T >
struct make_list : public mpl::apply_if<
  mpl::is_sequence< T >, mpl::identity< T >,
  mpl::identity< mpl::list< T > > > {};

class empty_type {};

template< class Base1, class Base2 >
struct derive
{
  struct type : public Base1, public Base2 {};
};

class EvPause {};
class EvStop {};
class Paused {};
class Stopped {};

using namespace mpl::placeholder;

template< class Derived, class Transitions >
struct state_base_type
{
  private:
    typedef typename make_list< Transitions >::type transition_list;
    // The following is a problem, because Derived is incomplete
    typedef typename mpl::transform< /* 1 */
      transition_list, mpl::apply1< _, Derived > >::type handler_list;
// typedef mpl::list< transition_handler< Derived, EvPause, Paused > >
// handler_list; /* 2 */

  public:
    // There are problems with the following as well, errors are similar
    // to the ones I had with transform yesterday
    typedef typename mpl::fold< /* 3 */
      handler_list, empty_type, derive< _1, _2 > >::type type;
// typedef empty_type type; /* 4 */
};

class Running : public state_base_type< Running,
  mpl::list< transition< EvPause, Paused >,
             transition< EvStop, Stopped > > >::type {};

int main()
{
  // this is just to see the type in the debugger
  Running * pState1 = 0;
  pState1;
 return 0;
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk