Date: Tue, 10 Mar 2020 21:06:06 +0100
* Jens Gustedt via Liaison:
> 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 the preprocessor does. This is the core of the problem.
>> 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.
Okay, if the macro arguments are mentioned exactly once, this might
actually work. There is some additional boilerplate, but it may not
be too bad.
> 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 the preprocessor does. This is the core of the problem.
>> 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.
Okay, if the macro arguments are mentioned exactly once, this might
actually work. There is some additional boilerplate, but it may not
be too bad.
Received on 2020-03-10 15:10:31