От: | Masterkent | ||
Дата: | 22.04.10 12:45 | ||
Оценка: | 8 (1) |
U>Как из двух "implicit conversion sequences" найти наилучшую описывается здесьU>13.3.3.1.1 Standard conversion sequences
U>фрагмент из Table 9:
U>Conversion, Rank, Subclause
U>"Integral Promotion" Promotion 4.5
U>"Boolean conversions" Conversion 4.12
U>13.3.3.2 Ranking implicit conversion sequences
U>В двух словах: так как Promotion лучше, чем Conversion, то будет применяться Integral promotion и bool продвинется до int.U>Standard conversion sequences are ordered by their ranks: an Exact Match is a better conversion than a Promotion,
U>which is a better conversion than a Conversion.
Operator functions рассматриваются только если хотя бы один из операндов имеет классовый или перечислительный тип:An implicit conversion sequence is a sequence of conversions used to convert an argument in a function call to the type of the corresponding parameter of the function being called.
В данном же случае следует руководствоваться исключительно правилами для встроенных операторов, описанными в разделе 5:If either operand has a type that is a class or an enumeration, a user-defined operator function might be declared that implements this operator or a user-defined conversion can be necessary to convert the operand to a type that is appropriate for a built-in operator. In this case, overload resolution is used to determine which operator function or built-in operator is to be invoked to implement the operator. Therefore, the operator notation is first transformed to the equivalent function-call notation as summarized in Table 8
5.10/1:If no operand of an operator in an expression has a type that is a class or an enumeration, the operator is assumed to be a built-in operator and interpreted according to clause 5.
5.9 Relational operators /2:The == (equal to) and the != (not equal to) operators have the same semantic restrictions, conversions, and result type as the relational operators except for their lower precedence and truth-value result.
5/9:The usual arithmetic conversions are performed on operands of arithmetic or enumeration type.
4.5 Integral promotions /4:Many binary operators that expect operands of arithmetic or enumeration type cause conversions and yield result types in a similar way. The purpose is to yield a common type, which is also the type of the result. This pattern is called the usual arithmetic conversions, which are defined as follows:
— If either operand is of type long double, the other shall be converted to long double.
— Otherwise, if either operand is double, the other shall be converted to double.
— Otherwise, if either operand is float, the other shall be converted to float.
— Otherwise, the integral promotions (4.5) shall be performed on both operands. [Footnote: As a consequence, operands of type bool, wchar_t, or an enumerated type are converted to some integral type]
— Then, if either operand is unsigned long the other shall be converted to unsigned long.
— Otherwise, if one operand is a long int and the other unsigned int, then if a long int can represent all the values of an unsigned int, the unsigned int shall be converted to a long int; otherwise both operands shall be converted to unsigned long int.
— Otherwise, if either operand is long, the other shall be converted to long.
— Otherwise, if either operand is unsigned, the other shall be converted to unsigned.
An rvalue of type bool can be converted to an rvalue of type int, with false becoming zero and true becoming one.
От: | uzhas | ||
Дата: | 22.04.10 18:31 | ||
Оценка: |