Re: use of struct vs class

2020-03-07 Thread mark via Digitalmars-d-learn
Steve, thank you once again. Now it compiles & runs! I now create my tree like this: auto debs = new RedBlackTree!(Deb, (a, b) => a.name < b.name); (I feel that the rbtree docs are inadequate regarding creating new empty trees, so have submitted a bug report: https://issues.dlang.org/show_bug

Re: use of struct vs class

2020-03-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/7/20 8:22 AM, mark wrote: 0x55701ef0 in _D3std9container6rbtree__T12RedBlackTreeTAyaVQea5_61203c2062Vbi0ZQBn5emptyMFNaNbNdNiNfZb (this=0x0)     at /home/mark/opt/ldc2-1.20.0-linux-x86_64/bin/../import/std/container/rbtree.d:967 967    return _end.left is null; (gdb) bt

Re: use of struct vs class

2020-03-07 Thread drug via Digitalmars-d-learn
07.03.2020 15:58, Steven Schveighoffer пишет: Hm... I'd say: 1. Don't use a pointer for the element. Just use the struct directly. Using a pointer is bad because it's now going to compare pointers, and not the element data. Not only that, but RBNodes are stored as heap-allocated structs, so

Re: use of struct vs class

2020-03-07 Thread mark via Digitalmars-d-learn
I've now gone back to using structs direct without pointers but I'm still doing something wrong. struct Deb { string name; ... RedBlackTree!string tags; bool valid() { return !(name.empty || description.empty); } void clear() { name = ""; ...; tags.clear; } } RedBlackTree!

Re: use of struct vs class

2020-03-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/7/20 5:58 AM, mark wrote: change #1:     if (line.empty) {     if (deb != null && deb.valid)     debs.insert(deb);     else // report incomplete     deb = null;     continue;  

Re: use of struct vs class

2020-03-07 Thread drug via Digitalmars-d-learn
07.03.2020 13:58, mark пишет: change #1:     if (line.empty) {     if (deb != null && deb.valid)     debs.insert(deb);     else // report incomplete     deb = null;     continue;   

Re: use of struct vs class

2020-03-07 Thread mark via Digitalmars-d-learn
change #1: if (line.empty) { if (deb != null && deb.valid) debs.insert(deb); else // report incomplete deb = null; continue; } if (deb == null)

Re: use of struct vs class

2020-03-07 Thread mark via Digitalmars-d-learn
Instead of deb.clear I'm now doing deb = null;

Re: use of struct vs class

2020-03-07 Thread mark via Digitalmars-d-learn
On Saturday, 7 March 2020 at 10:30:06 UTC, drug wrote: 07.03.2020 13:20, mark пишет: I have this struct (with details omitted [ snip ] Should Deb be a class rather than a struct? Do you consider using pointers in AA: ``` Deb*[string] debForName; ``` I've done some changes including using Deb

Re: use of struct vs class

2020-03-07 Thread drug via Digitalmars-d-learn
07.03.2020 13:20, mark пишет: I have this struct (with details omitted [ snip ] Should Deb be a class rather than a struct? Do you consider using pointers in AA: ``` Deb*[string] debForName; ```

use of struct vs class

2020-03-07 Thread mark via Digitalmars-d-learn
I have this struct (with details omitted ... for brevity): struct Deb { string name; ... RedBlackTree!string tags; void clear() { name = ""; ...; tags.clear; } bool valid() { return !(name.empty || description.empty); } } I plan to store >65K of these (with potential for gr

Re: Struct vs. Class

2015-06-26 Thread Chris via Digitalmars-d-learn
On Friday, 26 June 2015 at 11:28:38 UTC, Daniel Kozák wrote: On Fri, 26 Jun 2015 11:11:15 + Chris via Digitalmars-d-learn wrote: I have still some classes lying around in my code. As threading is becoming more and more of an issue, classes and OOP in general turn out to be a nuisance.

Re: Struct vs. Class

2015-06-26 Thread Daniel Kozák via Digitalmars-d-learn
On Fri, 26 Jun 2015 11:11:15 + Chris via Digitalmars-d-learn wrote: > I have still some classes lying around in my code. As threading > is becoming more and more of an issue, classes and OOP in general > turn out to be a nuisance. It's not so hard to turn the classes > into structs, a lot

Re: Struct vs. Class

2015-06-26 Thread Daniel Kozák via Digitalmars-d-learn
On Fri, 26 Jun 2015 11:11:15 + Chris via Digitalmars-d-learn wrote: > I have still some classes lying around in my code. As threading > is becoming more and more of an issue, classes and OOP in general > turn out to be a nuisance. It's not so hard to turn the classes > into structs, a lot

Struct vs. Class

2015-06-26 Thread Chris via Digitalmars-d-learn
I have still some classes lying around in my code. As threading is becoming more and more of an issue, classes and OOP in general turn out to be a nuisance. It's not so hard to turn the classes into structs, a lot of classes are in fact singletons (yes, I've been kinda fading out classes for a

Re: struct vs class for a simple token in my d lexer

2012-05-15 Thread Artur Skawina
On 05/14/12 17:10, Roman D. Boiko wrote: > (Subj.) I'm in doubt which to choose for my case, but this is a generic > question. > > http://forum.dlang.org/post/odcrgqxoldrktdtar...@forum.dlang.org > > Cross-posting here. I would appreciate any feedback. (Whether to reply in > this or that thread

Re: struct vs class for a simple token in my d lexer

2012-05-15 Thread Roman D. Boiko
On Tuesday, 15 May 2012 at 06:17:31 UTC, Era Scarecrow wrote: If you don't mind doing some lite informational reading, read up on 'lex and yacc'. ISBN: 1-56592-000-7; Hope I got that right. I'm not telling you to use C (or the other tools mind you), but it does go into handling tokens of multi

Re: struct vs class for a simple token in my d lexer

2012-05-14 Thread Roman D. Boiko
On Tuesday, 15 May 2012 at 06:17:31 UTC, Era Scarecrow wrote: On Monday, 14 May 2012 at 18:00:42 UTC, Roman D. Boiko wrote: On Monday, 14 May 2012 at 17:37:02 UTC, Dmitry Olshansky wrote: But hopefully you get the idea. See something simillar in std.regex, though pointer in there also serves fo

Re: struct vs class for a simple token in my d lexer

2012-05-14 Thread Era Scarecrow
On Monday, 14 May 2012 at 18:00:42 UTC, Roman D. Boiko wrote: On Monday, 14 May 2012 at 17:37:02 UTC, Dmitry Olshansky wrote: But hopefully you get the idea. See something simillar in std.regex, though pointer in there also serves for intrusive linked-list. Thanks, most likely I'll go your w

Re: struct vs class for a simple token in my d lexer

2012-05-14 Thread Era Scarecrow
On Monday, 14 May 2012 at 18:00:42 UTC, Roman D. Boiko wrote: On Monday, 14 May 2012 at 17:37:02 UTC, Dmitry Olshansky wrote: But hopefully you get the idea. See something simillar in std.regex, though pointer in there also serves for intrusive linked-list. Thanks, most likely I'll go your w

Re: struct vs class for a simple token in my d lexer

2012-05-14 Thread Roman D. Boiko
On Monday, 14 May 2012 at 17:37:02 UTC, Dmitry Olshansky wrote: But hopefully you get the idea. See something simillar in std.regex, though pointer in there also serves for intrusive linked-list. Thanks, most likely I'll go your way.

Re: struct vs class for a simple token in my d lexer

2012-05-14 Thread Dmitry Olshansky
On 14.05.2012 21:33, Dmitry Olshansky wrote: On 14.05.2012 21:20, Roman D. Boiko wrote: On Monday, 14 May 2012 at 16:41:39 UTC, Jonathan M Davis wrote: On Monday, May 14, 2012 17:10:23 Roman D. Boiko wrote: (Subj.) I'm in doubt which to choose for my case, but this is a generic question. http

Re: struct vs class for a simple token in my d lexer

2012-05-14 Thread Dmitry Olshansky
On 14.05.2012 21:20, Roman D. Boiko wrote: On Monday, 14 May 2012 at 16:41:39 UTC, Jonathan M Davis wrote: On Monday, May 14, 2012 17:10:23 Roman D. Boiko wrote: (Subj.) I'm in doubt which to choose for my case, but this is a generic question. http://forum.dlang.org/post/odcrgqxoldrktdtar...@f

Re: struct vs class for a simple token in my d lexer

2012-05-14 Thread Roman D. Boiko
On Monday, 14 May 2012 at 17:05:17 UTC, Dmitry Olshansky wrote: On 14.05.2012 19:10, Roman D. Boiko wrote: (Subj.) I'm in doubt which to choose for my case, but this is a generic question. http://forum.dlang.org/post/odcrgqxoldrktdtar...@forum.dlang.org Cross-posting here. I would appreciate

Re: struct vs class for a simple token in my d lexer

2012-05-14 Thread Dmitry Olshansky
On 14.05.2012 21:16, Tobias Pankrath wrote: struct Token{ uint col, line; uint flags;//indicated info about token, serves as both type tag and flag set; //indicates proper type once token was cooked (like "31.415926" -> 3.145926e1) i.e. values are calculated union { string chars; float f_val; d

Re: struct vs class for a simple token in my d lexer

2012-05-14 Thread Roman D. Boiko
On Monday, 14 May 2012 at 16:41:39 UTC, Jonathan M Davis wrote: On Monday, May 14, 2012 17:10:23 Roman D. Boiko wrote: (Subj.) I'm in doubt which to choose for my case, but this is a generic question. http://forum.dlang.org/post/odcrgqxoldrktdtar...@forum.dlang.org Cross-posting here. I would

Re: struct vs class for a simple token in my d lexer

2012-05-14 Thread Tobias Pankrath
struct Token{ uint col, line; uint flags;//indicated info about token, serves as both type tag and flag set; //indicates proper type once token was cooked (like "31.415926" -> 3.145926e1) i.e. values are calculated union { string chars; float f_val;

Re: struct vs class for a simple token in my d lexer

2012-05-14 Thread Dmitry Olshansky
On 14.05.2012 19:10, Roman D. Boiko wrote: (Subj.) I'm in doubt which to choose for my case, but this is a generic question. http://forum.dlang.org/post/odcrgqxoldrktdtar...@forum.dlang.org Cross-posting here. I would appreciate any feedback. (Whether to reply in this or that thread is up to yo

Re: struct vs class for a simple token in my d lexer

2012-05-14 Thread Roman D. Boiko
On Monday, 14 May 2012 at 15:53:34 UTC, Tobias Pankrath wrote: Quoting your post in another thread: On Monday, 14 May 2012 at 15:10:25 UTC, Roman D. Boiko wrote: Making it a class would give several benefits: * allow not to worry about allocating a big array of tokens. E.g., on 64-bit OS the

Re: struct vs class for a simple token in my d lexer

2012-05-14 Thread Jonathan M Davis
On Monday, May 14, 2012 17:10:23 Roman D. Boiko wrote: > (Subj.) I'm in doubt which to choose for my case, but this is a > generic question. > > http://forum.dlang.org/post/odcrgqxoldrktdtar...@forum.dlang.org > > Cross-posting here. I would appreciate any feedback. (Whether to > reply in this or

Re: struct vs class for a simple token in my d lexer

2012-05-14 Thread Roman D. Boiko
On Monday, 14 May 2012 at 15:44:54 UTC, Tobias Pankrath wrote: On Monday, 14 May 2012 at 15:10:25 UTC, Roman D. Boiko wrote: (Subj.) I'm in doubt which to choose for my case, but this is a generic question. http://forum.dlang.org/post/odcrgqxoldrktdtar...@forum.dlang.org Cross-posting here. I

Re: struct vs class for a simple token in my d lexer

2012-05-14 Thread Tobias Pankrath
Quoting your post in another thread: On Monday, 14 May 2012 at 15:10:25 UTC, Roman D. Boiko wrote: Making it a class would give several benefits: * allow not to worry about allocating a big array of tokens. E.g., on 64-bit OS the largest module in Phobos (IIRC, the std.datetime) consumes 13.

Re: struct vs class for a simple token in my d lexer

2012-05-14 Thread Tobias Pankrath
On Monday, 14 May 2012 at 15:10:25 UTC, Roman D. Boiko wrote: (Subj.) I'm in doubt which to choose for my case, but this is a generic question. http://forum.dlang.org/post/odcrgqxoldrktdtar...@forum.dlang.org Cross-posting here. I would appreciate any feedback. (Whether to reply in this or th

struct vs class for a simple token in my d lexer

2012-05-14 Thread Roman D. Boiko
(Subj.) I'm in doubt which to choose for my case, but this is a generic question. http://forum.dlang.org/post/odcrgqxoldrktdtar...@forum.dlang.org Cross-posting here. I would appreciate any feedback. (Whether to reply in this or that thread is up to you.) Thanks

Re: struct vs class

2010-11-14 Thread Lutger Blijdestijn
spir wrote: > On Sun, 14 Nov 2010 12:02:35 + > div0 wrote: > >> > Both of these points may conflict with semantic considerations above: >> > we may want to use structs for fast creation, but if ever they mean >> > "things", we must think at referencing them manually and/or using >> > ref

Re: struct vs class

2010-11-14 Thread Jonathan M Davis
On Sunday 14 November 2010 04:14:29 spir wrote: > On Sun, 14 Nov 2010 03:32:18 -0800 > > Jonathan M Davis wrote: > > On Sunday 14 November 2010 03:08:49 spir wrote: > > > Hello, > > > > > > > > > There seems to be 2 main differences between structs & classes: > > > 1. structs instances are dire

Re: struct vs class

2010-11-14 Thread spir
On Sun, 14 Nov 2010 12:02:35 + div0 wrote: > > Both of these points may conflict with semantic considerations above: > > we may want to use structs for fast creation, but if ever they mean > > "things", we must think at referencing them manually and/or using > > ref parameters. We may want

Re: struct vs class

2010-11-14 Thread spir
On Sun, 14 Nov 2010 03:32:18 -0800 Jonathan M Davis wrote: > On Sunday 14 November 2010 03:08:49 spir wrote: > > Hello, > > > > > > There seems to be 2 main differences between structs & classes: > > 1. structs instances are direct values, implement value semantics; while > > class instances ar

Re: struct vs class

2010-11-14 Thread div0
On 14/11/2010 11:08, spir wrote: Hello, There seems to be 2 main differences between structs& classes: 1. structs instances are direct values, implement value semantics; > while class instances are referenced (actually "pointed") 2. classes can be subtyped/subclassed in a simple way; structs

Re: struct vs class

2010-11-14 Thread bearophile
spir: > a value makes no sense by itself, it is bound to what it describes an aspect > of; referencing a value is meaningless, only copy makes no sense. For > instance, the position & color of a visual form should be values. Structs may have a meaning by themselves, all kind of member functions

Re: struct vs class

2010-11-14 Thread Jonathan M Davis
On Sunday 14 November 2010 03:08:49 spir wrote: > Hello, > > > There seems to be 2 main differences between structs & classes: > 1. structs instances are direct values, implement value semantics; while > class instances are referenced (actually "pointed") 2. classes can be > subtyped/subclassed i

struct vs class

2010-11-14 Thread spir
Hello, There seems to be 2 main differences between structs & classes: 1. structs instances are direct values, implement value semantics; while class instances are referenced (actually "pointed") 2. classes can be subtyped/subclassed in a simple way; structs cannot be really subtyped -- but the