digitalmars.D - struct destructors
- Janice Caron (14/14) Mar 07 2008 I see that structs now have destructors, according to the changelog for ...
- John C (4/24) Mar 07 2008 We don't, as yet. Walter's announcement says: "Yes, you read that right,...
- Janice Caron (15/17) Mar 07 2008 Gosh. But isn't the opAssign example wrong? It says:
- John C (2/20) Mar 07 2008 In the example, 'a' refers to an int. So no.
- Janice Caron (3/4) Mar 07 2008 So it does. I was confusing it with the previous example. Thanks for
- Bill Baxter (8/13) Mar 07 2008 But this looks wrong
- Robert Fraser (2/20) Mar 07 2008 So it should.
I see that structs now have destructors, according to the changelog for D2.012. How does that work? I wasn't even aware that they had /con/structors! I've still been using static opCall for that (and hating doing so, because it's such a kludge). So do we get to use this() and ~this() now? Can we use new and delete with structs? Can we use delete with structs on the stack? Also, what about assignment and copy construction? ...and repeatedly returning a struct from a function (as in, e() calls f(), which calls g(), which calls h(); h returns a struct, which returns it to g, which returns it to f, which returns it to e). Will those nested returns invoke a chain of copy constructors and destructors? Or will it be optimised to just a single copy? That's a lot of questions for one post. Sorry about that. Oh - one more. What's a postblit?
Mar 07 2008
Janice Caron wrote:I see that structs now have destructors, according to the changelog for D2.012. How does that work? I wasn't even aware that they had /con/structors! I've still been using static opCall for that (and hating doing so, because it's such a kludge).We don't, as yet. Walter's announcement says: "Yes, you read that right, struct destructors but no struct constructors yet."So do we get to use this() and ~this() now? Can we use new and delete with structs? Can we use delete with structs on the stack? Also, what about assignment and copy construction? ...and repeatedly returning a struct from a function (as in, e() calls f(), which calls g(), which calls h(); h returns a struct, which returns it to g, which returns it to f, which returns it to e). Will those nested returns invoke a chain of copy constructors and destructors? Or will it be optimised to just a single copy? That's a lot of questions for one post. Sorry about that. Oh - one more. What's a postblit?http://www.digitalmars.com/d/2.0/struct.html
Mar 07 2008
On 07/03/2008, John C <johnch_atms hotmail.com> wrote:> Oh - one more. What's a postblit? http://www.digitalmars.com/d/2.0/struct.htmlGosh. But isn't the opAssign example wrong? It says: S* opAssign(ref const S s) { a = s.a; return this; } but I rather think it should be S* opAssign(ref const S s) { a[] = s.a[]; return this; } since you don't /want/ this to share the same workspace as s. Am I missing something, or is this a documentation bug?
Mar 07 2008
Janice Caron wrote:Gosh. But isn't the opAssign example wrong? It says: S* opAssign(ref const S s) { a = s.a; return this; } but I rather think it should be S* opAssign(ref const S s) { a[] = s.a[]; return this; } since you don't /want/ this to share the same workspace as s. Am I missing something, or is this a documentation bug?In the example, 'a' refers to an int. So no.
Mar 07 2008
On 07/03/2008, John C <johnch_atms hotmail.com> wrote:In the example, 'a' refers to an int. So no.So it does. I was confusing it with the previous example. Thanks for the correction.
Mar 07 2008
Janice Caron wrote:On 07/03/2008, John C <johnch_atms hotmail.com> wrote:But this looks wrong """ Struct assignment t=s is defined to be semantically equivalent to: t = S.opAssign(s); """ Shouldn't that be t.opAssign(s)? --bbIn the example, 'a' refers to an int. So no.So it does. I was confusing it with the previous example. Thanks for the correction.
Mar 07 2008
Bill Baxter wrote:Janice Caron wrote:So it should.On 07/03/2008, John C <johnch_atms hotmail.com> wrote:But this looks wrong """ Struct assignment t=s is defined to be semantically equivalent to: t = S.opAssign(s); """ Shouldn't that be t.opAssign(s)? --bbIn the example, 'a' refers to an int. So no.So it does. I was confusing it with the previous example. Thanks for the correction.
Mar 07 2008