Issue 1012 - cannot instantiate template with no or default arguments without !() #1295

Closed
wants to merge 1 commit into
from

4 participants

@9rnsr
D Programming Language member

http://d.puremagic.com/issues/show_bug.cgi?id=1012

An enhancement which recently talked in the forum.

@ghost

What happens in this case:

struct Foo(T = int) { }
alias Foo Bar;  // is Bar a template or an instance?

and in this case:

template test(T) { }
template test(alias T) { }
struct Foo(T = int) { }
alias test!(Foo) X;  // which test is picked after the pull?

I don't think it's a smart idea to subtly instantiate templates in some places but not at others, it could cause problems. And your tests are going to have to be much more thorough than this, you're not even checking what the pragmas print. Additionally neither @WalterBright nor @andralex gave a nod to implement this, so they have to examine the enhancement & pull.

@donc
D Programming Language member

This pull request isn't relevant in either of those test cases. Neither of them generate template instances. So Bar is a template, just as before, and the test(alias T) is picked.
Look great to me, though I agree it would be better to use static assert instead of pragma(msg) in the test cases.

@ghost

Ok the semantics stay the same, but what the user expects might not. If in one context Foo becomes an instance, and in the other Foo is still a template symbol, it might be confusing to people. I'm for this pull, but I worry it might cause confusion.

@donc
D Programming Language member

The only bad situation I can see is if you have struct Foo{} and you change it to struct Foo(T=int){}, then any existing usage of Foo will continue to compile and work without modification, except that in explicit template parameters Foo will be an alias, not a type. If you have templates like your test() example, it will silently go from matching the type, to matching the alias. OTOH things like adding 'alias this' have the same sorts of consequences, but far more severe.

@tgehr

I don't see the point of this.

@JakobOvrum
D Programming Language member

I don't see the point of this.

In particular, it's nice to have a default instance of class or struct templates when writing library code:

enum Options { a, b }

struct Foo(Options option = Options.a)
{
    ...
}

void main()
{
    auto foo = Foo!(Options.b)();
    auto bar = Foo(); // currently not possible
}
@tgehr

That is not what this pull does. I have no issues with extending IFTI to aggregate template parameters. Your code still does not compile.

@9rnsr
D Programming Language member

I don't have strong motivation to keep this open, so close this.

@9rnsr 9rnsr closed this Jan 22, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment