templatized delegate

9il via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue May 23 04:18:33 PDT 2017


On Tuesday, 23 May 2017 at 10:30:56 UTC, Alex wrote:
> On Monday, 22 May 2017 at 21:44:17 UTC, ag0aep6g wrote:
>> With that kind of variadics, you're not dealing with a 
>> template. A (run-time) variadic delegate is an actual 
>> delegate, i.e. a value that can be passed around. But the 
>> variadic stuff is a bit weird to use, and probably affects 
>> performance.
>
> By the way, I'm not even sure, if variadics work in my case. I 
> have a strange struct of a random generator, which cannot be 
> copied, and I have no idea how to pass it to a variadic 
> function:
>
> import std.stdio;
> import mir.random;
>
> void main()
> {
> 	Random rndGen = Random(unpredictableSeed);
> 	fun(rndGen);
> }
>
> void fun(...)
> {
>
> }
>
> Yields "... is not copyable because it is annotated with 
> @disable" :)

1. Pass its pointer
2. Use variadic template with auto ref:

```
void foo(T...)(auto ref T tup)
{
}
```



More information about the Digitalmars-d-learn mailing list