An struct copy constructor that can cope with an AA?
Steven Schveighoffer
schveiguy at gmail.com
Mon Mar 9 17:52:32 UTC 2020
On 3/9/20 11:49 AM, mark wrote:
> On Monday, 9 March 2020 at 14:45:15 UTC, Steven Schveighoffer wrote:
>> On 3/9/20 9:23 AM, mark wrote:
>>> I have this struct:
> [snip]
>> I would name it dup instead of copy for consistency with D. A copy
>> constructor is pretty heavy for a struct to do a complete duplication
>> of the AA. You should have to opt-in to that.
>>
>
> Thanks, I'd already realised I ought to rename it .dup.
>
> Also, I only actually need to create it from the keys since I'm using
> the tags AA as a set so every value is the same. I did try tags.dup but
> got this:
>
> src/deb.d(25,24): Error: cannot implicitly convert expression
> dup(this.tags) of type const(void[0])[string] to void[0][string]
>
Right, because it's inside a const member function, the tags member is
const.
Right now, it looks like dup does not work even for value types (e.g.
const int[int] -> int[int]) let alone types with indirection (it should
also work for string keys). If there's not an issue already, someone
should file it.
-Steve
More information about the Digitalmars-d-learn
mailing list