Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Add const values/keys in AssociativeArray(Key, Type) wrapper.
Browse files Browse the repository at this point in the history
  • Loading branch information
denis-sh committed Jun 21, 2013
1 parent 178dbe7 commit 3bf1cb0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
24 changes: 20 additions & 4 deletions src/object.di
Expand Up @@ -484,18 +484,34 @@ public:
return *cast(Value[Key]*)(&p);
}

Value[] values() @property
// Note: can't make `values` and `keys` inout as it is used
// e.g. in Phobos like `ReturnType!(aa.keys)` instead of `typeof(aa.keys)`
// which will result in `inout` propagation.

inout(Value)[] inout_values() inout @property
{
auto a = _aaValues(p, Key.sizeof, Value.sizeof);
return *cast(Value[]*) &a;
return *cast(inout Value[]*) &a;
}

Key[] keys() @property
inout(Key)[] inout_keys() inout @property
{
auto a = _aaKeys(p, Key.sizeof);
return *cast(Key[]*) &a;
return *cast(inout Key[]*) &a;
}

Value[] values() @property
{ return inout_values; }

Key[] keys() @property
{ return inout_keys; }

const(Value)[] values() const @property
{ return inout_values; }

const(Key)[] keys() const @property
{ return inout_keys; }

int opApply(scope int delegate(ref Key, ref Value) dg)
{
return _aaApply2(p, Key.sizeof, cast(_dg2_t)dg);
Expand Down
24 changes: 20 additions & 4 deletions src/object_.d
Expand Up @@ -2170,18 +2170,34 @@ public:
return *cast(Value[Key]*)(&p);
}

Value[] values() @property
// Note: can't make `values` and `keys` inout as it is used
// e.g. in Phobos like `ReturnType!(aa.keys)` instead of `typeof(aa.keys)`
// which will result in `inout` propagation.

inout(Value)[] inout_values() inout @property
{
auto a = _aaValues(p, Key.sizeof, Value.sizeof);
return *cast(Value[]*) &a;
return *cast(inout Value[]*) &a;
}

Key[] keys() @property
inout(Key)[] inout_keys() inout @property
{
auto a = _aaKeys(p, Key.sizeof);
return *cast(Key[]*) &a;
return *cast(inout Key[]*) &a;
}

Value[] values() @property
{ return inout_values; }

Key[] keys() @property
{ return inout_keys; }

const(Value)[] values() const @property
{ return inout_values; }

const(Key)[] keys() const @property
{ return inout_keys; }

int opApply(scope int delegate(ref Key, ref Value) dg)
{
return _aaApply2(p, Key.sizeof, cast(_dg2_t)dg);
Expand Down

0 comments on commit 3bf1cb0

Please sign in to comment.