Perfect forwarding

Petar Petar
Thu Jul 30 05:40:28 UTC 2020


On Thursday, 30 July 2020 at 04:56:55 UTC, Petar Kirov 
[ZombineDev] wrote:
> On Wednesday, 29 July 2020 at 16:31:08 UTC, Jean-Louis Leroy 
> wrote:
>> [...]
>
> My point, that you can't do much useful processing with 
> `__parameters` (except pass all of subset of it), still stands.
>
> Say you have a function with N parameters. Some of those 
> parameters are integers and may have a UDA attached to them 
> that specifies the minimum and maximum value they may receive. 
> For example:
>
> R fun(
>   scope P1 arg1,
>   return int* arg2,
>   lazy @intetval(-16, 320) long arg3,
>   @interval(0, 127) uint arg4,
>   ref @interval(0, 8192) size_t arg5
> );
>
> The task is create a template, which given a function type like 
> typeof(&fun) returns a new function type with all integer 
> parameters replaced by the smallest type that is big enough to 
> hold the interval specified by the UDA and preserves all 
> storage classes.
>
>
> R hun(
>   scope P1 arg1,
>   return int* arg2,
>   lazy @intetval(-16, 320) short arg3,
>   @interval(0, 127) ubyte arg4,
>   ref @interval(0, 8192) ushort arg5
> );
>
> The way I'd like to go about solving this is like this:
>
> template TightenIntegerParams(Fun)
> {
>   alias TightenIntegerParams =
>     ReturnType!Fun function(
>       staticMap!(
>         TightenParam,
>         Parameters!Fun
>       )
>     );
> }
>
> However the moment staticMap internally does `Args[i]` in order 
> to pass the i-th element to the mapping function `F` we lose 
> all information about the storage classes and UDAs.

I now saw that Manu clarified what he meant.

Also I do realize that what we actually need is for 
`Parameters!fun[0]` to return a parameter object that includes 
not just the type but also the parameter name, UDAs attached and 
storage classes. If for example `ref` was a type qualifier, or 
just otherwise preserved by `alias`-ing it would help, but not 
solve the whole issue.


More information about the Digitalmars-d mailing list