Boost logo

Boost :

Subject: Re: [boost] the 'not' keyword
From: lcaminiti (lorcaminiti_at_[hidden])
Date: 2011-10-03 09:35:37


Darren Garvey-3 wrote:
>
>> This might not be a "pure" Boost question but do you know if compilers
>> portably support the 'not' keyword?
>>
>> int main ( ) {
>> if(not false) return 0;
>> return 1;
>> }
>>
>> This compiles on GCC but not on MSVC... Why? If you look at the C++
>> standard, it says that 'not' is part of the language...
>
> I'm not sure why you didn't ask this question on comp.std.c++ instead,
> but...
>

I know... thanks for answering anyways :)

> MSVC requires you #include <ciso646> to get the keyword alternatives,
> although I've no idea why (since I've recently started to like them).
>
> IIRC, you can also pass /Za to the compiler to disable MS extensions,
> which
> will then re-enable these keywords. Again, don't ask me.
>

OK, thanks! I'll use #include <ciso646>.

> One thing I'm a little curious about is whether the keywords are allowed
> in
> Boost libraries.
>

I want to explain why I asked. In Boost.Contract there is a limitation that
every assertion must start with an alphanumeric token a-z, A-Z, 0-9 (because
the assertion tokens are inspected by the pp to distinguish between normal
assertions, static_assert ..., const ..., if..., using ..., namespace ...,
typedef ..., etc and the pp inspection relies on concatenating the assertion
tokens with a special macro identifier SPECIAL_ID ## assertion-tokens).
Therefore, the following assertion expression will generate a pp error
because of the leading non-alphanumeric token `!`:

precondition( !empty() )

This is actually not a big deal at all because programmers can simply
rewrite such an assertion in any of the following ways that will all compile
with Boost.Contract:

precondition( not empty() )
precondition( bool(!empty()) )
precondition( empty() == false )

Now, `bool(!empty())` is the most general (it will work with /any/ assertion
expression, for example precondition( *this == *result ) /* error */ -->
precondition( bool(*this == *result) ) /* ok */) but I find `not empty()` to
be the most readable-- as long it is portably supported by compilers, hence
my question.

Thanks a lot!
--Lorenzo

--
View this message in context: http://boost.2283326.n4.nabble.com/the-not-keyword-tp3865759p3867513.html
Sent from the Boost - Dev mailing list archive at Nabble.com.

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