Yesterday I solved similar problem by using enum.
enum GameInfo[string] games=[
...
];
Dňa 8. 2. 2013 21:21 anonymous  wrote / napísal(a):
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.

Reply via email to