Re: Struct that destroys its original handle on copy-by-value

2015-08-03 Thread Dicebot via Digitalmars-d-learn
On Monday, 3 August 2015 at 08:54:32 UTC, Kagamin wrote: On Saturday, 1 August 2015 at 11:47:29 UTC, Joseph Rushton Wakeling wrote: Yea, but that's not what I'm trying to achieve. I know how I can pass something to `take` so as to e.g. obtain reference semantics or whatever; what I'm trying

Re: Struct that destroys its original handle on copy-by-value

2015-08-03 Thread Kagamin via Digitalmars-d-learn
On Saturday, 1 August 2015 at 11:47:29 UTC, Joseph Rushton Wakeling wrote: Yea, but that's not what I'm trying to achieve. I know how I can pass something to `take` so as to e.g. obtain reference semantics or whatever; what I'm trying to achieve is a range that _doesn't rely on the user

Re: Struct that destroys its original handle on copy-by-value

2015-08-03 Thread Joseph Rushton Wakeling via Digitalmars-d-learn
On Monday, 3 August 2015 at 09:01:51 UTC, Dicebot wrote: It is now verified as safe by `return ref`. Yes, until you pointed this out to me I'd been convinced that classes were the way forward for RNGs. I think that `return ref` is going to be a _very_ powerful tool for facilitating

Re: Struct that destroys its original handle on copy-by-value

2015-08-02 Thread Joseph Rushton Wakeling via Digitalmars-d-learn
On 02/08/15 03:38, Dicebot via Digitalmars-d-learn wrote: On Saturday, 1 August 2015 at 17:50:28 UTC, John Colvin wrote: I'm not sure how good an idea it is to totally enforce a range to be non-copyable, even if you could deal with the function call chain problem. Even in totally save-aware

Re: Struct that destroys its original handle on copy-by-value

2015-08-01 Thread Joseph Rushton Wakeling via Digitalmars-d-learn
On 31/07/15 19:21, Ali Çehreli via Digitalmars-d-learn wrote: On 07/26/2015 04:29 AM, Joseph Rushton Wakeling via Digitalmars-d-learn wrote: is this design idea even feasible in principle, or just a bad idea from the get-go? As I understand it, it is against one of fundamental D

Re: Struct that destroys its original handle on copy-by-value

2015-08-01 Thread John Colvin via Digitalmars-d-learn
On Saturday, 1 August 2015 at 12:10:43 UTC, Joseph Rushton Wakeling wrote: On 31/07/15 19:21, Ali Çehreli via Digitalmars-d-learn wrote: On 07/26/2015 04:29 AM, Joseph Rushton Wakeling via Digitalmars-d-learn wrote: is this design idea even feasible in principle, or just a bad idea from

Re: Struct that destroys its original handle on copy-by-value

2015-08-01 Thread Joseph Rushton Wakeling via Digitalmars-d-learn
On 31/07/15 13:40, Kagamin via Digitalmars-d-learn wrote: On Sunday, 26 July 2015 at 12:16:30 UTC, Joseph Rushton Wakeling wrote: Example: Unique!Random rng = new Random(unpredictableSeed); rng.take(10).writeln; My aim by contrast is to _allow_ that kind of use, but render the original

Re: Struct that destroys its original handle on copy-by-value

2015-08-01 Thread Dicebot via Digitalmars-d-learn
On Saturday, 1 August 2015 at 17:50:28 UTC, John Colvin wrote: I'm not sure how good an idea it is to totally enforce a range to be non-copyable, even if you could deal with the function call chain problem. Even in totally save-aware code, there can still be valid assignment of a range type.

Re: Struct that destroys its original handle on copy-by-value

2015-07-31 Thread Ali Çehreli via Digitalmars-d-learn
On 07/26/2015 04:29 AM, Joseph Rushton Wakeling via Digitalmars-d-learn wrote: is this design idea even feasible in principle, or just a bad idea from the get-go? As I understand it, it is against one of fundamental D principles: structs are value types where any copy can be used in place

Re: Struct that destroys its original handle on copy-by-value

2015-07-31 Thread Ali Çehreli via Digitalmars-d-learn
On 07/31/2015 11:01 AM, Dicebot wrote: On Friday, 31 July 2015 at 17:21:40 UTC, Ali Çehreli wrote: On 07/26/2015 04:29 AM, Joseph Rushton Wakeling via Digitalmars-d-learn wrote: is this design idea even feasible in principle, or just a bad idea from the get-go? As I understand it, it is

Re: Struct that destroys its original handle on copy-by-value

2015-07-31 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jul 31, 2015 at 06:01:44PM +, Dicebot via Digitalmars-d-learn wrote: On Friday, 31 July 2015 at 17:21:40 UTC, Ali Çehreli wrote: On 07/26/2015 04:29 AM, Joseph Rushton Wakeling via Digitalmars-d-learn wrote: is this design idea even feasible in principle, or just a bad idea

Re: Struct that destroys its original handle on copy-by-value

