Perfect forwarding
Jean-Louis Leroy
jl at leroy.nyc
Wed Jul 29 16:31:08 UTC 2020
On Wednesday, 29 July 2020 at 16:11:02 UTC, Petar Kirov
[ZombineDev] wrote:
> On Wednesday, 29 July 2020 at 12:54:36 UTC, Adam D. Ruppe wrote:
>> On Wednesday, 29 July 2020 at 10:38:29 UTC, Manu wrote:
>>> On Wed, Jul 29, 2020 at 9:40 AM Jean-Louis Leroy via
>>>> Guaranteed failure then? ;-)
>>>
>>> Yes.
>>
>> What's wrong with my solution earlier in the thread?
>
> That it uses a string mixin :P
>
> What Manu is arguing is that if parameter storage classes were
> instead proper type qualifiers, then one could trivially
> manipulate them with std.meta. And then supposedly there would
> be no need to string mixins at all.
If we go back to the original problem, you still need a string
mixin to inject the function name in two places.
As for Adam's solution, it solves a slightly different problem
but I don't see why he uses a string mixin:
template forward(alias fun)
{
import std.traits;
@(__traits(getAttributes, fun)) auto ref
forward(Parameters!fun args) {
return fun(args);
}
}
@(42) void myfun(int, ref double x, out string s);
pragma(msg, typeof(forward!myfun));
// void function(int _param_0, ref double _param_1, out string
_param_2) @system
pragma(msg, __traits(getAttributes, forward!myfun));
// tuple(42)
Anyway, storage classes are not a difficulty, as long as you use
the whole __parameters, or slice it (__parameters[0..1]), and
refrain from indexing it (__parameters[0] loses storage classes).
Strange beast...
More information about the Digitalmars-d
mailing list