Skip to content

Commit 89b8444

Browse files
committed
adopt for DIP1000
1 parent ee68b09 commit 89b8444

File tree

7 files changed

+104
-49
lines changed

7 files changed

+104
-49
lines changed

source/mir/algorithm/iteration.d

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -703,9 +703,9 @@ S reduceImpl(alias fun, S, Slices...)(S seed, Slices slices)
703703
do
704704
{
705705
static if (DimensionCount!(Slices[0]) == 1)
706-
seed = fun(seed, frontOf!slices);
706+
mixin(`seed = fun(seed,` ~ frontOf!(Slices.length) ~ `);`);
707707
else
708-
seed = .reduceImpl!fun(seed, frontOf!slices);
708+
mixin(`seed = .reduceImpl!fun(seed,` ~ frontOf!(Slices.length) ~ `);`);
709709
foreach_reverse(ref slice; slices)
710710
slice.popFront;
711711
}
@@ -960,7 +960,7 @@ void eachImpl(alias fun, Slices...)(Slices slices)
960960
do
961961
{
962962
static if (DimensionCount!(Slices[0]) == 1)
963-
fun(frontOf!slices);
963+
mixin(`fun(`~ frontOf!(Slices.length) ~ `);`);
964964
else
965965
.eachImpl!fun(frontOf2!slices);
966966
foreach_reverse(i; Iota!(Slices.length))
@@ -988,7 +988,7 @@ void chequerEachImpl(alias fun, Slices...)(Chequer color, Slices slices)
988988
{
989989
do
990990
{
991-
.chequerEachImpl!fun(color, frontOf!slices);
991+
mixin(`.chequerEachImpl!fun(color,` ~ frontOf!(Slices.length) ~ `);`);
992992
color = cast(Chequer)!color;
993993
foreach_reverse(i; Iota!(Slices.length))
994994
slices[i].popFront;
@@ -1029,7 +1029,7 @@ template eachOnBorder(alias fun)
10291029
alias N = DimensionCount!(Slices[0]);
10301030
static if (N == 1)
10311031
{
1032-
fun(frontOf!slices);
1032+
mixin(`fun(`~ frontOf!(Slices.length) ~ `);`);
10331033
if (slices[0].length > 1)
10341034
fun(backOf!slices);
10351035
}
@@ -1874,15 +1874,15 @@ bool findImpl(alias fun, size_t N, Slices...)(scope ref size_t[N] backwardIndex,
18741874
{
18751875
static if (DimensionCount!(Slices[0]) == 1)
18761876
{
1877-
if (fun(frontOf!slices))
1877+
if (mixin(`fun(`~ frontOf!(Slices.length) ~ `)`))
18781878
{
18791879
backwardIndex[0] = slices[0].length;
18801880
return true;
18811881
}
18821882
}
18831883
else
18841884
{
1885-
if (findImpl!fun(backwardIndex[1 .. $], frontOf!slices))
1885+
if (mixin(`findImpl!fun(backwardIndex[1 .. $],` ~ frontOf!(Slices.length) ~ `)`))
18861886
{
18871887
backwardIndex[0] = slices[0].length;
18881888
return true;
@@ -2018,7 +2018,7 @@ template find(alias pred)
20182018
Constraints:
20192019
All slices must have the same shape.
20202020
+/
2021-
@optmath Select!(DimensionCount!(Slices[0]) > 1, size_t[DimensionCount!(Slices[0])], size_t) find(Slices...)(auto ref Slices slices)
2021+
@optmath Select!(DimensionCount!(Slices[0]) > 1, size_t[DimensionCount!(Slices[0])], size_t) find(Slices...)(Slices slices)
20222022
if (Slices.length && allSatisfy!(hasShape, Slices))
20232023
{
20242024
static if (Slices.length > 1)
@@ -2125,9 +2125,10 @@ version(mir_test) unittest
21252125
assert(bi == [1, 1]);
21262126
assert(sl.backward(bi) == 5);
21272127

2128+
import mir.test;
21282129
// sl was changed
2129-
assert(sl == [[8, 8, 8],
2130-
[8, 8, 5]]);
2130+
sl.should == [[8, 8, 8],
2131+
[8, 8, 5]];
21312132
}
21322133

21332134
@safe pure nothrow
@@ -2160,7 +2161,7 @@ size_t anyImpl(alias fun, Slices...)(Slices slices)
21602161
{
21612162
static if (DimensionCount!(Slices[0]) == 1)
21622163
{
2163-
if (fun(frontOf!slices))
2164+
if (mixin(`fun(`~ frontOf!(Slices.length) ~ `)`))
21642165
return true;
21652166
}
21662167
else
@@ -2320,7 +2321,7 @@ size_t allImpl(alias fun, Slices...)(Slices slices)
23202321
{
23212322
static if (DimensionCount!(Slices[0]) == 1)
23222323
{
2323-
if (!fun(frontOf!slices))
2324+
if (!mixin(`fun(`~ frontOf!(Slices.length) ~ `)`))
23242325
return false;
23252326
}
23262327
else
@@ -2634,7 +2635,7 @@ template equal(alias pred = "a == b")
26342635
}
26352636
if (empty)
26362637
return true;
2637-
if (!pred(frontOf!slices))
2638+
if (!mixin(`pred(`~ frontOf!(Slices.length) ~ `)`))
26382639
goto False;
26392640
foreach (ref slice; slices)
26402641
slice.popFront;
@@ -2848,7 +2849,7 @@ size_t countImpl(alias fun, Slices...)(Slices slices)
28482849
{
28492850
static if (DimensionCount!(Slices[0]) == 1)
28502851
{
2851-
if(fun(frontOf!slices))
2852+
if(mixin(`fun(`~ frontOf!(Slices.length) ~ `)`))
28522853
ret++;
28532854
}
28542855
else

source/mir/interpolate/polynomial.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ version(mir_test)
7070
/++
7171
Constructs barycentric lagrange interpolant.
7272
+/
73-
Lagrange!(T, maxDerivative) lagrange(uint maxDerivative = 0, T, X)(scope const X[] x, scope const T[] y)
73+
Lagrange!(T, maxDerivative) lagrange(uint maxDerivative = 0, T, X)(scope const X[] x, scope const T[] y) @trusted
7474
if (maxDerivative < 16)
7575
{
7676
import mir.ndslice.allocation: rcslice;

source/mir/ndslice/concatenation.d

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ struct Concatenation(size_t dim, Slices...)
286286
}
287287

288288
/// Shape of the concatenation.
289-
size_t[N] shape()() const @property
289+
size_t[N] shape()() scope const @property
290290
{
291291
typeof(return) ret;
292292
foreach(i; Iota!N)
@@ -295,7 +295,7 @@ struct Concatenation(size_t dim, Slices...)
295295
}
296296

297297
/// Multidimensional input range primitives
298-
bool empty(size_t d = 0)() const @property
298+
bool empty(size_t d = 0)() scope const @property
299299
{
300300
static if (d == dim)
301301
{
@@ -311,7 +311,7 @@ struct Concatenation(size_t dim, Slices...)
311311
}
312312

313313
/// ditto
314-
void popFront(size_t d = 0)()
314+
void popFront(size_t d = 0)() scope
315315
{
316316
static if (d == dim)
317317
{

source/mir/ndslice/internal.d

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -359,18 +359,18 @@ package(mir) template strideOf(args...)
359359
}
360360
}
361361

362-
package(mir) template frontOf(args...)
362+
package(mir) template frontOf(size_t n)
363363
{
364-
static if (args.length == 0)
365-
enum frontOf = args;
366-
else
367-
{
368-
@optmath @property auto ref frontOfMod()()
364+
enum frontOf = () {
365+
string ret;
366+
static foreach (i; 0 .. n)
369367
{
370-
return args[0].front;
368+
if (i)
369+
ret ~= `, `;
370+
ret ~= "slices[" ~ i.stringof ~ `].front`;
371371
}
372-
alias frontOf = AliasSeq!(frontOfMod, frontOf!(args[1..$]));
373-
}
372+
return ret;
373+
} ();
374374
}
375375

376376
package(mir) template frontOf2(args...)

source/mir/ndslice/slice.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2375,7 +2375,7 @@ public:
23752375
Note:
23762376
Does not allocate neither new slice nor a closure.
23772377
+/
2378-
auto opUnary(string op)() return scope
2378+
auto opUnary(string op)()
23792379
if (op == "*" || op == "~" || op == "-" || op == "+")
23802380
{
23812381
import mir.ndslice.topology: map;

source/mir/series.d

Lines changed: 67 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2188,18 +2188,45 @@ Merges multiple (time) series into one.
21882188
Makes exactly one memory allocation for two series union
21892189
and two memory allocation for three and more series union.
21902190
2191-
Params:
2192-
seriesTuple = variadic static array of composed of series, each series must be sorted.
21932191
Returns: sorted GC-allocated series.
21942192
See_also $(LREF Series.opBinary) $(LREF makeUnionSeries)
21952193
*/
2196-
auto unionSeries(IndexIterator, Iterator, size_t N, SliceKind kind, size_t C)(Series!(IndexIterator, Iterator, N, kind)[C] seriesTuple...)
2197-
if (C > 1)
2194+
auto unionSeries(IndexIterator, Iterator, size_t N, SliceKind kind)(
2195+
Series!(IndexIterator, Iterator, N, kind) a,
2196+
Series!(IndexIterator, Iterator, N, kind) b,
2197+
) @safe
2198+
{
2199+
import core.lifetime: move;
2200+
Series!(IndexIterator, Iterator, N, kind)[2] ar = [move(a), move(b)];
2201+
return unionSeriesImplPrivate!false(move(ar));
2202+
}
2203+
2204+
/// ditto
2205+
auto unionSeries(IndexIterator, Iterator, size_t N, SliceKind kind)(
2206+
Series!(IndexIterator, Iterator, N, kind) a,
2207+
Series!(IndexIterator, Iterator, N, kind) b,
2208+
Series!(IndexIterator, Iterator, N, kind) c,
2209+
) @safe
21982210
{
21992211
import core.lifetime: move;
2200-
return unionSeriesImplPrivate!false(move(seriesTuple));
2212+
Series!(IndexIterator, Iterator, N, kind)[3] ar = [move(a), move(b), move(c)];
2213+
return unionSeriesImplPrivate!false(move(ar));
22012214
}
22022215

2216+
/// ditto
2217+
auto unionSeries(IndexIterator, Iterator, size_t N, SliceKind kind)(
2218+
Series!(IndexIterator, Iterator, N, kind) a,
2219+
Series!(IndexIterator, Iterator, N, kind) b,
2220+
Series!(IndexIterator, Iterator, N, kind) c,
2221+
Series!(IndexIterator, Iterator, N, kind) d,
2222+
) @safe
2223+
{
2224+
import core.lifetime: move;
2225+
Series!(IndexIterator, Iterator, N, kind)[4] ar = [move(a), move(b), move(c), move(d)];
2226+
return unionSeriesImplPrivate!false(move(ar));
2227+
}
2228+
2229+
22032230
///
22042231
@safe pure nothrow version(mir_test) unittest
22052232
{
@@ -2322,15 +2349,42 @@ auto makeUnionSeries(IndexIterator, Iterator, size_t N, SliceKind kind, size_t C
23222349
/**
23232350
Merges multiple (time) series into one.
23242351
2325-
Params:
2326-
seriesTuple = variadic static array of composed of series.
23272352
Returns: sorted manually allocated series.
23282353
See_also $(LREF unionSeries)
23292354
*/
2330-
auto rcUnionSeries(IndexIterator, Iterator, size_t N, SliceKind kind, size_t C)(Series!(IndexIterator, Iterator, N, kind)[C] seriesTuple...)
2331-
if (C > 1)
2355+
auto rcUnionSeries(IndexIterator, Iterator, size_t N, SliceKind kind)(
2356+
Series!(IndexIterator, Iterator, N, kind) a,
2357+
Series!(IndexIterator, Iterator, N, kind) b,
2358+
) @safe
23322359
{
2333-
return unionSeriesImplPrivate!true(seriesTuple);
2360+
import core.lifetime: move;
2361+
Series!(IndexIterator, Iterator, N, kind)[2] ar = [move(a), move(b)];
2362+
return unionSeriesImplPrivate!true(move(ar));
2363+
}
2364+
2365+
///ditto
2366+
auto rcUnionSeries(IndexIterator, Iterator, size_t N, SliceKind kind)(
2367+
Series!(IndexIterator, Iterator, N, kind) a,
2368+
Series!(IndexIterator, Iterator, N, kind) b,
2369+
Series!(IndexIterator, Iterator, N, kind) c,
2370+
) @safe
2371+
{
2372+
import core.lifetime: move;
2373+
Series!(IndexIterator, Iterator, N, kind)[3] ar = [move(a), move(b), move(c)];
2374+
return unionSeriesImplPrivate!true(move(ar));
2375+
}
2376+
2377+
///ditto
2378+
auto rcUnionSeries(IndexIterator, Iterator, size_t N, SliceKind kind)(
2379+
Series!(IndexIterator, Iterator, N, kind) a,
2380+
Series!(IndexIterator, Iterator, N, kind) b,
2381+
Series!(IndexIterator, Iterator, N, kind) c,
2382+
Series!(IndexIterator, Iterator, N, kind) d,
2383+
) @safe
2384+
{
2385+
import core.lifetime: move;
2386+
Series!(IndexIterator, Iterator, N, kind)[4] ar = [move(a), move(b), move(c), move(d)];
2387+
return unionSeriesImplPrivate!true(move(ar));
23342388
}
23352389

23362390
///
@@ -2374,9 +2428,9 @@ Params:
23742428
pragma(inline, false)
23752429
auto unionSeriesImpl(I, E,
23762430
IndexIterator, Iterator, size_t N, SliceKind kind, UI, UE)(
2377-
Series!(IndexIterator, Iterator, N, kind)[] seriesTuple,
2431+
scope Series!(IndexIterator, Iterator, N, kind)[] seriesTuple,
23782432
Series!(UI*, UE*, N) uninitSeries,
2379-
)
2433+
) @trusted
23802434
{
23812435
import mir.conv: emplaceRef;
23822436
import mir.algorithm.setops: multiwayUnion;
@@ -2403,7 +2457,7 @@ auto unionSeriesImpl(I, E,
24032457
}
24042458
}
24052459

2406-
private auto unionSeriesImplPrivate(bool rc, IndexIterator, Iterator, size_t N, SliceKind kind, size_t C, Allocator...)(Series!(IndexIterator, Iterator, N, kind)[C] seriesTuple, ref Allocator allocator)
2460+
private auto unionSeriesImplPrivate(bool rc, IndexIterator, Iterator, size_t N, SliceKind kind, size_t C, Allocator...)(Series!(IndexIterator, Iterator, N, kind)[C] seriesTuple, ref Allocator allocator) @safe
24072461
if (C > 1 && Allocator.length <= 1)
24082462
{
24092463
import mir.algorithm.setops: unionLength;

source/mir/stdio.d

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ struct File
111111
/++
112112
Throws: $(LREF FileException)
113113
+/
114-
void rawWrite(scope const(void)[] data)
114+
void rawWrite(scope const(void)[] data) scope
115115
in (__ctfe || fp !is null)
116116
{
117117
if (__ctfe)
@@ -124,7 +124,7 @@ struct File
124124
/++
125125
Throws: $(LREF FileException)
126126
+/
127-
void flush()
127+
void flush() scope
128128
in (__ctfe || fp !is null)
129129
{
130130
if (__ctfe)
@@ -151,7 +151,7 @@ struct AssumeNothrowFile
151151
/++
152152
Throws: $(LREF FileError)
153153
+/
154-
void rawWrite(scope const(void)[] data)
154+
void rawWrite(scope const(void)[] data) scope
155155
in (__ctfe || fp !is null)
156156
{
157157
if (__ctfe)
@@ -164,7 +164,7 @@ struct AssumeNothrowFile
164164
/++
165165
Throws: $(LREF FileError)
166166
+/
167-
void flush()
167+
void flush() scope
168168
in (__ctfe || fp !is null)
169169
{
170170
if (__ctfe)
@@ -179,15 +179,15 @@ struct AssumeNothrowFile
179179
mixin template FileMembers()
180180
{
181181
///
182-
void put(C)(const C data)
182+
void put(C)(const C data) scope
183183
if (is(C == char) || is(C == wchar) | is(C == dchar))
184184
{
185185
C[1] array = [data];
186186
this.rawWrite(array);
187187
}
188188

189189
///
190-
void put(C)(scope const(C)[] data)
190+
void put(C)(scope const(C)[] data) scope
191191
if (is(C == char) || is(C == wchar) | is(C == dchar))
192192
{
193193
this.rawWrite(data);
@@ -218,15 +218,15 @@ mixin template FileMembers()
218218
}
219219

220220
/// Writes values in a text form
221-
void writeln(string separator = "", Args...)(auto ref const Args args)
221+
void writeln(string separator = "", Args...)(auto ref const Args args) scope
222222
if (Args.length > 0)
223223
{
224224
write(args);
225225
this << endl;
226226
}
227227

228228
/// ditto
229-
void write(string separator = "", Args...)(auto ref const Args args)
229+
void write(string separator = "", Args...)(auto ref const Args args) scope
230230
if (Args.length > 0)
231231
{
232232
pragma(inline, false);

0 commit comments

Comments
 (0)