www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - std.array.array for immutable data types

reply Fra Mecca <me francescomecca.eu> writes:
Is there a way to avoid using to! conversion here?

immutable string[] dst = to!(immutable 
string[])(array(pipe.readEnd.byLineCopy));
Feb 18 2018
next sibling parent Seb <seb wilzba.ch> writes:
On Monday, 19 February 2018 at 07:08:49 UTC, Fra Mecca wrote:
 Is there a way to avoid using to! conversion here?

 immutable string[] dst = to!(immutable 
 string[])(array(pipe.readEnd.byLineCopy));
Are you looking for something like assumeUnique [1]? ``` pipe.readEnd.byLineCopy.array.assumeUnique; ``` It's just a nice wrapper for cast(immutable string[]). [1] https://dlang.org/phobos/std_exception.html#assumeUnique
Feb 18 2018
prev sibling parent reply Nicholas Wilson <iamthewilsonator hotmail.com> writes:
On Monday, 19 February 2018 at 07:08:49 UTC, Fra Mecca wrote:
 Is there a way to avoid using to! conversion here?

 immutable string[] dst = to!(immutable 
 string[])(array(pipe.readEnd.byLineCopy));
assumeUnique. immutable string[] dst = pipe.readEnd.byLineCopy.array.assumeUnique;
Feb 18 2018
parent Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
On Monday, February 19, 2018 07:25:07 Nicholas Wilson via Digitalmars-d-
learn wrote:
 On Monday, 19 February 2018 at 07:08:49 UTC, Fra Mecca wrote:
 Is there a way to avoid using to! conversion here?

 immutable string[] dst = to!(immutable
 string[])(array(pipe.readEnd.byLineCopy));
assumeUnique. immutable string[] dst = pipe.readEnd.byLineCopy.array.assumeUnique;
Arguably, to!(immutable string[]) should work on the result of byLineCopy, but it doesn't seem to. If it did, then that would eliminate the need for assumeUnique, and it's always better to avoid assumeUnique if you can. However, given the current limitation with to and byLineCopy, it probably is the best solution. - Jonathan M Davis
Feb 19 2018