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:
defined
identifierdefined (
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
defined
identifier
or
defined (
identifier)
which evaluateA defined-macro-expression evaluates to1
if the identifier is currently defined as a macro name (that is, if it is predefined or if it has been the subject of a#define
preprocessing directive without an intervening#undef
directive with the same subject identifier),0
if 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
#include
directive, except that no further macro expansion is performed. If such a directive would not satisfy the syntactic requirements of a#include
directive, the program is ill-formed. The has-include-expression evaluates to1
if the search for the source file succeeds, and to0
if the search fails.The
#ifdef
and#ifndef
directives, and thedefined
conditional inclusion operator, shall treat__has_include
as if it were the name of a defined macro. The identifier__has_include
shall 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 fordefined
unary operatortrue
andfalse
, 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
optional
facility 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 ]