Perfect forwarding
Jean-Louis Leroy
jl at leroy.nyc
Thu Jul 30 11:53:13 UTC 2020
On Thursday, 30 July 2020 at 04:56:55 UTC, Petar Kirov
[ZombineDev] wrote:
> 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.
Yes I know. My original problem was:
// from
@attrs ref int foo(@otherattrs virtual!Foo obj1, lazy int var,
ref virtual!Bar obj2);
// make:
@attrs ref int foo(@otherattrs Foo obj1, lazy int var, ref Bar
obj2) {
return dispatch(obj1, obj2)(obj1, var, obj2);
}
Back to what you described, is it a real use case? I am thinking
of writing an article on function generation for the D blog. I
was wondering how often this sort of transformation is needed.
More information about the Digitalmars-d
mailing list