Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Issue 8409 - Proposal: implement arr.dup in library #298

Closed
wants to merge 3 commits into from

Conversation

9rnsr
Copy link
Contributor

@9rnsr 9rnsr commented Sep 9, 2012

http://d.puremagic.com/issues/show_bug.cgi?id=8409

This works with UFCS, and doesn't break existing codes.

arr.dup, arr.idupbuilt-in property is used
arr.dup()library version is used

Requires: dlang/dmd#1110

@@ -603,6 +603,40 @@ template _isStaticArray(T)
enum bool _isStaticArray = false;
}

/*@property */auto dup(E)(inout(E)[] arr) pure @trusted
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe nothrow too?

Copy link
Contributor Author

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.

@9rnsr
Copy link
Contributor Author

9rnsr commented Sep 9, 2012

Apply two fixes from @alexp's comments.

@tgehr
Copy link

tgehr commented Sep 9, 2012

You might want to fix this:

struct S{
immutable int x;
}
void main(){
S[] x = [];
auto y=x.dup();
}

@9rnsr
Copy link
Contributor Author

9rnsr commented Sep 9, 2012

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
Copy link
Member

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.

Copy link

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.

Copy link
Member

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.

Copy link
Member

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?

@alexrp
Copy link
Member

alexrp commented Oct 6, 2012

This seems to be failing the auto tester?

@9rnsr
Copy link
Contributor Author

9rnsr commented Oct 6, 2012

Because this is based on the compiler fix (dlang/dmd#1110), so until merging it, auto tester will not become green.

@alexrp
Copy link
Member

alexrp commented Oct 19, 2012

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?)

@alexrp
Copy link
Member

alexrp commented Nov 18, 2012

@9rnsr see my previous comment

@MartinNowak
Copy link
Member

How about replacing the built-in properties instead of adding an alternative syntax?

@alexrp
Copy link
Member

alexrp commented Mar 7, 2013

The DMD pull request is merged now. Can we merge this?

@ghost
Copy link

ghost commented Mar 7, 2013

This is really odd, we already have the rule in D that foo and foo() are equivalent for functions, but now we're assigning a special meaning to it just for .dup. I think this is a step in the wrong direction..

@9rnsr
Copy link
Contributor Author

9rnsr commented Mar 7, 2013

Thanks many comments. I need more thought about this. Temporarily close.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
5 participants