Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are "not, and, or, not_eq.." part of the C++ standard? (And why might they be used or avoided in code?)

Tags:

c++

syntax

So it looks like all these: http://www.cplusplus.com/reference/clibrary/ciso646/ are keywords in c++.

My question is. Is this a part of the c++ standard?

Can I rely on this to be supported by major compilers? I know gcc does support these keywords.

Finally, perhaps this is more a preference or style question, but are there any advantages to using the keywords over the standard operators (!, !=, && ... etc)?

like image 735
anio Avatar asked Jul 20 '12 16:07

anio


1 Answers

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).

like image 139
Konrad Rudolph Avatar answered Nov 15 '22 06:11

Konrad Rudolph