templatized delegate
Stanislav Blinov via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue May 23 09:38:14 PDT 2017
On Tuesday, 23 May 2017 at 11:45:13 UTC, Alex wrote:
> On Tuesday, 23 May 2017 at 11:05:09 UTC, Stanislav Blinov wrote:
>> void variadic(Args...)(auto ref Args args) { /* ... */ }
>>
>> This infers whether you pass lvalues or rvalues. If passing
>> further down the chain of such calls is needed, one can use
>> std.functional : fowrard :
>
> yes...
>
>>
>> void variadic(Args...)(auto ref Args args) {
>> import std.functional : forward;
>> doStuff(forward!args);
>> }
>>
>> void doStuff(Args...)(auto ref Args args) {
>> /* ... */
>> }
>>
>> 'forward' aliases ref arguments (i.e. passed lvalues) and
>> moves value arguments (i.e. passed rvalues).
>>
>> If a value is not copyable, it may be move-able (check the
>> docs though, it may not be that either).
>>
>> void fun(Args...)(auto ref Args args) { /*...*/ }
>
> yes...
>
>> import std.algorithm : move;
>>
>> auto a = NonCopyable(42);
>>
>> fun(move(a));
>> // or:
>> func(NonCopyable(42));
>
> the problem, that I have is, that I would like to use the
> templated approach, but I don't have the function, but only a
> delegate, so:
>
> template(T, U...)
> {
> void delegate(ref T neededInput, ref U ignoredInput) dgPtr;
> }
>
> Not sure, if this is possible to handle at all...
Ah, now I think I get it. You want to store a single delegate
that could be called with different sets of arguments? No, you
can't do that: you need an actual delegate instance, and for
that, you need to know the signature, at least when instantiating
C.
More information about the Digitalmars-d-learn
mailing list