On Thursday, 29 August 2019 at 10:58:47 UTC, Simen Kjærås wrote:
On Thursday, 29 August 2019 at 10:39:44 UTC, Jabari Zakiya
wrote:
[...]
Great - then you can use shared(immutable(uint)[]). You should
be able to convert from immutable(uint[]) to that without
issue. There's a utility function in std.exception called
assumeUnique that can be used for conversion to immutable that
may be more informative than cast(immutable):
shared(uint) modpg;
shared(uint) res_0;
shared(immutable(uint)[]) restwins;
shared(immutable(uint)[]) resinvrs;
auto genPGparameters(int i) {
import std.typecons;
import std.exception;
// Showing both cast and assumeUnique:
return tuple(1u, 2u, cast(immutable)[3u],
[4u].assumeUnique);
}
unittest {
import std.meta : AliasSeq;
int pg;
// No need for temporaries:
AliasSeq!(modpg, res_0, restwins, resinvrs) =
genPGparameters(pg);
}
[...]
Correct - since there are no indirections in a uint, you can
assign directly to a shared(uint) - nobody else will have a
non-shared pointer to that uint, so it's somewhat safe. If you
do the same with uint[], you'll still have a pointer to the
same values, and changing a value that says it's thread-local
(no shared) will change values that is shared with the rest of
the program. There are some issues with the current shared
design, but this is what it's intended to do.
--
Simen
It still won't compile, with this error.
Error: AliasSeq!(modpg, res_0, restwins, resinvrs) is not an
lvalue and cannot be modified
Here's a gist of the code.
Top functions in code with issues are genPgParameters and selectPG
https://gist.github.com/jzakiya/9227e4810e1bd5b4b31e949d1cbd5c5d