Great forwarding to D?

tl; dr: How do you do great redirects to D?


The link has a great explanation, but, for example, let's say I have this method:

void foo(T)(in int a, out int b, ref int c, scope int delegate(ref const(T)) d) const nothrow { } 

How to create another method bar() , which can be called instead of foo() , which subsequently calls foo() "excellent" (that is, without introducing the compilation problem / scope / etc on the calling site)

Naive approach

 auto bar(T...)(T args) { writeln("foo() intercepted!"); return foo(args); } 

of course does not work, because it does not process the ref , in , out , inout , const -ness of the method, pure -ity, nothrow , etc., and also limits how values ​​can be used with r values.

And I don't know how to handle these possible cases ... any ideas?

+6
source share
1 answer

Your naive approach can be improved, although it is still not perfect:

 auto ref bar(T...)(auto ref T args) { writeln("foo() intercepted!"); return foo(args); } 

Now the only problem is scope arguments.

+3
source

Source: https://habr.com/ru/post/900397/


All Articles