Issue 8409 - Proposal: implement arr.dup in library #298
Conversation
@@ -603,6 +603,40 @@ template _isStaticArray(T) | |||
enum bool _isStaticArray = false; | |||
} | |||
|
|||
/*@property */auto dup(E)(inout(E)[] arr) pure @trusted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe nothrow
too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah..., yes. new
can become nothrow. Thanks.
Apply two fixes from @alexp's comments. |
You might want to fix this: struct S{ |
Added test case. |
@@ -603,6 +603,40 @@ template _isStaticArray(T) | |||
enum bool _isStaticArray = false; | |||
} | |||
|
|||
/*@property */auto dup(E)(inout(E)[] arr) pure nothrow @trusted | |||
{ | |||
static struct X // dummy namespace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is X technically needed, or just for organizational purposes? In the latter case I think the function is small enough to just delete it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is 'needed' because the grammar on TDPL (which would, as far as I can see, not allow local struct definitions either), as well as DMD's parser are all messed up. It is not currently possible to declare a local template without these tricks, because parsing fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be filed as a bug. It breaks the TOWD principle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the TOWD principle?
This seems to be failing the auto tester? |
Because this is based on the compiler fix (dlang/dmd#1110), so until merging it, auto tester will not become green. |
Are we just waiting on review of the compiler pull request in order to move forward with this? (I.e. does everyone agree that this is a good idea?) |
@9rnsr see my previous comment |
How about replacing the built-in properties instead of adding an alternative syntax? |
The DMD pull request is merged now. Can we merge this? |
This is really odd, we already have the rule in D that |
Thanks many comments. I need more thought about this. Temporarily close. |
http://d.puremagic.com/issues/show_bug.cgi?id=8409
This works with UFCS, and doesn't break existing codes.
arr.dup
,arr.idup
arr.dup()
Requires: dlang/dmd#1110