[Issue 10396] Optional, simplified syntax for simple contracts
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Jun 19 13:00:53 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10396
Marco Leise <Marco.Leise at gmx.de> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |Marco.Leise at gmx.de
--- Comment #1 from Marco Leise <Marco.Leise at gmx.de> 2013-06-19 13:00:50 PDT ---
There I fixed it: http://dpaste.1azy.net/2ec082c0 :)
--- 8< ------------------
string holds(string expr, string expl = null)
{
import std.array : split;
import std.string : strip;
expr = strip(expr);
string vars;
bool[string] processed;
foreach (token; split(expr)) if (token.length && token !in processed)
{
if (token[0] == '.' || token[0] >= 'A') {
if (vars !is null) vars ~= ", ";
vars ~= token ~ ` = " ~ to!string(` ~ token ~ `) ~ "`;
processed[token] = true;
}
}
if (expl) expl = " " ~ expl ~ ";";
return `import std.conv : to; import std.array : join; import std.typetuple
: ParameterIdentifierTuple; `
~ `assert(` ~ expr ~ `, __FUNCTION__ ~ "(" ~
join([ParameterIdentifierTuple!(mixin(__FUNCTION__))], ", ") ~ "):` ~ expl ~ `
(` ~ expr ~ `)` ~ ` failed with ` ~ vars ~ `");`;
}
void foo(uint x, uint y)
in { mixin(q{ x > y && x < 10 }.holds("x must be a digit larger than y")); }
body {}
void main()
{
foo(2, 3);
}
--- >8 ------------------
Prints:
foo(x, y): x must be a digit larger than y; (x > y && x < 10) failed with x =
2, y = 3
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list