How should I return multiple const values from a function?

Charles Hixson charleshixsn at earthlink.net
Mon Jan 2 22:53:13 UTC 2023


I want to return values of the template parameter type, so there doesn't 
seem to be any way to dup or idup them.  I don't want the returned 
values to be able to be used to modify the values held in the table.  
const out is an illegal parameter type.  dup doesn't work on ints.

So I tried to return a tuple, but cast(const) doesn't work on strings.  
(Error: cannot implicitly convert expression `tuple(k, v)` of type 
`Tuple!(string, string)` to `Tuple!(const(string), const(string))`  
Sometimes it remembers that I've done the cast, and sometimes it 
doesn't.  The code was: return    tuple (cast(const)(Key.init), 
cast(const)(Val.init));  I've no idea why it was talking about type 
`Tuple!(string, string)`, since in the test the types were (string, uint).

I feel like I'm overlooking something obvious, but I've no idea what.  I 
really just wanted to return dups, but those don't work if one of the 
types might be an int.  (Though I should have been trying to return 
idups.  O, well.)

-- 
Javascript is what you use to allow third part programs you don't know anything about and doing you know not what to run on your computer.



More information about the Digitalmars-d-learn mailing list