Re: overloading a function taking a void[][]
Am Wed, 08 Aug 2012 21:55:21 +0200 schrieb Timon Gehr timon.g...@gmx.ch: Well, I have done similar things in the past. The general concept should work. BTW: This is a working version, but it does cause template bloat: http://dpaste.dzfl.pl/d42a58aa Maybe this helps: http://dpaste.dzfl.pl/ed2e8e5d I see! I didn't have the cast(void[][]) in there. Usually a function defined with (void[][] data...) can take an arbitrary number of arguments of any type. But when used as above, it looses that feature and an explicit cast is necessary. http://dpaste.dzfl.pl/8bb247ff Not sure if I like this, I'll probably just have a separate function digestRange.
overloading a function taking a void[][]
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
Re: overloading a function taking a void[][]
Try this: template digest(Hash) if(isDigest!Hash){ digestType!Hash digest(Range)(Range data) if(!is(Range:void[][]) isInputRange!Range __traits(compiles,digest!Hash(ElementType!(Range).init))){ //implementation detail } digestType!Hash digest()(scope const(void[])[] data...){ // templated as a workaround //implementation detail } // ... (maybe more overloads) }
Re: overloading a function taking a void[][]
Am Wed, 08 Aug 2012 18:53:05 +0200 schrieb Timon Gehr timon.g...@gmx.ch: Try this: template digest(Hash) if(isDigest!Hash){ digestType!Hash digest(Range)(Range data) if(!is(Range:void[][]) isInputRange!Range __traits(compiles,digest!Hash(ElementType!(Range).init))){ //implementation detail } digestType!Hash digest()(scope const(void[])[] data...){ // templated as a workaround //implementation detail } // ... (maybe more overloads) } Clever, but doesn't seem to work. I can't create an instance of it, even when explicitly specifying the types. BTW: This is a working version, but it does cause template bloat: http://dpaste.dzfl.pl/d42a58aa
Re: overloading a function taking a void[][]
On 08/08/2012 09:11 PM, Johannes Pfau wrote: Am Wed, 08 Aug 2012 18:53:05 +0200 schrieb Timon Gehrtimon.g...@gmx.ch: Try this: template digest(Hash) if(isDigest!Hash){ digestType!Hash digest(Range)(Range data) if(!is(Range:void[][]) isInputRange!Range __traits(compiles,digest!Hash(ElementType!(Range).init))){ //implementation detail } digestType!Hash digest()(scope const(void[])[] data...){ // templated as a workaround //implementation detail } // ... (maybe more overloads) } Clever, but doesn't seem to work. I can't create an instance of it, even when explicitly specifying the types. Well, I have done similar things in the past. The general concept should work. BTW: This is a working version, but it does cause template bloat: http://dpaste.dzfl.pl/d42a58aa Maybe this helps: http://dpaste.dzfl.pl/ed2e8e5d