assert() vs. enforce(), invariant() vs. ... ?
Jacob Carlborg
doob at me.com
Thu Aug 29 06:26:32 PDT 2013
On 2013-08-29 13:19, Joseph Rushton Wakeling wrote:
> So, I thought I'd throw the idea out there so that others can suggest
> whether this is potentially useful or whether it's better/safer to
> hand-code such checks on a function-by-function basis.
You can quite easily create a wrapper for that.
struct EnforceWrapper (T)
{
T t;
auto opDispatch (string name, Args ...) (Args args)
{
// before code
mixin("auto result = " ~ name ~ "(args);");
// after code
return result;
}
}
auto obj = EnforceWrapper!(Object)(new Object);
obj.toString();
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list