http://d.puremagic.com/issues/show_bug.cgi?id=11415


monarchdo...@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |monarchdo...@gmail.com
         Resolution|                            |INVALID


--- Comment #3 from monarchdo...@gmail.com 2013-11-02 02:44:19 PDT ---
(In reply to comment #2)
> Filter produces a lazy range. In other words, it is not an int array. To store
> the result of filter in d[] you need to eagerly evaluate it. To do that you 
> can
> use std.array.array on the result of filter.
> The code becomes:
> 
> int[] d = [1,2,3,4,5,6,7];
> d = d.filter!(x => x > 3).array();
> 
> If this answers your question, please close the bug.
> 
> http://dlang.org/phobos/std_array.html#.array

Yes. Do note though that this will allocate a new array, and not *copy* filter
"into" the "d" array. Not that it's wrong, I just want to highlight it, as I
don't think its quite what the op wanted.

If you want to assign the *contents*, then std.algorithm.copy will do what you
want:
http://dlang.org/phobos/std_algorithm.html#copy
int[] d = [1,2,3,4,5,6,7];
d.filter!(x => x > 3)().copy(d);

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to