seeding the pot for 2.0 features

BCS BCS at pathlink.com
Fri Jan 26 11:42:18 PST 2007


BCS wrote:
> 1)  Modules structs and classes can have static this() functions, why 
> functions? If a static nested constructor were allowed for functions, it 
> would allow static function variable to be initialized at load time.


I think I have a better solution, let function statics behave like 
globals as far as access goes (plus default to private if that isn't 
already the case).

int[int] k;

void fn()
{
	static int[int] i;
	...
}

static this()
{
	foreach(int[2] j; [cast(int[2]) [1,0],[2,1],[4,2],[8,3],...])
	{
		k[j[1]] = j[0];
		fn.i[j[0]] = j[1];
	}
}



More information about the Digitalmars-d mailing list