Doubt about alias this

d coder dlang.coder at gmail.com
Thu Dec 6 03:24:13 PST 2012


Greetings

Kindly take a look at the code below. I am using alias this with a function
that returns by value. I believe in such cases the alias should not take
affect when an instance of foo is being used as an lvalue. As a result
elements of bar should not have been visible inside the constructor of foo.

Please comment. Is this a bug?

Regards
- Puneet

struct bar (bool B, N...) {
  int n = 0;
}

struct foo (N...) {
  bar!(true, N) _bar = void;

  bar!(true, N) getN() {
    return _bar;
  }

  alias getN this;

  public this(T) (T other)
    if (is(T unused : int)) {
    n = other;
  }
}


void main() {
  import std.stdio;
  foo!8 a = 42;
  writeln(a.n);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20121206/ab7a7b05/attachment.html>


More information about the Digitalmars-d mailing list