overloading a function taking a void[][]

Johannes Pfau nospam at example.com
Wed Aug 8 09:42:26 PDT 2012


I wanted to add a new overload to digest for the std.hash module (see
review in main newsgroup). This is the code written as two functions
which should be combined in one overloaded function

----------------
digestType!Hash digest(Hash)(scope const(void[])[] data...)
    if(isDigest!Hash)
{
    //implementation detail
}

digestType!Hash digestRange(Hash, Range)(Range data) if(isDigest!Hash &&
    isInputRange!Range && __traits(compiles,
    digest!Hash(ElementType!(Range).init)))
{
    //implementation detail
}
----------------

What I need is two overloads: One which takes a byte representation of
every possible type (and multiple parameters of that), except
InputRanges. And one which handles the InputRanges.
As an additional difficulty the overload taking all other types should
only cause one template instance (per Hash type) to avoid template
bloat (like currently).

It must also be possible to alias the template for specific Hash types
(could be done with a template instead of an alias as long as it doesn't
cause bloat):

alias digest!MD5 md5Of; //Works right now


More information about the Digitalmars-d-learn mailing list