summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Wey2011-01-29 23:16:07 +0100
committerMike Wey2011-01-29 23:16:07 +0100
commit7e793c9571f88ba422850e780e7cafff2cd3f1b2 (patch)
tree6a37d07b76bc8b6f0e0145bc3100734f200fb4cb
parent593d9e0b18a4d935ab01024f4a0150825a3630e8 (diff)
Simplyfy the Refcounted template a little
-rw-r--r--dmagick/Image.d7
-rw-r--r--dmagick/Utils.d6
2 files changed, 4 insertions, 9 deletions
diff --git a/dmagick/Image.d b/dmagick/Image.d
index 2b66aaa..3df6e00 100644
--- a/dmagick/Image.d
+++ b/dmagick/Image.d
@@ -19,12 +19,7 @@ import dmagick.c.image;
class Image
{
alias dmagick.c.image.Image MagickCoreImage;
- //We can't reduce the function literal further, becase that generates an error.
- alias RefCounted!( function(MagickCoreImage* img)
- {
- img = DestroyImage(img);
- }, MagickCoreImage ) ImageRef;
-
+ alias RefCounted!( DestroyImage, MagickCoreImage ) ImageRef;
ImageRef imageRef;
Options options;
diff --git a/dmagick/Utils.d b/dmagick/Utils.d
index 2550c40..e8cef21 100644
--- a/dmagick/Utils.d
+++ b/dmagick/Utils.d
@@ -66,7 +66,7 @@ real degreesToRadians(real deg)
}
struct RefCounted(alias pred, T)
- if ( !is(T == class) && is(typeof(pred(cast(T*)null)) == void) )
+ if ( !is(T == class) && is(typeof(pred(cast(T*)null)) == T*) )
{
T* payload;
@@ -96,7 +96,7 @@ struct RefCounted(alias pred, T)
(*refcount)--;
if ( *refcount == 0 )
- pred(payload);
+ payload = pred(payload);
}
@property size_t refCount()
@@ -110,7 +110,7 @@ unittest
int x = 10;
int y = 20;
- alias RefCounted!( (void* t){ x = 20; }, int ) IntRef;
+ alias RefCounted!( (int* t){ x = 20; return t; }, int ) IntRef;
auto a = IntRef(&x);
assert( a.refCount == 1 );