of "Conditional Implementation" vs "Assertive Input Validation"
dmitry.olsh at gmail.com
Mon Jul 23 06:39:31 PDT 2012
On 23-Jul-12 17:29, Philippe Sigaud wrote:
> On Mon, Jul 23, 2012 at 1:44 PM, Chris NS <ibisbasenji at gmail.com> wrote:
>> And for the curious, what I mean by embedding assertions in the conditions
>> is quite literally what it sounds like:
>> Range minPos ( Range ) ( Range R1 )
>> if( is( inputRange!Range ) )
>> assert( !isInfinite!Range, "minPos cannot operate on infinite ranges." )
> Would it be possible to create a If / Assert template that returns
> (er, becomes) true if the condition is true, and static asserts if not
Will explode every time a constraint is tested?
After all constraints do fail so that other function is picked up and
they are supposed to.
> template Assert(bool condition, string message)
> static if (condition)
> enum Assert = true;
> static assert(false, message);
> void foo(T,U)(T t, U u) if (is(T == int) && Assert!(isIntegral!U, "U
> must be an integer type"))
> void main()
> Seems to work (tm).
More information about the Digitalmars-d