On 23-Jul-12 17:29, Philippe Sigaud wrote:
On Mon, Jul 23, 2012 at 1:44 PM, Chris NS <ibisbase...@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;
else
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()
{
foo(1,"a");
}
Seems to work (tm).
--
Dmitry Olshansky