digitalmars.D.learn - why no to!bool(0) or to!bool(1) ?
- growler (17/17) Aug 26 2013 Is there any reason why the following code fails to compile?
- Jesse Phillips (8/15) Aug 26 2013 No one implemented probably. BTW:
- H. S. Teoh (6/25) Aug 26 2013 Hmm. Maybe file an enhancement request here:
- growler (5/30) Aug 26 2013 Done.
- growler (9/27) Aug 26 2013 The implicit conversion is only for literals and besides, I have
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) I can use a string, like so: --- auto bfalse = to!bool("false"); auto btrue = to!bool("true"); --- ...but usually the database column is an INTEGER type. I can cast(bool)(0) or cast(bool)(1) no problem but I much prefer to!bool. Thanks, G.
Aug 26 2013
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: void main() { bool a = 0; bool b = 1; assert(!a); assert(b); }
Aug 26 2013
On Tue, Aug 27, 2013 at 07:12:56AM +0200, Jesse Phillips wrote:On Tuesday, 27 August 2013 at 04:08:47 UTC, growler wrote:Hmm. Maybe file an enhancement request here: http://d.puremagic.com/issues T -- "I'm not childish; I'm just in touch with the child within!" - RLIs 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: void main() { bool a = 0; bool b = 1; assert(!a); assert(b); }
Aug 26 2013
On Tuesday, 27 August 2013 at 05:22:00 UTC, H. S. Teoh wrote:On Tue, Aug 27, 2013 at 07:12:56AM +0200, Jesse Phillips wrote:Done. http://d.puremagic.com/issues/show_bug.cgi?id=10909 Thanks, G.On Tuesday, 27 August 2013 at 04:08:47 UTC, growler wrote:Hmm. Maybe file an enhancement request here: http://d.puremagic.com/issues TIs 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: void main() { bool a = 0; bool b = 1; assert(!a); assert(b); }
Aug 26 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:No worries, thanks for the info.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: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
Aug 26 2013