Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-06-25 07:18:23


Christoph Ludwig wrote:
> On Thu, Jun 24, 2004 at 05:51:15PM +0200, Daniel Frey wrote:
>> Robert Ramey wrote:
>>> BOOST_STATIC_ASSERT(false)
>>
>> This *should* work. IMHO, if it doesn't, we should fix it, not work
>> around it like Michiel suggested.
>
> BOOST_STATIC_ASSERT(false) expands to a typedef that does not contain
> any dependent expression. I didn't check the detailed rules in my copy
> of the template book by Vandevoorde and Josuttis, but I think a
> compiler should check this typedef even if the function template is
> not instantiated.

The compiler is allowed but not required to reject a template that can never
produce a legal instantiation.

[...]

> I don't know if my solution (sizeof(T) && false) has any
> (dis-)advantages compared to Michiel's solution ((T*) 0).

A compiler is allowed to reject both. I think that you need one additional
level of indirection:

template<class T> struct always_false
{
    enum { value = 0 };
};

template<class T> struct always_assert
{
    BOOST_STATIC_ASSERT( always_false<T>::value );
};


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