templatized delegate
Alex via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue May 23 04:45:13 PDT 2017
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...
More information about the Digitalmars-d-learn
mailing list