New abstraction: Layout

Steven Schveighoffer schveiguy at yahoo.com
Tue Feb 20 12:34:43 UTC 2018


On 2/18/18 4:52 AM, Dmitry Olshansky wrote:
> On Saturday, 17 February 2018 at 19:37:12 UTC, Steven Schveighoffer wrote:
>> On 2/17/18 9:59 AM, Andrei Alexandrescu wrote:
>>> On 02/17/2018 09:03 AM, Steven Schveighoffer wrote:
>>>> I found this also works:
>>>>
>>>> static foreach(alias x; S.tupleof)
>>>> {
>>>>     writeln(x.offsetof);
>>>> }
>>>
>>> Yes, the implementation uses offsetof.
>>>
>>
>> I guess I'm just confused based on the statement "the builtin .tupleof 
>> ... [omits] the essential information of field offsets."
>>
>> What is this construct giving us that .tupleof doesn't?
>>
> 
> I guess the construct captures offsets as part of type. This is useful 
> for allocators + 2 things with same Layout can be bitblitted to each other.

I haven't looked at it in depth, so I didn't know the result of the 
abstraction (I thought it was a tuple, or a pair of tuples).

Note, you could do this without the need for a new abstraction, simply 
with .tupleof on the type itself.

And static foreach has made this much simpler. But definitely the 
interface to getting things from tupleof is not consistent. This reason 
alone may be cause to add such a construct.

-Steve


More information about the Digitalmars-d mailing list