what is special about unittest constants
anonymous
anonymous at example.com
Fri Feb 8 12:21:18 PST 2013
On Friday, 8 February 2013 at 20:12:41 UTC, Dan wrote:
> This constant in a module causes a compilation error of the
> "non-constant expression" variety.
>
> DEFINITION 1
> const(AssetProjectionMap) SavingsGrowth2013 = [
> AssetReturnType.Interest :
> RateCurve([DateRate(Date.min, CcRate(0.007))]),
> ];
>
> The fix that addresses this error at module level is:
>
> DEFINITION 2
>
> const(AssetProjectionMap) SavingsGrowth2013;
> static this() {
> SavingsGrowth2013 = [
> AssetReturnType.Interest :
> RateCurve([DateRate(Date.min, CcRate(0.007))]),
> ];
> }
>
>
> However, the same constant, when defined in a unittest block
> works with DEFINITION 1. What is the reason for the difference
> between unittest constants and module constants?
>
> Thanks,
> Dan
unittest blocks are evaluated at run time, just like your
DEFINITION 2, and unlike your DEFINITION 1 which would be
evaluated at compile time.
More information about the Digitalmars-d-learn
mailing list