Standard Library Applications for Explicit Conversion Operators

Document Number: N2293(07-0153)
Alisdair Meredith <>

Background and Rationale

One feature of the next version of the C++ Language will be Explicit Conversion operators, as descibed originally in n1592. One of the key motivating examples is to simplify the 'conversion to unspecified bool' idiom. (Note: Core wording is being updated to allow explicit bool conversions to work where the language requires them, such as evaluating if statements, and as arguments to && and || operators.)

This paper proposes to replace all use of unspecified-bool-type with explicit bool conversion operators. This will simplify the library clauses and aid clarity by removing pseudo-code from normative signatures and simpliying the associated explanatory text. In particular, note that hole in the type system that [func.wrap.func.undef] works around is closed, removing the whole clause.

On the other hand, it deliberately leaves the operator bool() conversion function for the vector<bool> and bitset proxy classes as implicit.

While this paper has no suggested applications of the feature beyond boolean conversions, the committee might want to explore explicit pointer conversion operators for the library smart pointers.

The paper would also resolve LWG issues 644 and 686 as NAD.

(A couple of Minor editorial nits (typos etc) are also fixed without comment.)

Proposed Changes to Working Draught (n2284)