why no to!bool(0) or to!bool(1) ?

growler growlercab at gmail.com
Mon Aug 26 22:34:59 PDT 2013


On Tuesday, 27 August 2013 at 05:13:01 UTC, Jesse Phillips wrote:
> On Tuesday, 27 August 2013 at 04:08:47 UTC, growler wrote:
>> Is there any reason why the following code fails to compile?
>>
>> ---
>> auto bfalse = to!bool(0);
>> auto btrue = to!bool(1);
>> ---
>> dmd2/src/phobos/std/conv.d(329): Error: template 
>> std.conv.toImpl
>> cannot deduce template function from argument types 
>> !(bool)(int)
>
> No one implemented probably. BTW:

No worries, thanks for the info.

>
> void main() {
>      bool a = 0;
>      bool b = 1;
>
>      assert(!a);
>      assert(b);
> }

The implicit conversion is only for literals and besides, I have
this sort of hackiness happening:

alias typeof(s.tueplof[ii]) FieldType;
s.tupleof[ii] = value.to!FieldType;

I just stick in a static-if(isBoolean!FieldType) and all is well.

Thanks,
G


More information about the Digitalmars-d-learn mailing list