Alternative operator representations

From cppreference.com
 
 
C++ language
General topics
Flow control
Conditional execution statements
Iteration statements
Jump statements
Functions
function declaration
lambda function declaration
function template
inline specifier
exception specifications (deprecated)
noexcept specifier (C++11)
Exceptions
Namespaces
Types
decltype specifier (C++11)
Specifiers
cv specifiers
storage duration specifiers
constexpr specifier (C++11)
auto specifier (C++11)
alignas specifier (C++11)
Initialization
Literals
Expressions
alternative representations
Utilities
Types
typedef declaration
type alias declaration (C++11)
attributes (C++11)
Casts
implicit conversions
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
C-style and functional cast
Memory allocation
Classes
Class-specific function properties
Special member functions
Templates
class template
function template
template specialization
parameter packs (C++11)
Miscellaneous
Inline assembly
 

C++ (and C) source code may be written in any non-ASCII 7-bit character set that includes the ISO 646:1983 invariant character set. However, several C++ operators and punctuators require characters that are outside of the ISO 646 codeset: {, }, [, ], #, \, ^, |, ~. To be able to use character encodings where some or all of these symbols do not exist (such as the German DIN 66003), C++ defines two kinds of alternatives: additional keywords that correspond to the operators that use these characters and special combinations of two or three ISO 646 compatible characters that are interpreted as if they were a single non-ISO 646 character.

Contents

[edit] Alternative keywords

There are alternative spellings for several operators defined as keywords in the C++ standard.

Primary Alternative
&& and
&= and_eq
& bitand
| bitor
~ compl
! not
!= not_eq
|| or
|= or_eq
^ xor
^= xor_eq

[edit] Compatibility with C

The same words are defined in the C programming language in the include file <iso646.h> as macros. Because in C++ these are language keywords, the C++ version of <iso646.h>, as well as <ciso646>, does not define anything.

[edit] Digraphs and trigraphs

The following combinations of two and three characters (digraphs and trigraphs) are valid substitutions for their respective primary characters:

Primary Digraph Trigraph
{ <% ??<
} %> ??>
[ <: ??(
] :> ??)
# %: ??=
\ ??/
^ ??'
| ??!
~ ??-

Note that trigraphs (but not digraphs) are parsed before comments and string literals are recognized, so a comment such as // Will the next line be executed?????/ will effectively comment out the following line, and the string literal such as "What's going on??!" is parsed as "What's going on|".

[edit] Keywords

and, and_eq, bitand, bitor, compl, not, not_eq, or, or_eq, xor, xor_eq

[edit] Example

The following example demonstrates the use of several alternative keywords:

%:include <iostream>
 
int main(int argc, char *argv<::>) 
<%
    if (argc > 1 and argv<:1:> not_eq '\0') <%
        std::cout << "Hello " << argv<:1:> << '\n';
    %>
%>