From: Andreas Huber (ahd6974-spamgroupstrap_at_[hidden])
Date: 2005-08-01 05:32:48


Hi there

I'm trying to address a point raised by Jonathan Turkanis during the
formal review of the statechart library. Basically, the problem boils
down to the following:

#include <boost/mpl/list.hpp>
#include <boost/mpl/size.hpp>
#include <boost/mpl/as_sequence.hpp>

namespace mpl = boost::mpl;

// InnerInitial is either an mpl sequence of types or a single type
template< class InnerInitial >
struct state
{
  // stateArray_ must have a length equal to the number of types
  // in InnerInitial
  int stateArray_[
    mpl::size<
      typename mpl::as_sequence< InnerInitial >::type
>::type::value
  ];
};

// A is defined later, possibly in a different translation unit
struct A;

template< class X >
struct B
{
  typedef typename X::reactions reactions;
};

int main()
{
  // fine: instantiation with an incomplete type
  state< A > a;
  // fine: instantiation with an mpl sequence containing B< A >
  state< mpl::list< B< A > > > b;
  // error: mpl::as_sequence triggers the instantiation of B's member
  // typedef, which tries to access the member typedef of A. A compile-
  // time error results because A is still incomplete at this point.
  state< B< A > > c; // *** here ***

  return 0;
}

MSVC7.1 and GCC3.4 agree that the last state template instantiation is
illegal (use of undefined type A). I'm wondering whether there is any
way to make this legal (different as_sequence implementation, implement
the state template differently, etc.)?

Thanks & Regards,

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