Debian Codegraph @

clang-tools-extra/docs/clang-tidy/checks/readability/operators-representation.rst

raw
1 .. title:: clang-tidy - readability-operators-representation
2
3 readability-operators-representation
4 ====================================
5
6 Enforces consistent token representation for invoked binary, unary and
7 overloaded operators in C++ code. The check supports both traditional and
8 alternative representations of operators, such as ``&&`` and ``and``, ``||``
9 and ``or``, and so on.
10
11 In the realm of C++ programming, developers have the option to choose between
12 two distinct representations for operators: traditional token representation
13 and alternative token representation. Traditional tokens utilize symbols,
14 such as ``&&``, ``||``, and ``!``, while alternative tokens employ more
15 descriptive words like ``and``, ``or``, and ``not``.
16
17 In the following mapping table, a comprehensive list of traditional and
18 alternative tokens, along with their corresponding representations,
19 is presented:
20
21 .. table:: Token Representation Mapping Table
22 :widths: auto
23
24 =========== ===========
25 Traditional Alternative
26 =========== ===========
27 ``&&`` ``and``
28 ``&=`` ``and_eq``
29 ``&`` ``bitand``
30 ``|`` ``bitor``
31 ``~`` ``compl``
32 ``!`` ``not``
33 ``!=`` ``not_eq``
34 ``||`` ``or``
35 ``|=`` ``or_eq``
36 ``^`` ``xor``
37 ``^=`` ``xor_eq``
38 =========== ===========
39
40 Example
41 -------
42
43 .. code-block:: c++
44
45 // Traditional Token Representation:
46
47 if (!a||!b)
48 {
49 // do something
50 }
51
52 // Alternative Token Representation:
53
54 if (not a or not b)
55 {
56 // do something
57 }
58
59 Options
60 -------
61
62 Due to the distinct benefits and drawbacks of each representation, the default
63 configuration doesn't enforce either. Explicit configuration is needed.
64
65 To configure check to enforce Traditional Token Representation for all
66 operators set options to `&&;&=;&;|;~;!;!=;||;|=;^;^=`.
67
68 To configure check to enforce Alternative Token Representation for all
69 operators set options to
70 `and;and_eq;bitand;bitor;compl;not;not_eq;or;or_eq;xor;xor_eq`.
71
72 Developers do not need to enforce all operators, and can mix the representations
73 as desired by specifying a semicolon-separated list of both traditional and
74 alternative tokens in the configuration, such as `and;||;not`.
75
76 .. option:: BinaryOperators
77
78 This option allows you to specify a semicolon-separated list of binary
79 operators for which you want to enforce specific token representation.
80 The default value is empty string.
81
82 .. option:: OverloadedOperators
83
84 This option allows you to specify a semicolon-separated list of overloaded
85 operators for which you want to enforce specific token representation.
86 The default value is empty string.