[Issue 9151] opCast makes "this" alias ineffective

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Dec 13 09:48:47 PST 2012


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



--- Comment #1 from Puneet Goel <puneet at coverify.org> 2012-12-13 09:48:46 PST ---
Also note that if both "this" alias and opCast to bool are present, the "this"
alias is getting ignored in favor of opCast -- though I am not using explicit
cast operation.

struct Foo {
  int t;
  bool get() {
    return (t == 0);
  }
  alias get this;
  T opCast(T) () if(is(T == int)) {
    return t;
  }
  T opCast(T) () if(is(T == bool)) {
    import std.stdio;
    writeln("I am here");
    return (t != 0);
  }
}

void main() {
  Foo f;
  if(f) {}
}

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