Design with appender: good or bad?

John Colvin john.loughran.colvin at gmail.com
Thu Apr 10 03:00:15 PDT 2014


On Thursday, 10 April 2014 at 09:47:35 UTC, Chris wrote:
> Are there any drawbacks with this design, i.e. using buf.put() 
> here
> (instead of a less efficient items ~= item;)?
>
> struct MyStruct {
>   Appender!(string[]) buf;
>   string name;
>
>   this(string name) {
>     this.name = name;
>     buf = appender!(string[]);
>   }
>
>   public addItem(string item) {
>     buf.put(item);
>   }
>
>   @property string[] items() {
>     return buf.data;
>   }
> }

Appender supports ~ and ~=, so you can have your cake and eat it.


More information about the Digitalmars-d-learn mailing list