disposable 1.0.0
A disposing mechanism like IDisposable in C# and an using guard like the using syntax in C#
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
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 callingdispose
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 insert a code such asscope(exit) {varname}.dispose();
- If you want a type which is inferred, you can omit
auto
.
- Registered by S.Percentage
- 1.0.0 released 7 years ago
- Pctg-x8/disposable
- MIT
- Copyright 2017 S.Percentage
- Authors:
- Dependencies:
- none
- Versions:
-
1.0.1 2017-Sep-26 1.0.0 2017-Sep-24 ~master 2017-Sep-26 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
0 downloads this month
-
16 downloads total
-
- Score:
- 0.7
- Short URL:
- disposable.dub.pm