[Issue 7301] RegexMatch opCast!bool not working

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jan 17 06:42:59 PST 2012


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



--- Comment #5 from Jerry Quinn <jlquinn at optonline.net> 2012-01-17 06:42:58 PST ---
(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.

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?

Note that the same compile failure happens if I write:

  auto re = regex("test");
  if (match("test", re)) { ... }


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: -------


More information about the Digitalmars-d-bugs mailing list