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

Commit

Permalink
Move the position of byKeyValue
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Jul 17, 2015
1 parent e0f2ca6 commit 6321a2b
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions src/object.d
Expand Up @@ -1865,6 +1865,36 @@ auto byValue(T : Value[Key], Value, Key)(T *aa) pure nothrow @nogc
return (*aa).byValue();
}

auto byKeyValue(T : Value[Key], Value, Key)(T aa) pure nothrow @nogc @property
{
static struct Result
{
AARange r;

pure nothrow @nogc:
@property bool empty() { return _aaRangeEmpty(r); }
@property auto front() @trusted
{
static struct Pair
{
// We save the pointers here so that the Pair we return
// won't mutate when Result.popFront is called afterwards.
private Key* keyp;
private Value* valp;

@property ref inout(Key) key() inout { return *keyp; }
@property ref inout(Value) value() inout { return *valp; }
}
return Pair(cast(Key*)_aaRangeFrontKey(r),
cast(Value*)_aaRangeFrontValue(r));
}
void popFront() { _aaRangePopFront(r); }
@property Result save() { return this; }
}

return Result(_aaRange(cast(void*)aa));
}

Key[] keys(T : Value[Key], Value, Key)(T aa) @property
{
auto a = cast(void[])_aaKeys(cast(inout(void)*)aa, Key.sizeof, typeid(Key[]));
Expand Down Expand Up @@ -1918,36 +1948,6 @@ unittest
assert(T.count == 2);
}

auto byKeyValue(T : Value[Key], Value, Key)(T aa) pure nothrow @nogc @property
{
static struct Result
{
AARange r;

pure nothrow @nogc:
@property bool empty() { return _aaRangeEmpty(r); }
@property auto front() @trusted
{
static struct Pair
{
// We save the pointers here so that the Pair we return
// won't mutate when Result.popFront is called afterwards.
private Key* keyp;
private Value* valp;

@property ref inout(Key) key() inout { return *keyp; }
@property ref inout(Value) value() inout { return *valp; }
}
return Pair(cast(Key*)_aaRangeFrontKey(r),
cast(Value*)_aaRangeFrontValue(r));
}
void popFront() { _aaRangePopFront(r); }
@property Result save() { return this; }
}

return Result(_aaRange(cast(void*)aa));
}

inout(V) get(K, V)(inout(V[K]) aa, K key, lazy inout(V) defaultValue)
{
auto p = key in aa;
Expand Down

0 comments on commit 6321a2b

Please sign in to comment.