
Hello all, 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... Thanks a lot. --Lorenzo -- Sent from my mobile device Lorenzo

Hi Lorenzo, On 2 October 2011 21:15, Lorenzo Caminiti <lorcaminiti@gmail.com> 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... 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. One thing I'm a little curious about is whether the keywords are allowed in Boost libraries. Cheers, Darren

[Darren Garvey]
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.
/Za is buggy and breaks conformant code (e.g. vector<unique_ptr<T>>). We recommend against using it, and we no longer test the C++ Standard Library with it. Stephan T. Lavavej Visual C++ Libraries Developer

MSVC requires you #include<ciso646> to get the keyword alternatives, although I've no idea why (since I've recently started to like them). I, too, have started to like the operator keywords -- at least for the logical operators (this bitwise operators not so much). I strive for a
On 10/02/2011 03:33 PM, Darren Garvey wrote: literate programming style and have become used to having these in other languages. They help bring the logical structure of an expression into focus, especially when combining both bitwise and logical operators in a single expression.
One thing I'm a little curious about is whether the keywords are allowed in Boost libraries.
Part of Boost's legacy is in pushing compiler vendors towards more rigorous standards compliance. At a minimum I would hope the Boost community would be neutral towards their use. Rob

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.

On Sun, Oct 2, 2011 at 1:15 PM, Lorenzo Caminiti <lorcaminiti@gmail.com>wrote:
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...
Because MSVC is non-compliant in this regard (surprise surprise). You can #include <ciso646>, the C++ version of C's <iso646.h>, where the alternate keywords originated. IIRC (cannot test right now), MSVC will define the alternate keywords C-style as macros, which is pretty close to how it should be (you may be able to #undef them). GCC's <ciso646> header is empty, as it should be. I'm not sure about other compilers. Do note that the use of these alternate keywords is quite unorthodox, and can be confusing to those who don't know about them. -- GMan, Nick Gorski

on Sun Oct 02 2011, Lorenzo Caminiti <lorcaminiti-AT-gmail.com> wrote:
Hello all,
This might not be a "pure" Boost question but do you know if compilers portably support the 'not' keyword?
Yes they do... or they used to.
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...
Huh; I don't know. -- Dave Abrahams BoostPro Computing http://www.boostpro.com
participants (7)
-
Darren Garvey
-
Dave Abrahams
-
GMan
-
lcaminiti
-
Lorenzo Caminiti
-
Rob Riggs
-
Stephan T. Lavavej