Skip to content

Commit 14e5fff

Browse files
authored
rework dips (#223)
1 parent addebe5 commit 14e5fff

File tree

4 files changed

+42
-31
lines changed

4 files changed

+42
-31
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ mir-algorithm-test-default
2929
mir-algorithm-test-dips
3030
subprojects/mir-core
3131
mir-core
32+
mir-algorithm-test-dip1008

doc/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LATEST:=$(shell git describe --abbrev=0 --tags | tr -d v)
88
# binaries
99
DMD=dmd
1010
RDMD=rdmd
11-
DDOC=$(DMD) -w -c -o- -version=StdDdoc -version=Have_mir
11+
DDOC=$(DMD) -w -c -o- -version=StdDdoc -version=Have_mir -preview=dip1008
1212

1313
# folders
1414
DOC_OUTPUT_DIR=web

dub.sdl

+5-3
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ buildType "unittest-release" {
2020
versions "mir_test"
2121
}
2222

23-
dflags "-preview=dip1008"
24-
2523
configuration "default" {
2624
}
2725

26+
configuration "dip1008" {
27+
dflags "-preview=dip1008"
28+
}
29+
2830
configuration "dips" {
29-
dflags "-preview=dip1000"
31+
dflags "-preview=dip1000" "-preview=dip1008"
3032
}

source/mir/exception.d

+35-27
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,39 @@ Most of API Required DIP1008.
55
+/
66
module mir.exception;
77

8+
version(D_Exceptions):
9+
10+
///
11+
auto ref enforce(string fmt, string file = __FILE__, int line = __LINE__, Expr)(scope auto return ref Expr arg) @trusted
12+
{
13+
import mir.functional: forward;
14+
import mir.utility: _expect;
15+
static if (__traits(compiles, arg !is null))
16+
{
17+
if (_expect(arg !is null, true))
18+
return forward!arg[0];
19+
}
20+
else
21+
{
22+
if (_expect(cast(bool)arg, true))
23+
return forward!arg[0];
24+
}
25+
static immutable exception = new Exception(fmt, file, line);
26+
throw exception;
27+
}
28+
29+
///
30+
@safe pure nothrow @nogc
31+
version (mir_test) unittest
32+
{
33+
import mir.exception;
34+
try enforce!"Msg"(false);
35+
catch(Exception e) assert(e.msg == "Msg");
36+
}
37+
38+
static if (__traits(compiles, (()@nogc {throw new Exception("");})()))
39+
{
40+
841
/++
942
+/
1043
class MirException : Exception
@@ -123,33 +156,6 @@ version (mir_test) unittest
123156
// catch(Exception e) assert(e.msg == "Msg");
124157
// }
125158

126-
///
127-
auto ref enforce(string fmt, string file = __FILE__, int line = __LINE__, Expr)(scope auto return ref Expr arg) @trusted
128-
{
129-
import mir.functional: forward;
130-
import mir.utility: _expect;
131-
static if (__traits(compiles, arg !is null))
132-
{
133-
if (_expect(arg !is null, true))
134-
return forward!arg[0];
135-
}
136-
else
137-
{
138-
if (_expect(cast(bool)arg, true))
139-
return forward!arg[0];
140-
}
141-
static immutable exception = new Exception(fmt, file, line);
142-
throw exception;
143-
}
144-
145-
///
146-
@safe pure nothrow @nogc
147-
version (mir_test) unittest
148-
{
149-
import mir.exception;
150-
try enforce!"Msg"(false);
151-
catch(Exception e) assert(e.msg == "Msg");
152-
}
153159

154160
/++
155161
+/
@@ -283,3 +289,5 @@ private const(char)[] initilizePayload(ref return char[maxMsgLen] payload, scope
283289
(() @trusted => memcpy(payload.ptr, msg.ptr, msg.length))();
284290
return payload[0 .. msg.length];
285291
}
292+
293+
}

0 commit comments

Comments
 (0)