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.

Reply via email to