Seeing as the scope keyword is (being?) deprecated, how would you handle something like this:

class Test
{
private:
  string str;

  this(string str)
  {
    this.str = str;
  }

public:
  static Test createFromString(string str)
  {
    return new Test();
  }

}

void main()
{

// at the end of the scope, test is destroyed and memory is freed
  scope Test test = Test.createFromString("test");

}

The only solution I can think of is using scope(exit) something like this:
scope(exit) { destroy(test); GC.free(cast(void*)test); }

which seems clumsy. Any other, better solutions?

Reply via email to