Copy parameters from function passed as an alias
bauss
jj_1337 at live.dk
Thu Oct 11 06:30:01 UTC 2018
On Wednesday, 10 October 2018 at 18:15:52 UTC, Paul Backus wrote:
> On Wednesday, 10 October 2018 at 12:10:06 UTC, bauss wrote:
>> On Wednesday, 10 October 2018 at 08:16:11 UTC, Kagamin wrote:
>>> How do you want to use parameter names of an arbitrary
>>> function?
>>
>> What I want to do is pass a function to a template and that
>> template creates a function with the same parameters as the
>> function passed to it, if it wasn't clear.
>>
>> I can already do that if you see my examples, BUT it's not
>> pretty.
>
> I suppose the question is, why is your first example
> inadequate? In other words, why is it important that the
> parameters of the generated function have the same names as the
> original parameters?
Because I'm constructing something from the parameters.
To give the real world example.
I'm converting a function into a soap envelope which means the
identifiers must be the same because the parameter names passed
in the soap envelope must have the same names.
Basically what I wanted was something like:
SoapEnvelope toEnvelope(alias fun)(...); // where ... is the
parameters of fun
The toEnvelope function then constructs the envelope based on the
function name and the parameters.
Within the "fun" function the soap envelope is constructed at
compile-time and then simply sends the envelope to the soap
client.
It's a bit more complex than that, but it should give you the
idea.
If the parameter names do not match the given function then the
parameters passed to the soap envelope's body will be invalid and
thus of course rejected by the web service.
I have it working with the ugly example I've given using the
template and the mixin, but it's no ideal because first of all
it's not pretty, it's difficuly to debug because well you can't
place any breakpoints within the function simply because the
function body is a string and at last it's just everything but
easy to maintain.
If there was something like "CopyParameters!fun" then it'd be so
much easier, but unfortunately there are only two choices here.
"Parameters!fun" will just give you the parameter types and
"ParameterIdentifierTuple!fun" will give you the parameter
identifiers. The problem is that when you want to construct the
parameters you can't really combine both of them without the last
example I've given and that's the problem.
The second example I gave would be okay, because you'd only have
to maintain the parameter mixin, but the first example would be
best because there are no mixins involved at all then. The last
example is pretty much a last resort and pretty much undesirable.
More information about the Digitalmars-d-learn
mailing list