http://d.puremagic.com/issues/show_bug.cgi?id=7301



--- Comment #6 from timon.g...@gmx.ch 2012-01-17 10:19:29 PST ---
(In reply to comment #5)
> (In reply to comment #4)
> > Neither int (outside the range [0,1]) nor RegexMatch implicitly convert to
> > bool. Negating counts as an explicit cast to bool.
> 
> As far as I can tell, RegexMatch does implicitly cast to bool.
> 
> struct RegexMatch {
>   T opCast(T : bool);
> }
> 
> I could be missing something, but this effectively declares an opCast!bool
> operator.
> 

opCast means explicit cast, as in cast(bool)regexMatch or !regexMatch or
regexMatch && 2.

> http://www.d-programming-language.org/operatoroverloading.html#Cast claims 
> that
> both ! and bare references will get rewritten to opCast!bool:
> 
>   if (e)   =>  if (e.opCast!(bool))
>   if (!e)  =>  if (!e.opCast!(bool))
> 
> That should take care of the return, no?

That only works for conditions and arguments to boolean operators. If you think
it should also work for return values where the enclosing function is declared
to return bool, then that is an enhancement request. It might be a reasonable
one.

> 
> Note that the same compile failure happens if I write:
> 
>   auto re = regex("test");
>   if (match("test", re)) { ... }
> 

Works for me.

> 
> It strikes me that the language docs are rather sparse on defining what can 
> and
> cannot be implicitly converted.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to