Skip to content

Commit 8d0164e

Browse files
committed
another fix for small array/ small string
1 parent 3414aad commit 8d0164e

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

source/mir/small_array.d

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ struct SmallArray(T, uint maxLength)
5353
}
5454

5555
/// ditto
56-
this(SmallArray array) nothrow
56+
this(const SmallArray array) nothrow
5757
{
5858
this.opAssign(array);
5959
}
6060

6161
/// ditto
62-
this(uint n)(SmallArray!(T, n) array)
62+
this(uint n)(const SmallArray!(T, n) array)
6363
{
6464
this.opAssign(array);
6565
}
@@ -116,7 +116,7 @@ struct SmallArray(T, uint maxLength)
116116
}
117117

118118
/// ditto
119-
ref typeof(this) opAssign(SmallArray rhs) return nothrow
119+
ref typeof(this) opAssign(const SmallArray rhs) return nothrow
120120
{
121121
_length = rhs._length;
122122
_data = rhs._data;
@@ -147,7 +147,7 @@ struct SmallArray(T, uint maxLength)
147147
}
148148

149149
/// ditto
150-
ref typeof(this) opAssign(uint n)(SmallArray!(T, n) rhs) return
150+
ref typeof(this) opAssign(uint n)(const SmallArray!(T, n) rhs) return
151151
if (n != maxLength)
152152
{
153153
static if (n < maxLength)

source/mir/small_string.d

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ extern(D):
6161
}
6262

6363
/// ditto
64-
this(SmallString str) nothrow
64+
this(const SmallString str) nothrow
6565
{
6666
this.opAssign(str);
6767
}
6868

6969
/// ditto
70-
this(uint n)(SmallString!n str)
70+
this(uint n)(const SmallString!n str)
7171
{
7272
this.opAssign(str);
7373
}
@@ -124,7 +124,7 @@ extern(D):
124124
}
125125

126126
/// ditto
127-
ref typeof(this) opAssign(SmallString rhs) return nothrow
127+
ref typeof(this) opAssign(const SmallString rhs) return nothrow
128128
{
129129
_data = rhs._data;
130130
return this;
@@ -149,12 +149,13 @@ extern(D):
149149
version(D_Exceptions) throw exception;
150150
else assert(0, errorMsg);
151151
}
152-
_data = cast(char[0 .. maxLength])(rhs._data[0 .. maxLength]);
152+
_data = cast(char[maxLength])(rhs._data[0 .. maxLength]);
153153
}
154+
return this;
154155
}
155156

156157
/// ditto
157-
ref typeof(this) opAssign(uint n)(SmallString!n rhs) return
158+
ref typeof(this) opAssign(uint n)(const SmallString!n rhs) return
158159
if (n != maxLength)
159160
{
160161
static if (n < maxLength)
@@ -330,3 +331,10 @@ const:
330331
b.put("!");
331332
assert(b == "asdf qwerty!!");
332333
}
334+
335+
@safe pure @nogc nothrow version(mir_test) unittest
336+
{
337+
import mir.conv: emplaceRef;
338+
SmallString!32 a, b;
339+
emplaceRef!(const SmallString!32)(a, cast(const)b);
340+
}

0 commit comments

Comments
 (0)