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

后端 未结 5 1786
無奈伤痛
無奈伤痛 2021-01-12 23:44

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?

Ca

5条回答
  •  感情败类
    2021-01-13 00:28

    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 (which is a standard header that’s empty on complying C++ implementations, but adds macros for the operators on MSVC).

提交回复
热议问题