www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Dummy template parameter vs empty template parameter list

reply Ben Jones <fake fake.fake> writes:
Looking through Phobos code there's a bunch functions defined 
with dummy template types:

void whatever(TDummy = void)( int x, ...) //TDummy is never used

Why not just use an empty template parameter list?

void whatever()(int x, ...)


My gut tells me that his is a workaround for an old limitation 
preventing empty template lists, but figured I'd ask.
Apr 10
parent Seb <seb wilzba.ch> writes:
On Wednesday, 10 April 2019 at 20:37:38 UTC, Ben Jones wrote:
 Looking through Phobos code there's a bunch functions defined 
 with dummy template types:

 void whatever(TDummy = void)( int x, ...) //TDummy is never used

 Why not just use an empty template parameter list?

 void whatever()(int x, ...)


 My gut tells me that his is a workaround for an old limitation 
 preventing empty template lists, but figured I'd ask.
It depends on the specific function, but there's lots of old code in Phobos. In this case it could be that it was a workaround for a DMD bug or limitation that has since been fixed. So never be afraid to question Phobos code and give it the full scrutiny it needs. A good rule of thumb is that if all unittests still pass, the reason was historic ;-)
Apr 10