Boost logo

Boost :

From: Andreas Huber (ah2003_at_[hidden])
Date: 2003-02-23 16:36:18

Hi Aleksey & all other metaprogramming gurus

The attached code compiles just fine with MSVC7.1 but MSVC7.0 once more has
its problems. This time I'm quite sure it has nothing to do with MPL,
instead VC7.0 seems to get confused and reports the following:

d:\Data\StopWatch\StopWatch.cpp(58) : error C2516:
'state_base_type<Derived,Context,Transitions,InnerInitial>::type' : is not a
legal base class

According to the docs this error is reported when you try to inherit from
built-in types like int.
If you then remove the 3 first characters of the lines marked with // ***
here ***, the program compiles and you can see in the debugger that the
result returned by the metafunction state_base_type is quite a legal base
class (see type of pWhatever).

Has anyone else ever encountered similar problems with either 7.0 or 6.5?
Are there any workarounds?



P.S. Please just ignore this when you're busy to make the new boost release
happen. I will repost in 2 weeks if I don't get any answers.


#include <boost/mpl/apply_if.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/mpl/as_sequence.hpp>
#include <boost/mpl/inherit.hpp>
#include <boost/mpl/list.hpp>
#include <boost/mpl/empty.hpp>
#include <boost/mpl/size.hpp>
#include <boost/mpl/clear.hpp>
#include <boost/mpl/transform.hpp>
#include <boost/mpl/fold.hpp>
namespace mpl = boost::mpl;
class node_state {};
class leaf_state {};
template< class InnerInitialList >
struct state_type
  typedef typename mpl::apply_if<
    mpl::empty< InnerInitialList >,
    mpl::identity< leaf_state >,
    mpl::identity< node_state > >::type type;
using namespace mpl::placeholder;
template< class Transitions, class Derived >
struct handler_list
  typedef typename mpl::transform<
    typename mpl::as_sequence< Transitions >::type,
    mpl::apply1< _, Derived > >::type type;
template< class Derived, class Context,
          class Transitions, class InnerInitial >
struct state_base_type
  typedef typename mpl::fold<
    typename handler_list< Transitions, Derived >::type,
    typename state_type<
      typename mpl::as_sequence< InnerInitial >::type >::type,
    mpl::inherit2< _1, _2 > >::type type;
class StopWatch {};
typedef mpl::clear< mpl::list<> >::type empty_list;
// /* // *** here ***
template< class Derived,
          class Context,
          class Transitions = empty_list,
          class InnerInitial = empty_list >
class simple_state : public state_base_type<
  Derived, Context, Transitions, InnerInitial >::type {};
class Reset : public simple_state< Reset, StopWatch > {};
// */ // *** here ***
// class Reset; // *** here ***
int main( int argc, char * argv[] )
  state_base_type< Reset, StopWatch, empty_list, empty_list >::type *
    pWhatever = 0;
 return 0;

Boost list run by bdawes at, gregod at, cpdaniel at, john at