The review of std.hash package

Johannes Pfau nospam at example.com
Wed Aug 8 12:05:09 PDT 2012


Am Wed, 08 Aug 2012 11:47:38 -0700
schrieb Walter Bright <newshound2 at digitalmars.com>:

> On 8/8/2012 9:47 AM, Johannes Pfau wrote:
> > Am Wed, 8 Aug 2012 17:50:33 +0200
> > schrieb Johannes Pfau <nospam at example.com>:
> >
> >> However, I do agree digest!Hash, md5Of, sha1Of should have an
> >> additional overload which takes a InputRange. It would be
> >> implemented with copy and be a nice convenience function.
> >
> > I implemented the function, it's actually quite simple:
> > ----
> > digestType!Hash digestRange(Hash, Range)(Range data)
> > if(isDigest!Hash && isInputRange!Range && __traits(compiles,
> >      digest!Hash(ElementType!(Range).init)))
> > {
> >      Hash hash;
> >      hash.start();
> >      copy(data, hash);
> >      return hash.finish();
> > }
> > ----
> 
> The finish() should be implicit when the range ends.
> 
> >
> > but I don't know how make it an overload. See thread "overloading a
> > function taking a void[][]" in D.learn for details.
> >
> 
> I don't know what you mean, it takes a range, not a void[][] as input.
> 
> 

So the post in D.learn for a detailed description. Yes the code I
posted takes a range, but digest (as it is now) takes void[][] to
accept all kind of types _without_ template bloat. The difficulty is to
combine those two overloads without causing unnecessary template bloat.


More information about the Digitalmars-d mailing list