Are "not, and, or, not_eq.." part of the C++ standard? (And why might they be used or avoided in code?)
My question is. Is this a part of the c++ standard?
Yes.
Can I rely on this to be supported by major compilers?
Yes. But MSVC doesn’t support this by default, you need to pass it the option /permissive-
(or, though this is buggy and outdated, /Za
), which disables Microsoft language extensions. It seems a good idea to enable this option for almost all C++ projects anyway, it’s just a shame it’s off by default.
but are there any advantages to using the keywords over the standard operators
In general, no. But in the case of and
, or
, not
, many (though probably not most) people find it more readable. Personally I recommend using them.
If you absolutely want the code to compile on MSVC without the /permissive-
flag, #include <ciso646>
(which is a standard header that’s empty on complying C++ implementations, but adds macros for the operators on MSVC).
Is this a part of the c++ standard?
Yes. See the table in section [lex.digraph].
Are there any advantages to using the keywords over the standard operators?
My understanding is that the original digraphs (<%
instead of {
, etc.) were introduced to allow people with simple keyboards to be able to write C code (Wikipedia corroborates this). Perhaps the same rationale applies for not_eq
, etc. But AFAIK, there is no good reason to write such stuff nowadays (unless you're coding on your smartphone), not least because 99% of programmers don't know it's valid C++!
Yes, they are supported.
In terms of the second half of your question they can lead to more readable code especially when dealing with bitwise operators as well as logical operations at the same time for example:
if( a & 1 == 0 || c | a == 2 );
vs
if( a & 1 == 0 or c | a == 2 );