Rebind template(bug?)
ag0aep6g via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Aug 22 11:48:12 PDT 2016
On 08/22/2016 08:04 PM, Engine Machine wrote:
> How do you seriously think this is cleaner/simpler? You have two
> classes. Their is no uniformity between them. You have uniformity
> between all the derived classes then have a special case for the base
> class. A certain easy to follow pattern is set up but needlessly break
> it for one case. Why?
It avoids the relatively obscure (and badly named, by me)
InstantiateOrEmptySeq template.
You can take this further with template constraints. Gives it a more
uniform appearance at the price of some repetition:
----
class T()
{
int x;
}
class T(A...) : T!(A[0..$-1])
if (A.length > 0 && A[$-1] == "Animal")
{
int y;
}
class T(A...) : T!(A[0..$-1])
if (A.length > 0 && A[$-1] == "Dog")
{
int z;
}
class T(A...) : T!(A[0..$-1])
if (A.length > 0 && A[$-1] == "Pug")
{
int s;
}
----
I wouldn't say that this is obviously, objectively, significantly better
than the version with the helper template, though.
By the way, it's not obvious to me what this whole thing achieves in
practice. And whatever benefit there is, it has to be weighed against
the cost of the added complexity.
I don't mean to say that this is not worth pursuing. Just a friendly
reminder that over-engineering is something to look out for, from
someone who is prone to over-engineering himself.
More information about the Digitalmars-d-learn
mailing list