compile-time opIndex
Dicebot via Digitalmars-d
digitalmars-d at puremagic.com
Thu Dec 18 08:34:19 PST 2014
On Thursday, 18 December 2014 at 16:15:09 UTC, Steven
Schveighoffer wrote:
> On 12/18/14 10:44 AM, Dicebot wrote:
>> Have you seen my http://wiki.dlang.org/DIP63 ?
>
> I admit this is somewhat over my head, but it seems to be more
> focused on types.
In D there is no special built-in value tuple concept. It is all
same thing but emulating this behavior for symbols and types is
much more difficult compared to values. This is the reason for
such focus - rest is not really a problem.
> I will note that your example:
>
> struct Pack(T...)
> {
> alias expand = T;
> alias expand this;
> }
>
> I don't think this would work, since you can't alias a value to
> a type?
Try this and be surprised :) `alias this` affects any symbol
lookup and this pattern results in pretty interesting behavior.
But it is still not good enough as described in the DIP.
> But I don't use tuples regularly, so I am not sure where
> exactly expand is used. I thought it was to convert a concrete
> struct into a tuple of values, not a type tuple.
You can ignore expansion for now, it was motivating use case but
DIP itself defines tools of defining user types that act like
built-in tuples - which fits the theme of your original proposal.
It also briefly speculates why adding such features to structs
does not seem a good idea.
Also there is no difference between tuple of values and type
tuple, it is same entity.
> I don't disagree with the idea of having operators inside
> templates, I just don't know if it solves the problem I was
> looking at.
Your original snippet seems to implementable within proposed DIP
if you replace struct with raw template. You will lose struct
properties like having actual instance but those don't exist for
built-in tuples either.
More information about the Digitalmars-d
mailing list