Whats the best way to get a struct/class member type?
simendsjo
simendsjo at gmail.com
Mon Apr 2 03:31:56 PDT 2012
On Mon, 02 Apr 2012 12:22:16 +0200, Simen Kjaeraas
<simen.kjaras at gmail.com> wrote:
> On Mon, 02 Apr 2012 12:07:38 +0200, simendsjo <simendsjo at gmail.com>
> wrote:
>
>> On Mon, 02 Apr 2012 10:56:41 +0200, simendsjo <simendsjo at gmail.com>
>> wrote:
>>
>>>
>>> The documentation explicitly says it shouldn't work for other than
>>> static members though.
>>> http://dlang.org/traits.html#getMember
>>
>> http://d.puremagic.com/issues/show_bug.cgi?id=7809
>
> struct Foo {
> int n;
> }
>
> void main( ) {
> static assert(is(typeof(Foo.n) == int));
> }
>
> Yup, it compiles. Mayhap it shouldn't, but it does. Of course, trying
> to use it for anything but typeof gives you an error. From this we can
> conclude that either this behavior is also buggy, or getMember should
> work that way.
It's convenient that it works this way.
Probably a change that didn't get reflected to the documentation.
More information about the Digitalmars-d-learn
mailing list