cpp/language/operator other

Explanation
The function call operator provides function semantics for any object.

The conditional operator (colloquially referred to as ternary conditional) checks the boolean value of the first expression and, depending on the resulting value, evaluates and returns either the second or the third expression.

Built-in function call operator
The function call expressions have the form

where
 * is an expression that names a
 * ... is a possibly empty list of arbitrary expressions, except the comma operator is not allowed at the top level to avoid ambiguity.

The expression that names the function can be @a@ lvalue expression that refers to a function @b@ pointer to function @c@ explicit expression that selects a member function @d@ implicit class member access expression, e.g. member function name used within another member function.

The function (or member) name specified by can be overloaded,  rules used to decide which overload is to be called.

If specifies a member function, it may be virtual, in which case the final overrider of that function will be called, using dynamic dispatch at runtime.

To call the function,

Each function parameter is initialized with its corresponding argument after if necessary. If there is no corresponding argument, the corresponding is used, and if there is none, the program is ill-formed. If the call is made to a member function, then the pointer to current object is converted as if by explicit cast to the  pointer expected by the function. The initialization and destruction of each parameter occurs in the context of the caller, which means, for example, that if constructor of a parameter throws an exception, the exception handlers defined within the function, even as a function-try block, are not considered. If the function is a variadic function, are applied to all arguments matched by the ellipsis parameter. It is implementation-defined whether the of a parameter ends when the function in which it is defined returns or at the end of the enclosing full-expression.

The return type of a function call expression is the return type of the chosen function, decided using static binding (ignoring the keyword), even if the overriding function that's actually called returns a different type. This allows the overriding functions to return pointers or references to classes that are derived from the return type returned by the base function, i.e. C++ supports covariant return types. If specifies a destructor, the return type is.

The value category of a function call expression is lvalue if the function returns an lvalue reference or an rvalue reference to function, is an xvalue if the function returns an rvalue reference to object, and is a prvalue otherwise. If the function call expression is a prvalue of object type, it must have complete type except when used as the operand of  (or as the right operand of a built-in comma operator that is the operand of ).

Function call expression is similar in syntax to value initialization, to expression , and to direct initialization of a temporary , where  is the name of a type.

Built-in comma operator
The comma operator expressions have the form

In a comma expression, the expression is evaluated, its result is  (although if it has class type, it won't be destroyed ), and its side effects are completed before evaluation of the expression  begins.

The type, value, and value category of the result of the comma expression are exactly the type, value, and value category of the second operand,. If is a temporary, the result of the expression is that temporary. If is a bit-field, the result is a bit-field.

The comma in various comma-separated lists, such as function argument lists and initializer lists, is not the comma operator. If the comma operator needs to be used in such contexts, it has to be parenthesized:.

Conditional operator
The conditional operator expressions have the form

The first operand of the conditional operator is evaluated and to. After both the value evaluation and all side effects of the first operand are completed, if the result was, the second operand is evaluated. If the result was, the third operand is evaluated.

The type and value category of the conditional expression are determined according to the following rules:

@1@ If either or  has type, then one of the following must be true, or the program is ill-formed:
 * @1.1@ Either or  (but not both) is a (possibly parenthesized) . The result of the conditional operator has the type and the value category of the other expression. If the other expression is a, the result is a bit-field. Such conditional operator was commonly used in C++11  prior to C++14.


 * @1.2@ Both and  are of type  (including the case when they are both throw-expressions). The result is a prvalue of type.

@2@ Otherwise, if or  are glvalue bit-fields of the same value category and of types cv1 T and cv2 T, respectively, the operands are considered to be of type cv T for the remainder of this section, where cv is the union of cv1 and cv2. @3@ Otherwise, if and  have different types, at least one of which is a (possibly cv-qualified) class type, or both are glvalues of the same value category and have the same type except for cv-qualification, then an attempt is made to form an  ignoring member access, whether an operand is a bit-field, as described below. An operand (call it ) of type can be converted to the target type of the other operand (call it ) of type  as follows:
 * @3.1@ If is an lvalue, the target type is, and the reference must bind directly to.


 * @3.3@ If is, or if neither the above conversion sequences can be formed and at least one of  and  is a (possibly cv-qualified) class type,
 * @3.3.1@ if and  are the same class type (ignoring cv-qualification) and  is at least as cv-qualified as, the target type is ,
 * @3.3.2@ otherwise, if is a base class of, the target type is  with the cv-qualifiers of :


 * @3.3.3@ otherwise, the target type is the type that would have after applying the lvalue-to-rvalue, array-to-pointer, and function-to-pointer.
 * @3.4@ If both sequences can be formed ( to target type of and  to target type of ), or only one can be formed but it is the ambiguous conversion sequence, the program is ill-formed.
 * @3.5@ If exactly one conversion sequence can be formed (note that it may still be ill-formed e.g. due to access violation), that conversion sequence is applied and the converted operand is used in place of the original operand for the remained of this description (starting at ).
 * @3.6@ If no conversion sequence can be formed, the operands are left unchanged for the remainder of this description.

@4@ If and  are glvalues of the same type and the same value category, then the result has the same type and value category, and is a bit-field if at least one of  and  is a bit-field. @5@ Otherwise, the result is a prvalue. If and  do not have the same type, and either has (possibly cv-qualified) class type, overload resolution is performed using the built-in candidates below to attempt to convert the operands to built-in types. If the overload resolution fails, the program is ill-formed. Otherwise, the selected conversions are applied and the converted operands are used in place of the original operands for step 6. @6@ The lvalue-to-rvalue, array-to-pointer, and function-to-pointer conversions are applied to the second and third operands. Then,
 * @6.1@ If both and  now have the same type, the result is a prvalue of that type  copy-initialized from whatever operand was selected after evaluating.
 * @6.2@ If both and  have arithmetic or enumeration type: the  are applied to bring them to common type, and that type is the result.
 * @6.3@ If both and  are pointers, or one is a pointer and the other is a null pointer constant, then pointer conversions and qualification conversions are applied to bring them to common type, and that type is the result.


 * @6.4@ If both and  are pointers to members, or one is a pointer to member and the other is a null pointer constant, then pointer-to-member conversions and qualification conversions are applied to bring them to common type, and that type is the result.


 * @6.5@ If both and  are null pointer constants, and at least one of which is of type std, then the result's type is.
 * @6.6@ In all other cases, the program is ill-formed.

For every pair of promoted arithmetic types and  and for every type, where  is a pointer, pointer-to-member, or scoped enumeration type, the following function signatures participate in the overload resolution performed in step 5 of the rules above:

where LR is the result of performed on  and. The operator “” cannot be overloaded, these function signatures only exist for the purpose of overload resolution.

The return type of a conditional operator is also accessible as the binary type trait std.

Standard library
Many classes in the standard library overload to be used as function objects.

The comma operator is not overloaded by any class in the standard library. The boost library uses in boost.assign, boost.spirit, and other libraries. The database access library SOCI also overloads.