On 2010-05-05 14:04:13 -0400, Walter Bright <[email protected]> said:

bearophile wrote:
I have to use a syntax like this often enough inside
unittests:

static assert(!__traits(compiles, foo(10)));

But why? Just use:

    foo(10);

To put it more simply than bearophile:

        foo(10);
        // gives you an error when foo(10) does *not* compile

        static assert(!__traits(compiles, foo(10)));
        // gives you an error when foo(10) compiles with no error
        // (notice the negation operator "!")

It is sometime a good idea to assert that a template cannot be instantiated with bogus arguments.

--
Michel Fortin
[email protected]
http://michelf.com/

Reply via email to