Overloading Lazy Vs. Non-Lazy

Steven Schveighoffer schveiguy at yahoo.com
Thu Aug 12 04:58:23 PDT 2010


On Wed, 11 Aug 2010 18:10:53 -0400, Tomek Sowiński <just at ask.me> wrote:

> Steven Schveighoffer napisał:
>
>> Hold on, can't we have enforce and lenforce (lazy enforce)?
>>
>> From a simple grep, 99% of enforce instances are:
>>
>> enforce(condition)
>> -or-
>> enforce(condition, "compile-time-string")
>> -or-
>> enforce(condition, "compile-time-string" ~ type.stringof)
>>
>> There are a few ones which actually would be allocating strings at
>> runtime, but seriously, can't we just modify those to lenforce and get
>> inlining everywhere else?  I think phobos would see both a huge speedup
>> and a smaller footprint immediately if enforce did not take a lazy arg.
>
> I like this idea. But > 1 option makes you think and that's painful;)

One possibility is to have enforce force you to pass in a compile-time  
evaluatable string.  I don't really know if this is possible.  But then at  
least the compiler could prevent you from accidentally using the wrong  
enforce.

> BTW, am I the only person surprised that in a language whose generic  
> code to fit the need can transform like Optimus Prime himself you
> can't do lazy <-> non-lazy automagically?

It's been suggested before (by me even):  
http://d.puremagic.com/issues/show_bug.cgi?id=1817

But that would be limited to templates only.  A non-template function  
which takes a lazy argument could not make any conversions.

I'd rather see an overload, or just separate the names.

-Steve


More information about the Digitalmars-d mailing list