disposable 1.0.1

A disposing mechanism like IDisposable in C# and an using guard like the using syntax in C#


To use this package, put the following dependency into your project's dependencies section:

dub.json
dub.sdl

Disposable

A disposing mechanism like IDisposable in C#, and using guard like using statement in C#.

Examples

class DisposableInt : Disposable
{
    private int v;
    private bool disposed;

    this(int t) { this.v = t; }
    /// Destructor must call `dispose` with `disposing = false` in its body
    ~this() { this.dispose(false); }

    override nothrow void dispose() { this.dispose(true); }
    nothrow void dispose(bool disposing)
    {
        assert(this.disposed != disposing);
        this.disposed = true;
    }
}

mixin(using!q{ auto p = new DisposableInt(2) });
static assert(is(typeof(p) == DisposableInt));
mixin(using!q{ DisposableInt di = new DisposableInt(2) });
mixin(using!q{ d2 = new DisposableInt(2) });
static assert(is(typeof(di) == DisposableInt));
static assert(is(typeof(d2) == DisposableInt));

Provided classes/methods

  • interface Disposable
    • A Disposable interface that can be disposed by calling dispose method
    • nothrow void dispose()
      • Disposes unmanaged objects(OpenGL Objects, Win32 Objects...) in the object.

  • string using(string)() {...}
    • The using statement emulation.
    • Passes a variable declaration statement as string(using q{...} is preferred) to declare a variable and to insert a code such as scope(exit) {varname}.dispose();
    • If you want a type which is inferred, you can omit auto.
Authors:
S.Percentage
Dependencies:
none
Versions:
1.0.1 2017-Sep-26
1.0.0 2017-Sep-24
~master 2017-Sep-26
Show all 3 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 3 downloads this month

  • 5 downloads total