Input/Output multiple values from function

Simen Kjærås simen.kjaras at
Thu Aug 29 10:58:47 UTC 2019

On Thursday, 29 August 2019 at 10:39:44 UTC, Jabari Zakiya wrote:
> The values modpg, res_0, restwins, and resinvrs are constant 
> (immutable) values that are generated at run time. They are 
> global/shared and used inside threads.
> So this process is initializing them at the start of the 
> program, based on the input values to it.

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) = 

> The compiler only has a problem, it seems, with the arrays and 
> not the single values.

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.


More information about the Digitalmars-d-learn mailing list