88 lines · plain
1.. title:: clang-tidy - readability-operators-representation2 3readability-operators-representation4====================================5 6Enforces consistent token representation for invoked binary, unary and7overloaded operators in C++ code. The check supports both traditional and8alternative representations of operators, such as ``&&`` and ``and``, ``||``9and ``or``, and so on.10 11In the realm of C++ programming, developers have the option to choose between12two distinct representations for operators: traditional token representation13and alternative token representation. Traditional tokens utilize symbols,14such as ``&&``, ``||``, and ``!``, while alternative tokens employ more15descriptive words like ``and``, ``or``, and ``not``.16 17In the following mapping table, a comprehensive list of traditional and18alternative tokens, along with their corresponding representations,19is presented:20 21.. table:: Token Representation Mapping Table22 :widths: auto23 24 =========== ===========25 Traditional Alternative26 =========== ===========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 40Example41-------42 43.. code-block:: c++44 45 // Traditional Token Representation:46 47 if (!a||!b)48 {49 // do something50 }51 52 // Alternative Token Representation:53 54 if (not a or not b)55 {56 // do something57 }58 59Options60-------61 62Due to the distinct benefits and drawbacks of each representation, the default63configuration doesn't enforce either. Explicit configuration is needed.64 65To configure check to enforce Traditional Token Representation for all66operators set options to `&&;&=;&;|;~;!;!=;||;|=;^;^=`.67 68To configure check to enforce Alternative Token Representation for all69operators set options to70`and;and_eq;bitand;bitor;compl;not;not_eq;or;or_eq;xor;xor_eq`.71 72Developers do not need to enforce all operators, and can mix the73representations as desired by specifying a semicolon-separated list of74both traditional and alternative tokens in the configuration,75such as `and;||;not`.76 77.. option:: BinaryOperators78 79 This option allows you to specify a semicolon-separated list of binary80 operators for which you want to enforce specific token representation.81 The default value is empty string.82 83.. option:: OverloadedOperators84 85 This option allows you to specify a semicolon-separated list of overloaded86 operators for which you want to enforce specific token representation.87 The default value is empty string.88