Skip to content

Commit

Permalink
ae.utils.meta.rcclass: Add a bit of const-correctness
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberShadow committed Jan 8, 2024
1 parent 3b89454 commit c40f79b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions utils/meta/rcclass.d
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if (is(C == class))

private RCClassStore!C* _rcClassStore;

@property C _rcClassGet()
@property inout(C) _rcClassGet() inout
{
return cast(C)_rcClassStore.data.ptr;
}
Expand All @@ -53,6 +53,7 @@ if (is(C == class))
ref typeof(this) opAssign(T)(T value)
if (is(T == typeof(null)))
{
assert(value is null);
_rcClassDestroy();
_rcClassStore = null;
return this;
Expand All @@ -68,18 +69,18 @@ if (is(C == class))
return this;
} ///

T opCast(T)()
inout(T) opCast(T)() inout
if (is(T == RCClass!U, U) && is(typeof({C c; U u = cast(U)c;})))
{
static if (!is(T == RCClass!U, U)) // Destructure into U
assert(false);
T result;
inout(T) result;
// Check if dynamic cast is valid
if (!cast(U)this._rcClassGet())
return result;
result._rcClassStore = cast(typeof(result._rcClassStore))_rcClassStore;
cast()result._rcClassStore = cast(typeof(result._rcClassStore))_rcClassStore;
if (_rcClassStore)
_rcClassStore.refCount++;
(cast()_rcClassStore.refCount)++;
return result;
} ///

Expand Down

0 comments on commit c40f79b

Please sign in to comment.