Proposal: static template(fail)
Bruce Adams
tortoise_74 at yeah.who.co.uk
Fri Dec 14 16:41:12 PST 2007
On Fri, 14 Dec 2007 20:01:17 -0000, BCS <ao at pathlink.com> wrote:
> Reply to Bruce,
>
>> On Fri, 14 Dec 2007 19:09:25 -0000, BCS <ao at pathlink.com> wrote:
>>
>>> what would this do?:
>>> template Foo(T)
>>> {
>>> static if(logic1!(T)) template(fail);
>>> }
>>> template Foo(T)
>>> {
>>> static if(logic2!(T)) template(fail);
>>> }
>>> from a programers level, it might be valid. My though is (an wow
>>> could this be costly) try all cases*, if there isn't exactly one
>>> match, error.
>>> * Walter's not going to like that for performance reasons.
>>>
>> I'm not so sure about that. Its a bit like saying he wouldn't like you
>> to
>> write poorly designed / optimised code. He may not like it but a
>> programming
>> language can't help but permit it even if it does discourage it.
>
> I'm taking about DMD's performance. The compile time cost of find a
> template match could go through the roof with the "backtracking finds
> one match" solution.
>
Prolog is entirely based on backtracking huge numbers of predicates and it
doesn't
run that slowly. I don't think it would be much of a problem in D unless
you write
a huge number of really complex evil templates and stick them all in one
module.
I'm not sure even the legendary obfuscator Downs could stretch it to
breaking point.
Mr. Blade library might come closer. Anyway, as with any language feature
you should
only pay for it if you use it. Unless you are overusing it, it shouldn't
be a problem.
More information about the Digitalmars-d
mailing list