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

Whisperity via cfe-dev cfe-dev at lists.llvm.org
Fri Jun 26 05:08:38 PDT 2020


std::conditional should already not evaluate the "other" "branch" depending
on the condition. I'm not exactly sure about what you mean by
short-circuiting otherwise.

I like this builtin idea, however, there is a slight catch: what the
argument for __builtin_has_type or __builtin_type_exists is, syntactically?
A name? An elaborated name? It will end up having to be a sort of "super
unevaluated context" and that might make parsing it a bit of a hell...

All type_traits so far expect their template argument T to *be* a type.

In addition, what happens if your condition evaluates to:
    using FILE = void;

This still makes "std::FILE" a thing, which will cause weird issues later
on, unless the rest of the library is defended against each of these cases.
Which seems even more tedious work.


David Chisnall via cfe-dev <cfe-dev at lists.llvm.org> ezt írta (időpont:
2020. jún. 26., P, 11:34):

> 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
> like:
>
> 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
> sufficient?
>
> David
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200626/189c4788/attachment.html>


More information about the cfe-dev mailing list