Template pred is true for pred!(pred!(pred)) but not for value "true"

Meta via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Mar 8 14:17:30 PDT 2015


On Sunday, 8 March 2015 at 21:11:12 UTC, Meta wrote:
> Yeah, definitely wrong.
>
> template canBeAlias(T...)
> if (T.length == 1)
> {
> 	static if (is(typeof({alias _ = T[0];})))
> 	{
> 		enum canBeAlias = true;
> 	}
> 	else
> 	{
> 		enum canBeAlias = false;
> 	}
> }
>
> void main()
> {
>     pragma(msg, canBeAlias!canBeAlias); //prints "true"
>     static assert(canBeAlias!(canBeAlias!canBeAlias)); 
> //passes?!
>     static assert(!canBeAlias!true); //Error: static 
> assert(!true) is false
> }
>
> OR
>
> void main()
> {
>     pragma(msg, canBeAlias!canBeAlias); //prints "true"
>     static assert(!canBeAlias!true); //passes
>     //Error: static assert (canBeAlias!(true)) is false
>     static assert(canBeAlias!(canBeAlias!canBeAlias));
> }
>
> So it definitely does depend on which comes first. This is a 
> weird bug...

Urgh, I'm all messed up now. The results in the second case are 
correct, but the results in the first case are wrong, as 
!canBeAlias!true should be !false, not !true.


More information about the Digitalmars-d-learn mailing list