2015-07-31 Thread Dicebot via Digitalmars-d-learn
On Friday, 31 July 2015 at 18:13:04 UTC, Ali Çehreli wrote: To make sure, I didn't mean that I know of structs in Phobos that behave that way. Although, it would be interesting to identify them. :) Ali Things like Unique, Scoped, RefCounted - pretty much everything which wraps reference

Re: Struct that destroys its original handle on copy-by-value

2015-07-31 Thread Dicebot via Digitalmars-d-learn
On Friday, 31 July 2015 at 18:23:39 UTC, H. S. Teoh wrote: It seems that what the language (originally) defines structs to be, is not entirely consistent with how it has come to be used (which also entailed later extensions to the struct definition), and this has been a source of problems.

Re: Struct that destroys its original handle on copy-by-value

2015-07-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/31/15 1:21 PM, Ali Çehreli wrote: Disallowing automatic copying and providing a function comes to mind. Isn't that what std.algorithm.move is for? -Steve

Re: Struct that destroys its original handle on copy-by-value

2015-07-31 Thread Dicebot via Digitalmars-d-learn
On Friday, 31 July 2015 at 17:21:40 UTC, Ali Çehreli wrote: On 07/26/2015 04:29 AM, Joseph Rushton Wakeling via Digitalmars-d-learn wrote: is this design idea even feasible in principle, or just a bad idea from the get-go? As I understand it, it is against one of fundamental D principles:

Re: Struct that destroys its original handle on copy-by-value

2015-07-31 Thread Ali Çehreli via Digitalmars-d-learn
On 07/31/2015 12:18 PM, Steven Schveighoffer wrote: On 7/31/15 1:21 PM, Ali Çehreli wrote: Disallowing automatic copying and providing a function comes to mind. Isn't that what std.algorithm.move is for? -Steve Sounds great and I like it! :) Ali

Re: Struct that destroys its original handle on copy-by-value

2015-07-31 Thread Kagamin via Digitalmars-d-learn
On Sunday, 26 July 2015 at 12:16:30 UTC, Joseph Rushton Wakeling wrote: Example: Unique!Random rng = new Random(unpredictableSeed); rng.take(10).writeln; My aim by contrast is to _allow_ that kind of use, but render the original handle empty when it's done. `take` stores the range,

Re: Struct that destroys its original handle on copy-by-value

2015-07-30 Thread via Digitalmars-d-learn
On Wednesday, 29 July 2015 at 19:10:36 UTC, Adam D. Ruppe wrote: On Sunday, 26 July 2015 at 12:16:30 UTC, Joseph Rushton Wakeling wrote: My aim by contrast is to _allow_ that kind of use, but render the original handle empty when it's done. I don't think D offers any way to do that. With the

Re: Struct that destroys its original handle on copy-by-value

2015-07-29 Thread Vlad Levenfeld via Digitalmars-d-learn
On Wednesday, 29 July 2015 at 19:10:36 UTC, Adam D. Ruppe wrote: On Sunday, 26 July 2015 at 12:16:30 UTC, Joseph Rushton Wakeling wrote: My aim by contrast is to _allow_ that kind of use, but render the original handle empty when it's done. I don't think D offers any way to do that. With the

Re: Struct that destroys its original handle on copy-by-value

2015-07-29 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 26 July 2015 at 12:16:30 UTC, Joseph Rushton Wakeling wrote: My aim by contrast is to _allow_ that kind of use, but render the original handle empty when it's done. I don't think D offers any way to do that. With the disabled postblit, you can force people into a method you write

Re: Struct that destroys its original handle on copy-by-value

2015-07-29 Thread Joseph Rushton Wakeling via Digitalmars-d-learn
On Sunday, 26 July 2015 at 11:30:16 UTC, Joseph Rushton Wakeling wrote: Hello all, A design question that came up during the hackathon held during the last Berlin D Meetup. [...] Ping on the above -- nobody has any insight...?

Re: Struct that destroys its original handle on copy-by-value

2015-07-26 Thread Martijn Pot via Digitalmars-d-learn
On Sunday, 26 July 2015 at 11:30:16 UTC, Joseph Rushton Wakeling wrote: Hello all, A design question that came up during the hackathon held during the last Berlin D Meetup. [...] Sounds like unique_ptr (so UniqueRange might be a nice name). Maybe you can get some ideas from that.

Struct that destroys its original handle on copy-by-value

2015-07-26 Thread Joseph Rushton Wakeling via Digitalmars-d-learn
Hello all, A design question that came up during the hackathon held during the last Berlin D Meetup. I was trying to come up with a range that can be copied by value, but when this is done, destroys the original handle. The idea would be behaviour something like this: auto

Re: Struct that destroys its original handle on copy-by-value

2015-07-26 Thread Joseph Rushton Wakeling via Digitalmars-d-learn
On 26/07/15 13:45, Martijn Pot via Digitalmars-d-learn wrote: Sounds like unique_ptr (so UniqueRange might be a nice name). Maybe you can get some ideas from that. There is already a Unique in std.typecons. However, I'm not sure that it's doing what I require. Example: Unique!Random