On Saturday, 22 April 2017 at 18:26:56 UTC, Dmitry Olshansky
wrote:
On 4/22/17 6:57 PM, Stanislav Blinov wrote:
On Saturday, 22 April 2017 at 16:41:00 UTC, Nordlöw wrote:
If defaultValue is not lazy, it's potentially wasteful.
What do you mean with "potentially wasteful"?
Excess calls to copy constructors?
Evaluation of an expression the result of which might not be
used.
defaultValue could be anything: a literal, an lvalue, a result
of a
function call...
IMO you are overenginering this. defaultValue will most likely
be something distinct such as compile-time constant.
I'm looking at it from the perspective of it being added to
Phobos, which seems to be Nordlöw's intent. There should not be
any assumptions in that scenario, or there should be an overload
for the "most likely" case.
The signature says: defaultValue will be anything convertible to
typeof(defaultValue), and is going to be evaluated regardless of
whether or not std.conv.to() call throws.
All I'm saying is the purpose *suggests* that the defaultValue
parameter should be lazy, and that that currently annotating it
so defeats that purpose is due to a bug. Although one could work
around the bug for the time being by using
std.exception.assumeWontThrow.