Immediate Context in C 11 Template Substitution
The C 11 Standard introduces Substitution Failure Is Not An Error (SFINAE), which allows for the suppression of hard compilation errors during template argument substitution. However, the standard defines a specific "immediate context" for which SFINAE applies, leaving some uncertainty about when a substitution error results in a hard or soft error.
Immediate Context Definition
The Standard defines the immediate context as:
"Only invalid types and expressions in the immediate context of the function type and its template parameter types can result in a deduction failure."
This definition is vague, but a non-normative note provides a hint:
"The evaluation of the substituted types and expressions can result in side effects such as... Such side effects are not in the “immediate context” and can result in the program being ill-formed."
Decision Procedure
To determine whether a substitution error occurs in the immediate context, consider the following decision procedure:
Examples
Conclusion
By understanding the concept of immediate context and using the above decision procedure, programmers can better predict when substitution errors will result in hard or soft errors, enabling more effective use of SFINAE in C 11 templates.
The above is the detailed content of What Determines Whether a C 11 Template Substitution Error Is a Hard or Soft Error?. For more information, please follow other related articles on the PHP Chinese website!