C++ Logo

liaison

Advanced search

Re: [wg14/wg21 liaison] a common C/C++ core specification

From: Jens Gustedt <jens.gustedt_at_[hidden]>
Date: Tue, 10 Mar 2020 20:54:25 +0100
Florian,

on Tue, 10 Mar 2020 20:16:21 +0100 you (Florian Weimer
<fw_at_[hidden]>) wrote:

> > Basically what the user has to write here is one line per type,
> > which is very concise and fits on one screen with a "tabular"
> > layout (type left, expression right). For C++ the generated code is
> > 9 overloaded functions and a template for the default case. This
> > boiler plate introduces a lot of possibilities for mistakes.
>
> That may be so, but you simply cannot use these lists in cases where
> any macro parameter is expanded more than once. Even for the default
> case in your example, you probably would have to use some lambda
> construct to capture the type of X, or you risk running into the same
> macro explosion issue we encountered with the original <tgmath.h>
> implementation in glibc.

the `generic_type` used there does not evaluate its argument, it comes
from 6.10.8.3, mandatory type macros

But sure you are right that macros are not ideal because this type of
problems

> Do you think there is a mechanical way to capture types and values so
> that each macro argument is expanded exactly once? Perhaps using
> lambdas?

Yes, exactly, you could have a lambda having such a generic selection
as return expression. This then receives the user's expression through
a normal function parameter, so the expression would only be evaluated
once when passed into the lambda. Then with an "auto" lambda the
return type is still driven by the type of the selected expression.

Since lambdas are `constexpr` whenever they may, this works out for
most use cases. (All of the `constexpr` stuff is not yet worked out, I
still have to address that, this is a big chunk.)

Jens

-- 
:: INRIA Nancy Grand Est ::: Camus ::::::: ICube/ICPS :::
:: ::::::::::::::: office Strasbourg : +33 368854536   ::
:: :::::::::::::::::::::: gsm France : +33 651400183   ::
:: ::::::::::::::: gsm international : +49 15737185122 ::
:: http://icube-icps.unistra.fr/index.php/Jens_Gustedt ::

Received on 2020-03-10 14:57:14