RE: [boost] [mpl] More problems with MSVC 7.0, 8-/

2003-02-07 Thread Aleksey Gurtovoy
Andreas Huber wrote:
> 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. 

OK, I see the problem; fixed now in the CVS. 

But what I was horrified by is the way VC 7.0 masks the errors here. 
It's the first time I saw something like this (I don't use 7.0 in 
day-to-day work), and I just hope you didn't spent too much time 
figuring out what was happenning there. FYI, MSVC 6.5 is much more 
predictable and easy to work with in this regard, and since, from 
MPL-centric point of view, the compilers are pretty much at the
the same level of standard conformance, for debugging purposes
you might consider using 6.5 (if you have one, of course).


> 
> 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. 

Oh, this one is known - please see 

http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?Effective_MPL
,

Item 5.7

But actually you don't need to implement your own 'derive' 
metafunction, MPL already does it for you:

#include "boost/mpl/inherit.hpp"
#include "boost/mpl/empty_base.hpp"

// ...

// was:
//  typedef typename mpl::fold< /* 3 */ 
//handler_list, empty_type, derive< _1, _2 > >::type type; 

typedef typename mpl::fold< 
  handler_list, mpl::empty_base, mpl::inherit< _1, _2 >
>::type type; 

or, shorter yet,

#include "boost/mpl/inherit_linearly.hpp"

// ...
typedef typename mpl::inherit_linearly<
  handler_list
, mpl::inherit<_1,_2>
>::type type;


The same for 'make_list' - the MPL version is called 'as_sequence',
please see "boost/mpl/as_sequence.hpp".

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

Nonetheless, they are fixed in the CVS now :). 

Thanks for the reports,
Aleksey
___
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost



[boost] [mpl] More problems with MSVC 7.0, 8-/

2003-02-06 Thread Andreas Huber
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 
#include 
#include 
#include 
#include 
#include 
#include 

#include 
#include 



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;
}


___
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost