[cfe-dev] RFC: A mechanism for importing a declaration only when it exists

David Chisnall via cfe-dev cfe-dev at lists.llvm.org
Fri Jun 26 02:34:41 PDT 2020

On 26/06/2020 05:05, Louis Dionne via cfe-dev wrote:
> Now, I understand this raises several questions. Of course, this couldn't be
> done at the preprocessor level because I don't think we can know whether a
> declaration exists at that time. However, I was curious to ask on this list
> whether someone could think of a reasonable way to solve this problem.
> Having some mechanism for doing this would be a huge life improvement for libc++.

I agree that something like this would be incredibly useful.  I wonder 
if it's sufficient to provide a built-in type trait and write something 

using FILE = std::conditional<__type_exists_v<::FILE>, ::FILE, void>;

(With some built-in equivalent of std::conditional that does 
short-circuit evaluation)  You'd still have the std::FILE type, but it 
would be void on platforms where it didn't exist.  Would this be 


More information about the cfe-dev mailing list