From 050528beb4c7f1547908b6f9dd18797e582787aa Mon Sep 17 00:00:00 2001 From: 9il Date: Sun, 26 Apr 2020 17:40:00 +0700 Subject: [PATCH 1/5] allow equal to work with input ranges, cleanup imports --- source/mir/algorithm/iteration.d | 63 +++++++++++++++++------------ source/mir/algorithm/setops.d | 4 +- source/mir/container/binaryheap.d | 2 +- source/mir/exception.d | 26 ++++++------ source/mir/format.d | 1 - source/mir/interpolate/polynomial.d | 2 +- source/mir/ndslice/allocation.d | 3 +- source/mir/ndslice/dynamic.d | 50 +++++++++++------------ source/mir/ndslice/package.d | 5 +-- source/mir/ndslice/topology.d | 10 ++--- source/mir/rc/array.d | 2 +- source/mir/series.d | 26 ++++++------ 12 files changed, 102 insertions(+), 92 deletions(-) diff --git a/source/mir/algorithm/iteration.d b/source/mir/algorithm/iteration.d index 8108ab3b..5507e4ff 100644 --- a/source/mir/algorithm/iteration.d +++ b/source/mir/algorithm/iteration.d @@ -536,7 +536,6 @@ private void checkShapesMatch( (scope ref const Slices slices) if (Slices.length > 1) { - enum msg = "all arguments must be slices" ~ tailErrorMessage!(fun, pfun); enum msgShape = "all slices must have the same shape" ~ tailErrorMessage!(fun, pfun); enum N = slices[0].shape.length; foreach (i, Slice; Slices) @@ -2399,32 +2398,49 @@ template equal(alias pred = "a == b") { import mir.functional: naryFun; static if (__traits(isSame, naryFun!pred, pred)) - /++ - Params: - slices = Two or more slices, slices, ranges, and arrays. - - Returns: - `true` any of the elements verify `pred` and `false` otherwise. - +/ - bool equal(Slices...)(scope Slices slices) - if (Slices.length >= 2) { - enum msg = "all arguments must be slices" ~ tailErrorMessage!(); - enum msgShape = "all slices must have the same dimension count" ~ tailErrorMessage!(); - import mir.internal.utility; - foreach (i, Slice; Slices) + /++ + Params: + slices = Two or more ndslices, ranges, and arrays. + + Returns: + `true` any of the elements verify `pred` and `false` otherwise. + +/ + bool equal(Slices...)(scope Slices slices) + if (Slices.length >= 2) { - // static assert (isSlice!Slice, msg); - static if (i) + import mir.internal.utility; + static if (allSatisfy!(hasShape, Slices)) + { + auto shape0 = slices[0].shape; + enum N = DimensionCount!(Slices[0]); + foreach (ref slice; slices[1 .. $]) + { + if (slice.shape != shape0) + goto False; + } + return all!pred(allLightScope!slices); + } + else { - static assert (DimensionCount!(Slices[i]) == DimensionCount!(Slices[0])); - foreach (j; Iota!(DimensionCount!(Slices[0]))) - if (slices[i].shape[j] != slices[0].shape[j]) + for(;;) + { + auto empty = slices[0].empty; + foreach (ref slice; slices[1 .. $]) + { + if (slice.empty != empty) + goto False; + } + if (empty) + return true; + if (!pred(frontOf!slices)) goto False; + foreach (ref slice; slices) + slice.popFront; + } } + False: return false; } - return all!pred(allLightScope!slices); - False: return false; } else alias equal = .equal!(naryFun!pred); @@ -2466,7 +2482,6 @@ version(mir_test) unittest @safe pure nothrow @nogc version(mir_test) unittest { - import mir.algorithm.iteration: equal; import mir.math.common: approxEqual; import mir.ndslice.allocation: rcslice; import mir.ndslice.topology: as, iota; @@ -3563,7 +3578,6 @@ if (isInputRange!Range && is(typeof(naryFun!pred(r.front, r.front)) == bool)) /// @safe version(mir_test) unittest { - import std.algorithm.comparison : equal; import std.algorithm.mutation : copy; int[] arr = [ 1, 2, 2, 2, 2, 3, 4, 4, 4, 5 ]; @@ -3655,7 +3669,6 @@ struct Uniq(alias pred, Range) version(none) @safe version(mir_test) unittest { - import std.algorithm.comparison : equal; import std.internal.test.dummyrange; import std.range; @@ -3683,8 +3696,6 @@ version(none) @safe version(mir_test) unittest // https://issues.dlang.org/show_bug.cgi?id=17264 { - import std.algorithm.comparison : equal; - const(int)[] var = [0, 1, 1, 2]; assert(var.uniq.equal([0, 1, 2])); } diff --git a/source/mir/algorithm/setops.d b/source/mir/algorithm/setops.d index 259b3ac9..5ba1c785 100644 --- a/source/mir/algorithm/setops.d +++ b/source/mir/algorithm/setops.d @@ -122,7 +122,7 @@ MultiwayMerge!(naryFun!less, RangeOfRanges) multiwayMerge /// @safe nothrow @nogc version(mir_test) unittest { - import std.algorithm.comparison : equal; + import mir.algorithm.iteration: equal; static a = [ @@ -174,7 +174,7 @@ auto multiwayUnion(alias less = "a < b", RangeOfRanges)(RangeOfRanges ror) /// @safe version(mir_test) unittest { - import std.algorithm.comparison : equal; + import mir.algorithm.iteration: equal; // sets double[][] a = diff --git a/source/mir/container/binaryheap.d b/source/mir/container/binaryheap.d index 27699e48..6f660458 100644 --- a/source/mir/container/binaryheap.d +++ b/source/mir/container/binaryheap.d @@ -67,7 +67,7 @@ if (isRandomAccessRange!Store || isRandomAccessRange!(typeof(Store.init[]))) { import mir.utility : min; import mir.functional : naryFun; - static if (__VERSION__ >= 2085) import core.lifetime: move; else import std.algorithm.mutation: move; + import core.lifetime: move; import std.algorithm.mutation : swapAt; static if (isRandomAccessRange!Store) diff --git a/source/mir/exception.d b/source/mir/exception.d index 4b8bcaf7..862db21e 100644 --- a/source/mir/exception.d +++ b/source/mir/exception.d @@ -7,6 +7,9 @@ module mir.exception; version(D_Exceptions): +static if (__traits(compiles, (()@nogc {throw new Exception("");})())) + version = NOGCEXP; + /// auto ref enforce(string fmt, string file = __FILE__, int line = __LINE__, Expr)(scope auto return ref Expr arg) @trusted { @@ -40,9 +43,6 @@ version(D_Ddoc) else private enum _version_D_Ddoc = false; -static if (_version_D_Ddoc || __traits(compiles, (()@nogc {throw new Exception("");})())) -{ - /++ +/ class MirException : Exception @@ -52,8 +52,9 @@ class MirException : Exception } /// Generic style +version(NOGCEXP) version (mir_test) @safe pure nothrow @nogc -version (mir_test) unittest +unittest { import mir.exception; try throw new MirException("Hi D", 2, "!"); @@ -61,8 +62,9 @@ version (mir_test) unittest } /// C++ style +version(NOGCEXP) version (mir_test) @safe pure nothrow @nogc -version (mir_test) unittest +unittest { import mir.exception; import mir.format; @@ -71,8 +73,9 @@ version (mir_test) unittest } /// Low-level style +version(NOGCEXP) version (mir_test) @safe pure nothrow @nogc -version (mir_test) unittest +unittest { import mir.exception; import mir.format; @@ -82,8 +85,9 @@ version (mir_test) unittest } /// +version(NOGCEXP) version (mir_test) @safe pure nothrow @nogc -version (mir_test) unittest +unittest { @safe pure nothrow @nogc bool func(scope const(char)[] msg) @@ -127,7 +131,7 @@ version (mir_test) unittest // /// // @safe pure nothrow @nogc -// version (mir_test) unittest +// version(NOGCEXP) version (mir_test) unittest // { // import mir.exception; // try enforce(false, "Hi D", 2, "!"); @@ -154,7 +158,7 @@ version (mir_test) unittest // /// // @safe pure nothrow @nogc -// version (mir_test) unittest +// version(NOGCEXP) version (mir_test) unittest // { // import mir.exception; // try enforce(false, "Msg"); @@ -172,7 +176,7 @@ class MirError : Error /// @system pure nothrow @nogc -version (mir_test) unittest +version(NOGCEXP) version (mir_test) unittest { @system pure nothrow @nogc bool func(scope const(char)[] msg) @@ -294,5 +298,3 @@ private const(char)[] initilizePayload(ref return char[maxMsgLen] payload, scope (() @trusted => memcpy(payload.ptr, msg.ptr, msg.length))(); return payload[0 .. msg.length]; } - -} diff --git a/source/mir/format.d b/source/mir/format.d index b0f8465d..7e89f943 100644 --- a/source/mir/format.d +++ b/source/mir/format.d @@ -191,7 +191,6 @@ pragma(inline, false) ref W printEscaped(C = char, W)(scope return ref W w, scope const(char)[] str) { // TODO: replace with Mir implementation. - import std.uni: isGraphical; w.put('\"'); foreach (char c; str[]) { diff --git a/source/mir/interpolate/polynomial.d b/source/mir/interpolate/polynomial.d index a7bf91b0..7e89b0f0 100644 --- a/source/mir/interpolate/polynomial.d +++ b/source/mir/interpolate/polynomial.d @@ -140,7 +140,7 @@ struct Lagrange(T, uint maxAdditionalFunctions = 0, X = T) +/ this(Slice!(RCI!(immutable X)) grid, RCArray!T values) { - static if (__VERSION__ >= 2085) import core.lifetime: move; else import std.algorithm.mutation: move; + import core.lifetime: move; auto weights = grid.lightScope.inversedBarycentricWeights; this(grid.move, values.move, weights.move); } diff --git a/source/mir/ndslice/allocation.d b/source/mir/ndslice/allocation.d index 0ed54aee..d319c86d 100644 --- a/source/mir/ndslice/allocation.d +++ b/source/mir/ndslice/allocation.d @@ -333,8 +333,7 @@ version(mir_test) { import mir.ndslice.slice; import mir.ndslice.allocation: slice; - - import std.datetime.date; + import mir.date: Date; auto dataframe = slice!(double, Date, string)(4, 3); assert(dataframe.length == 4); diff --git a/source/mir/ndslice/dynamic.d b/source/mir/ndslice/dynamic.d index cb9886d7..9ce0d1bb 100644 --- a/source/mir/ndslice/dynamic.d +++ b/source/mir/ndslice/dynamic.d @@ -764,29 +764,29 @@ auto reversed(Iterator, size_t N, SliceKind kind)(Slice!(Iterator, N, kind) slic @safe @nogc pure nothrow version(mir_test) unittest { + import mir.algorithm.iteration : equal; + import mir.ndslice.concatenation : concatenation; import mir.ndslice.slice; import mir.ndslice.topology; - import std.algorithm.comparison : equal; - import std.range : chain; auto i0 = iota([4], 0); auto r0 = i0.retro; auto i1 = iota([4], 4); auto r1 = i1.retro; auto i2 = iota([4], 8); auto r2 = i2.retro; auto slice = iota(3, 4).universal; - assert(slice .flattened.equal(chain(i0, i1, i2))); + assert(slice .flattened.equal(concatenation(i0, i1, i2))); // Template - assert(slice.reversed!(0) .flattened.equal(chain(i2, i1, i0))); - assert(slice.reversed!(1) .flattened.equal(chain(r0, r1, r2))); - assert(slice.reversed!(0, 1) .flattened.equal(chain(r2, r1, r0))); - assert(slice.reversed!(1, 0) .flattened.equal(chain(r2, r1, r0))); - assert(slice.reversed!(1, 1) .flattened.equal(chain(i0, i1, i2))); - assert(slice.reversed!(0, 0, 0).flattened.equal(chain(i2, i1, i0))); + assert(slice.reversed!(0) .flattened.equal(concatenation(i2, i1, i0))); + assert(slice.reversed!(1) .flattened.equal(concatenation(r0, r1, r2))); + assert(slice.reversed!(0, 1) .flattened.equal(concatenation(r2, r1, r0))); + assert(slice.reversed!(1, 0) .flattened.equal(concatenation(r2, r1, r0))); + assert(slice.reversed!(1, 1) .flattened.equal(concatenation(i0, i1, i2))); + assert(slice.reversed!(0, 0, 0).flattened.equal(concatenation(i2, i1, i0))); // Function - assert(slice.reversed (0) .flattened.equal(chain(i2, i1, i0))); - assert(slice.reversed (1) .flattened.equal(chain(r0, r1, r2))); - assert(slice.reversed (0, 1) .flattened.equal(chain(r2, r1, r0))); - assert(slice.reversed (1, 0) .flattened.equal(chain(r2, r1, r0))); - assert(slice.reversed (1, 1) .flattened.equal(chain(i0, i1, i2))); - assert(slice.reversed (0, 0, 0).flattened.equal(chain(i2, i1, i0))); + assert(slice.reversed (0) .flattened.equal(concatenation(i2, i1, i0))); + assert(slice.reversed (1) .flattened.equal(concatenation(r0, r1, r2))); + assert(slice.reversed (0, 1) .flattened.equal(concatenation(r2, r1, r0))); + assert(slice.reversed (1, 0) .flattened.equal(concatenation(r2, r1, r0))); + assert(slice.reversed (1, 1) .flattened.equal(concatenation(i0, i1, i2))); + assert(slice.reversed (0, 0, 0).flattened.equal(concatenation(i2, i1, i0))); } private enum _stridedCode = q{ @@ -919,23 +919,23 @@ pure nothrow version(mir_test) unittest @safe @nogc pure nothrow version(mir_test) unittest { - import mir.ndslice.slice; - import mir.ndslice.topology; - import std.algorithm.comparison : equal; + import mir.ndslice; + import mir.algorithm.iteration : equal; + import std.range : chain; auto i0 = iota([4], 0); auto s0 = stride(i0, 3); auto i1 = iota([4], 4); auto s1 = stride(i1, 3); auto i2 = iota([4], 8); auto s2 = stride(i2, 3); auto slice = iota(3, 4).universal; - assert(slice .flattened.equal(chain(i0, i1, i2))); + assert(slice .flattened.equal(concatenation(i0, i1, i2))); // Template - assert(slice.strided!0(2) .flattened.equal(chain(i0, i2))); - assert(slice.strided!1(3) .flattened.equal(chain(s0, s1, s2))); - assert(slice.strided!(0, 1)(2, 3).flattened.equal(chain(s0, s2))); + assert(slice.strided!0(2) .flattened.equal(concatenation(i0, i2))); + assert(slice.strided!1(3) .flattened.equal(concatenation(s0, s1, s2))); + assert(slice.strided!(0, 1)(2, 3).flattened.equal(concatenation(s0, s2))); // Function - assert(slice.strided(0, 2).flattened.equal(chain(i0, i2))); - assert(slice.strided(1, 3).flattened.equal(chain(s0, s1, s2))); - assert(slice.strided(0, 2).strided(1, 3).flattened.equal(chain(s0, s2))); + assert(slice.strided(0, 2).flattened.equal(concatenation(i0, i2))); + assert(slice.strided(1, 3).flattened.equal(concatenation(s0, s1, s2))); + assert(slice.strided(0, 2).strided(1, 3).flattened.equal(concatenation(s0, s2))); } /++ diff --git a/source/mir/ndslice/package.d b/source/mir/ndslice/package.d index 27f87179..c1db06dd 100644 --- a/source/mir/ndslice/package.d +++ b/source/mir/ndslice/package.d @@ -608,8 +608,7 @@ version(mir_test) unittest pure nothrow version(mir_test) unittest { - import std.algorithm.comparison : equal; - import std.range : iota; + import mir.ndslice.topology : iota; import mir.array.allocation : array; auto r = 1000.iota.array; @@ -634,7 +633,7 @@ pure nothrow version(mir_test) unittest t1.popBack(); assert(t1.back == 17); - assert(t1.equal(iota(12, 18))); + assert(t1 == iota([6], 12)); t1.front = 13; assert(t1.front == 13); diff --git a/source/mir/ndslice/topology.d b/source/mir/ndslice/topology.d index 7251a460..f5a0fe51 100644 --- a/source/mir/ndslice/topology.d +++ b/source/mir/ndslice/topology.d @@ -2634,13 +2634,13 @@ version(mir_test) unittest /// pure version(mir_test) unittest { - import std.algorithm.iteration : sum, reduce; - import mir.utility : max; - import mir.ndslice.dynamic : transposed; + import mir.algorithm.iteration: reduce; + import mir.math.common: fmax; + import mir.math.stat: mean; + import mir.math.sum; /// Returns maximal column average. auto maxAvg(S)(S matrix) { - return reduce!max(matrix.universal.transposed.pack!1.map!sum) - / double(matrix.length); + return reduce!fmax(0.0, matrix.alongDim!1.map!mean); } // 1 2 // 3 4 diff --git a/source/mir/rc/array.d b/source/mir/rc/array.d index fe277fb5..356bb0b2 100644 --- a/source/mir/rc/array.d +++ b/source/mir/rc/array.d @@ -510,7 +510,7 @@ struct mir_rci(T) ref opAssign(Q)(return mir_rci!Q rhs) scope return nothrow if (isImplicitlyConvertible!(Q*, T*)) { - static if (__VERSION__ >= 2085) import core.lifetime: move; else import std.algorithm.mutation: move; + import core.lifetime: move; _iterator = rhs._iterator; _array = move(rhs._array); return this; diff --git a/source/mir/series.d b/source/mir/series.d index 2b31b26c..05dc809d 100644 --- a/source/mir/series.d +++ b/source/mir/series.d @@ -33,8 +33,8 @@ See_also: $(LREF unionSeries), $(LREF troykaSeries), $(LREF troykaGalop). import mir.array.allocation: array; import mir.algorithm.setops: multiwayUnion; - import std.datetime: Date; - static if (__VERSION__ >= 2085) import core.lifetime: move; else import std.algorithm.mutation: move; + import mir.date: Date; + import core.lifetime: move; import std.exception: collectExceptionMsg; ////////////////////////////////////// @@ -62,7 +62,7 @@ See_also: $(LREF unionSeries), $(LREF troykaSeries), $(LREF troykaGalop). assert(series0 .asSlice // ref qualifier is optional - .map!((ref key, ref value) => key.month == value) + .map!((ref key, ref value) => key.yearMonthDay.month == value) .all); ////////////////////////////////////// @@ -85,7 +85,7 @@ See_also: $(LREF unionSeries), $(LREF troykaSeries), $(LREF troykaGalop). assert(collectExceptionMsg!Exception( series0.get(missingDate) - ) == "Series double[Date]: Missing required key"); + ) == "Series double[date]: Missing required key"); assert(collectExceptionMsg!Exception( series0.get(missingDate, new Exception("My exception msg")) @@ -93,11 +93,11 @@ See_also: $(LREF unionSeries), $(LREF troykaSeries), $(LREF troykaGalop). assert(collectExceptionMsg!Exception( series0.getVerbose(missingDate) - ) == "Series double[Date]: Missing 2016-Mar-01 key"); + ) == "Series double[date]: Missing 2016-03-01 key"); assert(collectExceptionMsg!Exception( series0.getExtraVerbose(missingDate, "My exception msg") - ) == "My exception msg. Series double[Date]: Missing 2016-Mar-01 key"); + ) == "My exception msg. Series double[date]: Missing 2016-03-01 key"); // assign with get* series0.get(refDate) = 100; @@ -402,7 +402,7 @@ struct mir_series(IndexIterator_, Iterator_, size_t N_ = 1, SliceKind kind_ = Co /// @safe pure nothrow version(mir_test) unittest { - import std.datetime: Date; + import mir.date: Date; ////////////////////////////////////// // Constructs two time-series. @@ -431,7 +431,7 @@ struct mir_series(IndexIterator_, Iterator_, size_t N_ = 1, SliceKind kind_ = Co static if (doUnittest) @safe pure nothrow version(mir_test) unittest { - import std.datetime: Date; + import mir.date: Date; ////////////////////////////////////// // Constructs two time-series. @@ -1236,7 +1236,7 @@ struct mir_series(IndexIterator_, Iterator_, size_t N_ = 1, SliceKind kind_ = Co ref opAssign(RIndexIterator, RIterator)(Series!(RIndexIterator, RIterator, N, kind) rvalue) return if (isAssignable!(IndexIterator, RIndexIterator) && isAssignable!(Iterator, RIterator)) { - static if (__VERSION__ >= 2085) import core.lifetime: move; else import std.algorithm.mutation: move; + import core.lifetime: move; this._data._structure = rvalue._data._structure; this._data._iterator = rvalue._data._iterator.move; this._index = rvalue._index.move; @@ -1426,7 +1426,7 @@ alias Series = mir_series; /// 2-dimensional data @safe pure version(mir_test) unittest { - import std.datetime: Date; + import mir.date: Date; import mir.ndslice.topology: canonical, iota; size_t row_length = 5; @@ -1639,7 +1639,7 @@ auto rcseries(RK, RV, K = RK, V = RV)(RV[RK] aa) emplaceRef!V(it._data.front, kv.value.to!V); it.popFront; } - static if (__VERSION__ >= 2085) import core.lifetime: move; else import std.algorithm.mutation: move; + import core.lifetime: move; .sort(ret.lightScope); static if (is(typeof(ret) == R)) return ret; @@ -2243,7 +2243,7 @@ auto unionSeries(IndexIterator, Iterator, size_t N, SliceKind kind, size_t C)(Se /// @safe pure nothrow version(mir_test) unittest { - import std.datetime: Date; + import mir.date: Date; ////////////////////////////////////// // Constructs two time-series. @@ -2272,7 +2272,7 @@ auto unionSeries(IndexIterator, Iterator, size_t N, SliceKind kind, size_t C)(Se /// @safe pure nothrow version(mir_test) unittest { - import std.datetime: Date; + import mir.date: Date; ////////////////////////////////////// // Constructs three time-series. From bff3268938afefdf79d45351582990cc5d81a229 Mon Sep 17 00:00:00 2001 From: 9il Date: Sun, 26 Apr 2020 17:42:41 +0700 Subject: [PATCH 2/5] fixup docs --- source/mir/exception.d | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/source/mir/exception.d b/source/mir/exception.d index 862db21e..aceadb2e 100644 --- a/source/mir/exception.d +++ b/source/mir/exception.d @@ -7,8 +7,15 @@ module mir.exception; version(D_Exceptions): -static if (__traits(compiles, (()@nogc {throw new Exception("");})())) +version(D_Ddoc) + private enum _version_D_Ddoc = true; +else + private enum _version_D_Ddoc = false; + +static if (_version_D_Ddoc || __traits(compiles, (()@nogc {throw new Exception("");})())) +{ version = NOGCEXP; +} /// auto ref enforce(string fmt, string file = __FILE__, int line = __LINE__, Expr)(scope auto return ref Expr arg) @trusted @@ -38,11 +45,6 @@ version (mir_test) unittest catch(Exception e) assert(e.msg == "Msg"); } -version(D_Ddoc) - private enum _version_D_Ddoc = true; -else - private enum _version_D_Ddoc = false; - /++ +/ class MirException : Exception From 56a879d08c65edc54b8072992d8ab6f8253f58d3 Mon Sep 17 00:00:00 2001 From: 9il Date: Sun, 26 Apr 2020 17:56:10 +0700 Subject: [PATCH 3/5] ditto --- meson.build | 2 +- source/mir/exception.d | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index eb5a9b07..6920360e 100644 --- a/meson.build +++ b/meson.build @@ -102,7 +102,7 @@ this_dep = declare_dependency( dependencies: required_deps, ) -test_versions = ['mir_test'] +test_versions = ['mir_test', 'NOGCEXP'] if has_cpp_headers install_subdir('include/', diff --git a/source/mir/exception.d b/source/mir/exception.d index aceadb2e..cf388780 100644 --- a/source/mir/exception.d +++ b/source/mir/exception.d @@ -12,7 +12,8 @@ version(D_Ddoc) else private enum _version_D_Ddoc = false; -static if (_version_D_Ddoc || __traits(compiles, (()@nogc {throw new Exception("");})())) +version(D_Ddoc) {} else +static if (__traits(compiles, (()@nogc {throw new Exception("");})())) { version = NOGCEXP; } @@ -21,7 +22,7 @@ static if (_version_D_Ddoc || __traits(compiles, (()@nogc {throw new Exception(" auto ref enforce(string fmt, string file = __FILE__, int line = __LINE__, Expr)(scope auto return ref Expr arg) @trusted { import core.lifetime: forward; - import mir.utility: _expect; + import mir.utility: _expect;_version_D_Ddoc static if (__traits(compiles, arg !is null)) { if (_expect(arg !is null, true)) From c8aa5ab5f7a44be77f9231fb116b0a4304b1654f Mon Sep 17 00:00:00 2001 From: 9il Date: Sun, 26 Apr 2020 17:59:02 +0700 Subject: [PATCH 4/5] fixup --- source/mir/exception.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/mir/exception.d b/source/mir/exception.d index cf388780..d2f6a801 100644 --- a/source/mir/exception.d +++ b/source/mir/exception.d @@ -22,7 +22,7 @@ static if (__traits(compiles, (()@nogc {throw new Exception("");})())) auto ref enforce(string fmt, string file = __FILE__, int line = __LINE__, Expr)(scope auto return ref Expr arg) @trusted { import core.lifetime: forward; - import mir.utility: _expect;_version_D_Ddoc + import mir.utility: _expect; static if (__traits(compiles, arg !is null)) { if (_expect(arg !is null, true)) From a60d17c972f66c041bfe2dc7b99109e442657f5a Mon Sep 17 00:00:00 2001 From: 9il Date: Sun, 26 Apr 2020 18:03:49 +0700 Subject: [PATCH 5/5] fixup --- source/mir/exception.d | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/source/mir/exception.d b/source/mir/exception.d index d2f6a801..a98289c0 100644 --- a/source/mir/exception.d +++ b/source/mir/exception.d @@ -12,11 +12,7 @@ version(D_Ddoc) else private enum _version_D_Ddoc = false; -version(D_Ddoc) {} else -static if (__traits(compiles, (()@nogc {throw new Exception("");})())) -{ - version = NOGCEXP; -} +private enum NOGCEXP = __traits(compiles, (()@nogc {throw new Exception("");})()); /// auto ref enforce(string fmt, string file = __FILE__, int line = __LINE__, Expr)(scope auto return ref Expr arg) @trusted @@ -55,7 +51,7 @@ class MirException : Exception } /// Generic style -version(NOGCEXP) version (mir_test) +version (mir_test) static if (NOGCEXP) @safe pure nothrow @nogc unittest { @@ -65,7 +61,7 @@ unittest } /// C++ style -version(NOGCEXP) version (mir_test) +version (mir_test) static if (NOGCEXP) @safe pure nothrow @nogc unittest { @@ -76,7 +72,7 @@ unittest } /// Low-level style -version(NOGCEXP) version (mir_test) +version (mir_test) static if (NOGCEXP) @safe pure nothrow @nogc unittest { @@ -88,7 +84,7 @@ unittest } /// -version(NOGCEXP) version (mir_test) +version (mir_test) static if (NOGCEXP) @safe pure nothrow @nogc unittest { @@ -134,7 +130,7 @@ unittest // /// // @safe pure nothrow @nogc -// version(NOGCEXP) version (mir_test) unittest +// version (mir_test) unittest static if (NOGCEXP) // { // import mir.exception; // try enforce(false, "Hi D", 2, "!"); @@ -161,7 +157,7 @@ unittest // /// // @safe pure nothrow @nogc -// version(NOGCEXP) version (mir_test) unittest +// version (mir_test) unittest static if (NOGCEXP) // { // import mir.exception; // try enforce(false, "Msg"); @@ -179,7 +175,8 @@ class MirError : Error /// @system pure nothrow @nogc -version(NOGCEXP) version (mir_test) unittest +version (mir_test) static if (NOGCEXP) +unittest { @system pure nothrow @nogc bool func(scope const(char)[] msg)