|Posted by Tejas|
in reply to jfondren
Posted in reply to jfondren
On Wednesday, 4 August 2021 at 09:43:57 UTC, jfondren wrote:
On Wednesday, 4 August 2021 at 08:08:35 UTC, Tejas wrote:
On Thursday, 29 July 2021 at 20:44:35 UTC, Elronnd wrote:
d.require(5, 7); //compile error
From a semantics perspective, though, I don't think there's anything wrong with this, and 'require' could reasonably cast the const away before assigning. Am I missing anything?
const away is undefined behaviour in D. And what is this "require"? Maybe show more code?
what's wanted here is an assign-once hash table, I imagine.
require is https://dlang.org/phobos/object.html#.require , and it'd be the assignment line of that code that would have to cast away const.
assert(nums == [0: 1]);
assert(__traits(compiles, nums.require(0, 0)));
Well, OP will have to create non-const AA first and then cast it to const, it seems.
auto b = cast(const(int)[int])a;
Probably hide the process behind a function to make it look more smooth; otherwise I'm outta ideas.