templatized delegate

Nicholas Wilson via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue May 23 03:42:54 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" :)

Random is copy @disabled to prevent incorrect use.
You need to pass it by ref or pointer. I dont know if you can 
pass variables as ref to a variadic, but you should be able to 
pass it by address.
fun(&rndGen);


More information about the Digitalmars-d-learn mailing list