On Fri, 23 Apr 2010 09:43:10 -0300, Robert Jacques <[email protected]> wrote:

On Fri, 23 Apr 2010 10:25:35 -0300, Gareth Charnock <[email protected]> wrote:
Is this a bug, or am I being dense? I've tried it this on 2.036,2.042 and 2.043 and on each the compiler produces errors. Searched bugzilla for "template and instantiated" and "template and instantiate"

struct A(uint N)  {
}
void unary_op(uint N)(A!(N)) {
}
void main() {
     A!(3) a3;

     pragma(msg,typeof(a3)); //prints A!(3), so a3 is not void, dammit

     unary_op!3(A);// Error: cannot implicitly convert expression
                   // (A(uint N)) of type void to A!(N)
unary_op(A); // Error: template template.unary_op(uint N) does not // match any function template declaration
                   // Error: template template.unary_op(uint N) cannot
                   // deduce template function from argument types
                   // !()(void)   <== what?
}

Well, first, let's make this valid D code:


struct A(uint N)  {}

void unary_op(uint N)(A!N value) {}

void main(string[] args) {
     A!(3) a3;
     pragma(msg,typeof(a3));
     unary_op!3(a3);
     unary_op(a3);
}

But that still doesn't compile.

It looks like you're running across a variant of bug 2257 (http://d.puremagic.com/issues/show_bug.cgi?id=2257). Please vote it up.



PS. You can get things like this to work using template constraints.

For example, here's a horrible hack:
void unary_op(T)(T value)
if(T.stringof[0..3] == "A!(" && T.stringof[$-1..$] == ")"  ){}

Reply via email to