www.digitalmars.com         C & C++   DMDScript  

D - typedefs in templates get exported ?

I've been trying to write a simple template module to allow functions from
dll to be loaded

but it seem that typedefs from templates get put into the global namespace.
and forward declares are needed

----------------------------------------------------------------------------
--
template func0( T )
{
 typedef T (*fp)() = &erf;
 T erf() { throw new Exception("func0 not inited"); return T.init; }
}

template func1( T, P )
{
 typedef T (*fp)(P) = &erf;
 T erf( P p ) { throw new Exception("func0 not inited");  return T.init; }
}

instance func0( int ) I_V_fp;
instance func1( int, int ) I_I_fp;

I_V_fp.fp tc;

int main( char[][] args )
{
 return tc();
}
----------------------------------------------------------------------------
--
error on compile ;
tet.d(5): cannot implicitly convert T(*)() to int(*)()

----------------------------------------------------------------------------
--

template func0( T )
{
 T erf() { throw new Exception("func0 not inited"); return T.init; }
 typedef T (*fp)() = &erf;
// fp use() { return erf; }
}

template func1( T, P )
{
 T erf( P p ) { throw new Exception("func1 not inited");  return T.init; }
 typedef T (*fp)(P) = &erf;
// fp use() { return erf; }
}
extern( Windows)
{
instance func1( int, int ) I_I_fp;
instance func0( int ) I_V_fp;
}

I_V_fp.fp tc;

int main( char[][] args )
{
 return tc();
}
----------------------------------------------------------------------------
--
compiles, but
----------------------------------------------------------------------------
--
remove the comments on fp use() { return erf; }
(I know they should be &erf)
you get the error
tet.d(26): expected 1 arguments to function, not 0
change to &erf does not effect this;

----------------------------------------------------------------------------
--
template func0( T )
{
 T erf() { throw new Exception("func0 not inited"); return T.init; }
 alias T (*fp)(); // = &erf;
 fp use() { return &erf; }
}

template func1( T, P )
{
 T erf( P p ) { throw new Exception("func1 not inited");  return T.init; }
 alias T (*fp)(P); // = &erf;
 fp use() { return &erf; }
}
extern( Windows)
{
instance func1( int, int ) I_I_fp;
instance func0( int ) I_V_fp;
}

I_V_fp.fp tc;

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

----------------------------------------------------------------------------
--
compiles.
Feb 08 2003