Mysteries of the Underscore

Johan Engelen j at j.nl
Mon Dec 24 11:30:31 UTC 2018


On Monday, 24 December 2018 at 11:18:44 UTC, Ron Tarrant wrote:
> I found a mention that in the definition of a delegate, a 
> function parameter and its type could be replaced by an 
> underscore:
>
> myTestRig.addOnDestroy(delegate void(Widget w) { quitApp(); } );
>
> became:
>
> myTestRig.addOnDestroy(delegate void(_) { quitApp(); } );
>
> I was trying to find some further documentation on this, but 
> I'm coming up empty.
>
> Questions:
>
> 1) What is this called (substituting an underscore in this 
> manner)?
>
> 2) Where can a learn more about it?

The underscore is just an identifier but nothing special, it 
could be any valid identifier like "ldkhfksdkdsg".

```
void ggg();

void takedelegate(void delegate(int) dlg);

void foo() {
     takedelegate( delegate void(asdadasdeg) { ggg(); } );
}
```
The type of the argument is deduced from the function the 
delegate is passed to.

-Johan



More information about the Digitalmars-d-learn mailing list