Why do some T.init evaluate to true while others to false?
ArturG via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri May 27 11:48:23 PDT 2016
On Friday, 27 May 2016 at 18:03:23 UTC, Steven Schveighoffer
wrote:
> I didn't change the default. The default is to pick the first
> member and use that as the init value. I may not have even
> considered what foo.init might be when I was creating my enum.
>
> -Steve
by default i ment this
enum foo
{
bar
}
foo f;
if(f) "dosnt print".writeln;
but i understand what you mean which adds a problem to my
checkThen template, as the return type of the template depends on
the return type of the callable which right now returns the init
value of the callable return type if the type you pass into the
template evaluates to false.
an example:
class Foo { int x; }
Foo foo(){ return null; }
foo.checkThen!( f => f.x = 5; ).writeln; // writes f.x.init
because i kinda need a common return type if foo wouldnt return
null
More information about the Digitalmars-d-learn
mailing list