Getting around forward references in templates?

Tristam MacDonald swiftcoder at gmail.com
Mon May 7 06:41:45 PDT 2007


Interesting... So since I am using gdc, both compilers exhibit this bug. More to the point, has anyone come up with ways of dealing with this? From what I have tried, no source file containing a template specialisation can be imported by the file containing the template itself - even if the first file doesn't use the template.

Worth noting is that if I put both structs from my original example in the same file, the forward references work fine! So why are imports different?

A.d:

module A;

struct As(T)
{
	T x, y;
	
	void set(Bs o) {x = cast(T)o.a; y = cast(T)o.b;}
}

alias As!(float) Af;

struct Bs
{
	float a, b;
	
	static Bs opCall(float x, float y) {Bs t; t.a = x; t.b = y; return t;}
	
	void set(Af o) {a = o.x; b = o.y;}
}
 // No errors and compiles fine???

Stewart Gordon Wrote:
> "Tristam MacDonald" <swiftcoder at gmail.com> wrote in message 
> news:f1f6ac$2uvc$1 at digitalmars.com...
> > So am I correct that it is impossible to forward reference a template 
> > instantiation? And if so, why?
> 
> Because the compiler has bugs in it.
> 
> http://d.puremagic.com/issues/show_bug.cgi?id=810
> 
> Generally, if you ever see the phrase "forward reference" in a compiler 
> message, chances are it's a bug.
> 
> http://d.puremagic.com/issues/show_bug.cgi?id=340
> 
> Stewart. 



More information about the Digitalmars-d mailing list