Re: is(some template instantiation) is true, but the actual instantiation fails

2016-01-30 Thread Adrian Matoga via Digitalmars-d-learn
On Saturday, 30 January 2016 at 00:16:21 UTC, Ali Çehreli wrote: > https://issues.dlang.org/show_bug.cgi?id=15623 As I noted on the bug report, they are work when moved from module scope to inside a function (e.g. main()). At least there's that workaround... Ali Thanks a lot! Now I can con

Re: is(some template instantiation) is true, but the actual instantiation fails

2016-01-30 Thread Adrian Matoga via Digitalmars-d-learn
On Friday, 29 January 2016 at 23:44:56 UTC, Basile B. wrote: Haven't you seen my answer about constraint ? If you put a constraint on your function template then invalid instantiations are rejected. I mean... this language feature is not just ornamental... What do you think constraints are u

Re: is(some template instantiation) is true, but the actual instantiation fails

2016-01-29 Thread Ali Çehreli via Digitalmars-d-learn
On 01/29/2016 09:01 AM, Adrian Matoga wrote: > Oh, there's more: > // this should fail: > static assert(is(CallsFoo!NoFoo)); > // this should fail too: > static assert(is(typeof({ alias Baz = CallsFoo!NoFoo; return Baz.init; > }(; > // and this: > static assert(__traits(compiles, { alias Baz

Re: is(some template instantiation) is true, but the actual instantiation fails

2016-01-29 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/29/16 6:44 PM, Basile B. wrote: Haven't you seen my answer about constraint ? If you put a constraint on your function template then invalid instantiations are rejected. I mean... this language feature is not just ornamental... What do you think constraints are used for otherwise ^^ A c

Re: is(some template instantiation) is true, but the actual instantiation fails

2016-01-29 Thread Basile B. via Digitalmars-d-learn
On Friday, 29 January 2016 at 17:01:46 UTC, Adrian Matoga wrote: On Friday, 29 January 2016 at 16:36:01 UTC, Steven Schveighoffer wrote: On 1/29/16 10:28 AM, Adrian Matoga wrote: [...] is(T) is supposed to be false if T is not a valid type. I would agree with you that the static assert shoul

Re: is(some template instantiation) is true, but the actual instantiation fails

2016-01-29 Thread Adrian Matoga via Digitalmars-d-learn
On Friday, 29 January 2016 at 16:36:01 UTC, Steven Schveighoffer wrote: On 1/29/16 10:28 AM, Adrian Matoga wrote: Code: struct HasFoo { void foo() {} } struct NoFoo {} struct CallsFoo(T) { T t; void bar() { t.foo(); } } static assert(is(CallsFoo!HasFoo)); alias Bar = CallsFoo!

Re: is(some template instantiation) is true, but the actual instantiation fails

2016-01-29 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/29/16 10:28 AM, Adrian Matoga wrote: Code: struct HasFoo { void foo() {} } struct NoFoo {} struct CallsFoo(T) { T t; void bar() { t.foo(); } } static assert(is(CallsFoo!HasFoo)); alias Bar = CallsFoo!HasFoo; static assert(is(CallsFoo!NoFoo)); // (1) //alias Baz = CallsFoo

Re: is(some template instantiation) is true, but the actual instantiation fails

2016-01-29 Thread Basile B. via Digitalmars-d-learn
On Friday, 29 January 2016 at 15:28:29 UTC, Adrian Matoga wrote: How can I reliably test if CallsFoo can be instantiated? You can use a constraint to prevent invalid instantiation: struct HasFoo { void foo() {} } struct NoFoo {} struct CallsFoo(T) if (__traits(hasMember, T, "foo")) {

is(some template instantiation) is true, but the actual instantiation fails

2016-01-29 Thread Adrian Matoga via Digitalmars-d-learn
Code: struct HasFoo { void foo() {} } struct NoFoo {} struct CallsFoo(T) { T t; void bar() { t.foo(); } } static assert(is(CallsFoo!HasFoo)); alias Bar = CallsFoo!HasFoo; static assert(is(CallsFoo!NoFoo)); // (1) //alias Baz = CallsFoo!NoFoo; // (2) This compil