Replace Option with Nullable

This commit is contained in:
2021-03-27 10:28:49 +01:00
parent 0fcc83d00e
commit 92284c8541
6 changed files with 48 additions and 438 deletions

View File

@ -21,11 +21,11 @@
module tanya.algorithm.iteration;
import std.algorithm.comparison;
import std.typecons;
import tanya.memory.lifetime;
import tanya.meta.trait;
import tanya.meta.transform;
import tanya.range;
import tanya.typecons;
// These predicates are used to help preserve `const` and `inout` for
// ranges built on other ranges.
@ -570,7 +570,7 @@ if (isBidirectionalRange!Range)
private struct SingletonByValue(E)
{
private Option!E element;
private Nullable!E element;
@disable this();
@ -581,9 +581,9 @@ private struct SingletonByValue(E)
}
private this(U)(ref U element)
if (is(Unqual!U == Option!(Unqual!E)) || is(Unqual!U == Option!(const E)))
if (is(Unqual!U == Nullable!(Unqual!E)) || is(Unqual!U == Nullable!(const E)))
{
if (!element.isNothing)
if (!element.isNull)
{
this.element = element.get;
}
@ -600,19 +600,19 @@ private struct SingletonByValue(E)
void popFront()
in (!empty)
{
this.element.reset();
this.element.nullify();
}
alias popBack = popFront;
@property bool empty() const
{
return this.element.isNothing;
return this.element.isNull;
}
@property size_t length() const
{
return !this.element.isNothing;
return !this.element.isNull;
}
auto save()
@ -620,11 +620,6 @@ private struct SingletonByValue(E)
return SingletonByValue!E(this.element);
}
auto save() const
{
return SingletonByValue!(const E)(this.element);
}
ref inout(E) opIndex(size_t i) inout
in (!empty)
in (i == 0)
@ -675,11 +670,6 @@ private struct SingletonByRef(E)
return typeof(this)(*this.element);
}
auto save() const return
{
return SingletonByRef!(const E)(*this.element);
}
ref inout(E) opIndex(size_t i) inout return
in (!empty)
in (i == 0)