This commit is contained in:
Eugen Wissner 2017-07-06 08:35:16 +02:00
parent 9429e7bb14
commit b79657f0d2
2 changed files with 36 additions and 24 deletions

View File

@ -130,7 +130,7 @@ struct Range(A)
return typeof(return)(*this.container, this.begin, this.end); return typeof(return)(*this.container, this.begin, this.end);
} }
Range!(const A) opIndex() const A.ConstRange opIndex() const
{ {
return typeof(return)(*this.container, this.begin, this.end); return typeof(return)(*this.container, this.begin, this.end);
} }
@ -146,7 +146,7 @@ struct Range(A)
return typeof(return)(*this.container, this.begin + i, this.begin + j); return typeof(return)(*this.container, this.begin + i, this.begin + j);
} }
Range!(const A) opSlice(const size_t i, const size_t j) const @trusted A.ConstRange opSlice(const size_t i, const size_t j) const @trusted
in in
{ {
assert(i <= j); assert(i <= j);

View File

@ -24,11 +24,12 @@ import tanya.memory;
* Forward range for the $(D_PSYMBOL SList). * Forward range for the $(D_PSYMBOL SList).
* *
* Params: * Params:
* E = Element type. * L = List type.
*/ */
struct SRange(E) struct SRange(L)
{ {
private alias EntryPointer = CopyConstness!(E, SEntry!(Unqual!E)*); private alias EntryPointer = typeof(L.head);
private alias E = typeof(EntryPointer.content);
private EntryPointer* head; private EntryPointer* head;
@ -79,7 +80,7 @@ struct SRange(E)
return typeof(return)(*this.head); return typeof(return)(*this.head);
} }
SRange!(const E) opIndex() const L.ConstRange opIndex() const
{ {
return typeof(return)(*this.head); return typeof(return)(*this.head);
} }
@ -94,10 +95,10 @@ struct SRange(E)
struct SList(T) struct SList(T)
{ {
/// The range types for $(D_PSYMBOL SList). /// The range types for $(D_PSYMBOL SList).
alias Range = SRange!T; alias Range = SRange!SList;
/// Ditto. /// Ditto.
alias ConstRange = SRange!(const T); alias ConstRange = SRange!(const SList);
private alias Entry = SEntry!T; private alias Entry = SEntry!T;
@ -434,7 +435,7 @@ struct SList(T)
version (assert) version (assert)
{ {
private bool checkRangeBelonging(ref SRange!T r) const private bool checkRangeBelonging(ref Range r) const
{ {
const(Entry*)* pos = &this.head; const(Entry*)* pos = &this.head;
for (; pos != r.head && *pos !is null; pos = &(*pos).next) for (; pos != r.head && *pos !is null; pos = &(*pos).next)
@ -456,7 +457,7 @@ struct SList(T)
* *
* Precondition: $(D_PARAM r) is extracted from this list. * Precondition: $(D_PARAM r) is extracted from this list.
*/ */
size_t insertBefore(R)(SRange!T r, R el) size_t insertBefore(R)(Range r, R el)
if (isImplicitlyConvertible!(R, T)) if (isImplicitlyConvertible!(R, T))
in in
{ {
@ -477,7 +478,7 @@ struct SList(T)
} }
/// Ditto. /// Ditto.
size_t insertBefore(R)(SRange!T r, R el) size_t insertBefore(R)(Range r, R el)
if (!isInfinite!R if (!isInfinite!R
&& isInputRange!R && isInputRange!R
&& isImplicitlyConvertible!(ElementType!R, T)) && isImplicitlyConvertible!(ElementType!R, T))
@ -812,7 +813,7 @@ struct SList(T)
} }
next = &(*next).next; next = &(*next).next;
} }
remove(SRange!T(*next)); remove(Range(*next));
return this; return this;
} }
@ -906,15 +907,16 @@ private @nogc @safe unittest
} }
/** /**
* Forward range for the $(D_PSYMBOL SList). * Forward range for the $(D_PSYMBOL DList).
* *
* Params: * Params:
* E = Element type. * L = List type.
*/ */
struct DRange(E) struct DRange(L)
{ {
private alias EntryPointer = CopyConstness!(E, DEntry!(Unqual!E)*); private alias E = typeof(L.head.content);
private alias TailPointer = CopyConstness!(E, DEntry!(Unqual!E))*; private alias EntryPointer = typeof(L.head);
private alias TailPointer = Unqual!EntryPointer;
private EntryPointer* head; private EntryPointer* head;
private TailPointer tail; private TailPointer tail;
@ -987,7 +989,7 @@ struct DRange(E)
return typeof(return)(*this.head, this.tail); return typeof(return)(*this.head, this.tail);
} }
DRange!(const E) opIndex() const L.ConstRange opIndex() const
{ {
return typeof(return)(*this.head, this.tail); return typeof(return)(*this.head, this.tail);
} }
@ -1002,10 +1004,10 @@ struct DRange(E)
struct DList(T) struct DList(T)
{ {
/// The range types for $(D_PSYMBOL DList). /// The range types for $(D_PSYMBOL DList).
alias Range = DRange!T; alias Range = DRange!DList;
/// Ditto. /// Ditto.
alias ConstRange = DRange!(const T); alias ConstRange = DRange!(const DList);
private alias Entry = DEntry!T; private alias Entry = DEntry!T;
@ -1512,7 +1514,7 @@ struct DList(T)
version (assert) version (assert)
{ {
private bool checkRangeBelonging(ref DRange!T r) const private bool checkRangeBelonging(ref Range r) const
{ {
const(Entry*)* pos = &this.head; const(Entry*)* pos = &this.head;
for (; pos != r.head && *pos !is null; pos = &(*pos).next) for (; pos != r.head && *pos !is null; pos = &(*pos).next)
@ -1534,7 +1536,7 @@ struct DList(T)
* *
* Precondition: $(D_PARAM r) is extracted from this list. * Precondition: $(D_PARAM r) is extracted from this list.
*/ */
size_t insertBefore(R)(DRange!T r, R el) size_t insertBefore(R)(Range r, R el)
if (isImplicitlyConvertible!(R, T)) if (isImplicitlyConvertible!(R, T))
in in
{ {
@ -1555,7 +1557,7 @@ struct DList(T)
} }
/// Ditto. /// Ditto.
size_t insertBefore(R)(DRange!T r, R el) size_t insertBefore(R)(Range r, R el)
if (!isInfinite!R if (!isInfinite!R
&& isInputRange!R && isInputRange!R
&& isImplicitlyConvertible!(ElementType!R, T)) && isImplicitlyConvertible!(ElementType!R, T))
@ -1883,7 +1885,7 @@ struct DList(T)
} }
if (that.empty) if (that.empty)
{ {
remove(DRange!T(*next, this.tail)); remove(Range(*next, this.tail));
} }
else else
{ {
@ -1953,3 +1955,13 @@ struct DList(T)
} }
assert(i == 3); assert(i == 3);
} }
// Issue 232: https://issues.caraus.io/issues/232.
private @nogc unittest
{
class A
{
}
static assert(is(SList!(A*)));
static assert(is(DList!(A*)));
}