| Doc. No.: | P0061R1 |
|---|---|
| Date: | 2015-10-23 |
| Reply to: | Clark Nelson |
| Richard Smith |
__has_include for C++17Replace paragraph 1 of 16.1 with several paragraphs, as follows:
- defined-macro-expression:
definedidentifierdefined (identifier)
- h-preprocessing-token:
- any preprocessing-token other than
>
- h-pp-tokens:
- h-preprocessing-token
- h-pp-tokens h-preprocessing-token
- has-include-expression:
__has_include ( <h-char-sequence> )__has_include ( "q-char-sequence" )__has_include (string-literal)__has_include ( <h-pp-tokens> )The expression that controls conditional inclusion shall be an integral constant expression except that identifiers (including those lexically identical to keywords) are interpreted as described below146 and it may contain zero or more defined-macro-expressions and/or has-include-expressions as unary operator expressions.
of the form
definedidentifier
or
defined (identifier)
which evaluateA defined-macro-expression evaluates to1if the identifier is currently defined as a macro name (that is, if it is predefined or if it has been the subject of a#definepreprocessing directive without an intervening#undefdirective with the same subject identifier),0if it is not.The third and fourth forms of has-include-expression are considered only if neither of the first or second forms matches, in which case the preprocessing tokens are processed just as in normal text.
The header or source file identified by the parenthesized preprocessing token sequence in each contained has-include-expression is searched for as if that preprocessing token sequence were the pp-tokens in a
#includedirective, except that no further macro expansion is performed. If such a directive would not satisfy the syntactic requirements of a#includedirective, the program is ill-formed. The has-include-expression evaluates to1if the search for the source file succeeds, and to0if the search fails.The
#ifdefand#ifndefdirectives, and thedefinedconditional inclusion operator, shall treat__has_includeas if it were the name of a defined macro. The identifier__has_includeshall not appear in any context not mentioned in this section.
Change 16.1p4:
... After all replacements due to macro expansion andtheevaluations of defined-macro-expressions and has-include-expressions have been performed, all remaining identifiers and keywords147, except fordefinedunary operatortrueandfalse, are replaced with the pp-number0, and then each preprocessing token is converted into a token. ...
Add the following example after 16.1p6:
[ Example: This demonstrates a way to include a library
optionalfacility only if it is available.#if __has_include(<optional>) # include <optional> # define have_optional 1 #elif __has_include(<experimental/optional>) # include <experimental/optional> # define have_optional 1 # define experimental_optional 1 #else # define have_optional 0 #endif— end example ]