normal function and template function conflict

monarch_dodra monarchdodra at gmail.com
Thu Jul 26 10:18:21 PDT 2012


I was trying to write a PRNG, and I wanted to give it two seed 
methods. The first is to seed from a unique UIntType, and the 
other is to seed from an entire range of seeds. Like so:

--------
void seed(UIntType value = default_seed)
{...}

void seed(Range)(Range range)
   if (isInputRange!Range)
{...}
--------
Where UIntType is a template parameter of the struct.

However, this makes the compiler complain, because of a 
conflict...? Is mixing normal functions with parametrized ones 
impossible?

I *fixed* the issue by contemplating the first call with:
--------
void seed(T)(T value = default_seed)
   if (is(typeof(T == UIntType)))
{...}
--------
Problems:
1) It is ugly as sin.
2) The default parameter doesn't work anymore.

So here are my two questions:
1) Is what I was originally trying to do actually illegal, or is 
it some sort of compiler limitation? TDPL implies this should 
work perfectly fine...
2) Is there a "correct" workaround?


More information about the Digitalmars-d-learn mailing list