Skip to content

Commit

Permalink
add Contract to Vector and StringImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
dushibaiyu committed Jun 27, 2017
1 parent a537fe6 commit 14b7fae
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/yu/container/cirularqueue.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import yu.container.common;
Allocator = which type Allocator will used
*/

@trusted struct CirularQueue(T, Allocator = GCAllocator, bool autoExten = false, bool addInGC = true) {
@trusted struct CirularQueue(T, Allocator = GCAllocator, bool autoExten = false, bool addInGC = true) if(is(T == Unqual!T)) {
enum TSize = T.sizeof;
enum addToGC = addInGC && hasIndirections!T && !is(Unqual!Allocator == GCAllocator);
static if (hasIndirections!T)
Expand Down
3 changes: 2 additions & 1 deletion src/yu/container/common.d
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module yu.container.common;

import core.atomic;
import std.traits : Unqual;
import std.experimental.allocator;


Expand Down Expand Up @@ -78,7 +79,7 @@ mixin template Refcount()
}

/// Array Cow Data
struct ArrayCOWData(T, Allocator,bool inGC = false)
struct ArrayCOWData(T, Allocator,bool inGC = false) if(is(T == Unqual!T))
{
import core.memory : GC;
import std.exception : enforce;
Expand Down
3 changes: 2 additions & 1 deletion src/yu/container/string.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ alias WString = IWString!(Mallocator);
alias DString = IDString!(Mallocator);

// The Cow String
@trusted struct StringImpl(Char, Allocator)
@trusted struct StringImpl(Char, Allocator)
if(is(Char == Unqual!Char) && isSomeChar!Char)
{
alias Data = ArrayCOWData!(Char, Allocator);
static if (StaticAlloc!Allocator)
Expand Down
4 changes: 3 additions & 1 deletion src/yu/container/vector.d
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import yu.array;
2. 不允许copy: 对于引用类型 和 指针
*/

@trusted struct Vector(T, Allocator = Mallocator, bool addInGC = true) //if(!(hasIndirections!T))
@trusted struct Vector(T, Allocator = Mallocator, bool addInGC = true) if(is(T == Unqual!T))
{
enum addToGC = addInGC && hasIndirections!T && !is(Unqual!Allocator == GCAllocator);
enum needDestroy = (is(T == struct) && hasElaborateDestructor!T);
Expand Down Expand Up @@ -462,4 +462,6 @@ unittest {
1541515, 15415, 1545, 1545, 1545, 1545, 15454, 0, 54154]);

vec22 ~= [0, 1, 2, 1, 212];

//Vector!(shared int) vec2;
}

0 comments on commit 14b7fae

Please sign in to comment.