January 21, 2003
walter; when I try to compile the following code with 0.50 alpha
I get
Assertion failure: '0' on line 918 in file 'func.c'
(uncomment the comment and the compiler crashes very likely I've got the
template specialation wrong)


//template delegatehelper( P, RV, T : RV (*T)( P ) )
template delegatehelper( P, RV, T : RV (*)( P ) )
{
  class FcHelper
  {
   T toCall;
   this( T funcPtr ) { toCall = funcPtr; }
   RV evoke( P param ) { return toCall( param ); }
  }
}

template autocloser( T, P )
{
 auto class MyBlock
 {
  bit delegate ( T ) closeDelegate;
  bit (*closeFuncPtr)( T );

  closeDelegate close;
  T item;

  this( operationDelegate close0, P param, out T made )
  {
   mad = item = new T( param );
   close = close0;
  }
  this( closeFuncPtr close0, P param, out T made )
  {
   instance delegatehelper( T, bit, closeFuncPtr ) dh;
   dh.FcHelper conv = new dh.FcHelper( close0 );
   this( &conv.evoke, param, made );
  }

  ~this()
  {
   close( item );
  }
 }
}

class MyFile { int i; this( int ii ) { i = ii; printf( "OPEN\n" ); } }

bit closeIt( MyFile f )
{
 printf( "CLOSE\n" );
 return true;
}


int main( char[][] args )
{
 instance autocloser( MyFile, int ) closer;
 MyFile res;
 printf("Starting ...\n");
 {
  auto closer.MyBlock autoCloser = new closer.MyBlock( &closeIt, 3, res );
  printf("[doing stuff]\n");
 }
 printf("end.\n");

 return 0;
}



January 21, 2003
traced to destructor

the following will compile if you comment out the destructor

template foo( T )
{
 class failsToCompile
 {
  this( T item ) { }
  ~this()
  {
  }
 }
}

instance foo( int ) myfoo;

int main( char[][] args )
{
 return 0;
}



Top | Discussion index | About this forum | D home