New abstraction: Layout

Steven Schveighoffer schveiguy at yahoo.com
Tue Feb 20 12:31:07 UTC 2018


On 2/19/18 6:18 AM, Nathan S. wrote:
> On Saturday, 17 February 2018 at 12:49:07 UTC, Andrei Alexandrescu wrote:
>> On 02/16/2018 10:10 PM, rikki cattermole wrote:
>>> Could use the name for the field as well. At the minimum useful for 
>>> debugging purposes.
>>
>> That would be tricky because fields are decomposed down to primitive 
>> types. -- Andrei
> 
> That's unfortunate. Not being able to get the names and types together 
> is my main dissatisfaction with the current interface.

.tupleof does all this:

struct S
{
   int x;
   double y;
}

static foreach(alias v; S.tupleof)
{
   pragma(msg, typeof(v));
   pragma(msg, v.offsetof);
   pragma(msg, __traits(identifier, v));
}

output while compiling:
int
0LU
x
double
8LU
y

It's admittedly an ugly interface...

-Steve


More information about the Digitalmars-d mailing list