Boost logo

Boost :

Subject: Re: [boost] C++11 challenge: ASSERT_INVALID_EXPR
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2011-12-05 08:44:09


On 12/04/2011 05:15 PM, Dave Abrahams wrote:
>
> I don't know whether this is actually possible, but I was thinking today
> that there might be a way to use the new SFINAE to detect errors in a
> large class of invalid expressions without actually causing a hard
> error, and thereby build an assertion that fails compilation when passed
> a valid expression and passes for any invalid expression in the large
> class mentioned above.
>
> Any takers?

Why not just something like

template<class T>
decltype(my_expr_that_depends_on_T, char) foo(int);

template<class T>
int foo(...);

static const bool valid = sizeof(foo<T>(0)) == sizeof(char);

BOOST_MPL_ASSERT(!valid, ...)

I suppose the problem with the macro will be to be able to find a nice
syntax to specify the template arguments the expression must depend on.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk