digitalmars.D.learn - Filling an array
- Alex (28/28) Mar 12 2016 Hi all!
- Mike Parker (13/18) Mar 12 2016 Looks like a bug somewhere. The work around is to cast:
- Alex (4/23) Mar 12 2016 Thanks!
- ag0aep6g (3/4) Mar 12 2016 Nicer than a cast: construct a Nullable!int.
- Alex (3/7) Mar 12 2016 ok... so... this makes the error very strange, then... almost
- user42 (6/9) Mar 12 2016 I thought this was supposed to halt with an error rather than
Hi all! I have, maybe, a silly question.. Not sure, if https://forum.dlang.org/post/ibxhuqamgclrcatsyhst forum.dlang.org has something to do with the topic Having the following code: import std.typecons; import std.algorithm; void main() { uint[] arr_ref; arr_ref.length = 5; assert(arr_ref == [0, 0, 0, 0, 0]); arr_ref[] = 1; assert(arr_ref == [1, 1, 1, 1, 1]); Nullable!uint[] arr; arr.length = 5; bool[] check_arr; arr.each!(a => check_arr ~= a.isNull); assert(check_arr == [true, true, true, true, true]); //arr[] = 1; fill(arr, 1); assert(arr == [1, 1, 1, 1, 1]); } The question is, why the commented out line throws the error: Error: cannot implicitly convert expression (1) of type int to Nullable!uint[], while the line after that works.
Mar 12 2016
On Saturday, 12 March 2016 at 14:33:19 UTC, Alex wrote://arr[] = 1; The question is, why the commented out line throws the error: Error: cannot implicitly convert expression (1) of type int to Nullable!uint[], while the line after that works.Looks like a bug somewhere. The work around is to cast: arr[] = cast(Nullable!uint)1; I suggest you file this in the bug tracker [1] if it isn't there already. Just use he minimal code that shows the problem: void main() { import std.typecons; Nullable!uint[] arr; arr.length = 5; arr[] = 1; } [1] https://dlang.org/bugstats.php
Mar 12 2016
On Saturday, 12 March 2016 at 15:44:00 UTC, Mike Parker wrote:On Saturday, 12 March 2016 at 14:33:19 UTC, Alex wrote:Thanks! Bug filed under https://issues.dlang.org/show_bug.cgi?id=15792//arr[] = 1; The question is, why the commented out line throws the error: Error: cannot implicitly convert expression (1) of type int to Nullable!uint[], while the line after that works.Looks like a bug somewhere. The work around is to cast: arr[] = cast(Nullable!uint)1; I suggest you file this in the bug tracker [1] if it isn't there already. Just use he minimal code that shows the problem: void main() { import std.typecons; Nullable!uint[] arr; arr.length = 5; arr[] = 1; } [1] https://dlang.org/bugstats.php
Mar 12 2016
On 12.03.2016 16:44, Mike Parker wrote:arr[] = cast(Nullable!uint)1;Nicer than a cast: construct a Nullable!int. arr[] = Nullable!uint(1);
Mar 12 2016
On Saturday, 12 March 2016 at 19:35:30 UTC, ag0aep6g wrote:On 12.03.2016 16:44, Mike Parker wrote:ok... so... this makes the error very strange, then... almost senseless...arr[] = cast(Nullable!uint)1;Nicer than a cast: construct a Nullable!int. arr[] = Nullable!uint(1);
Mar 12 2016
On Saturday, 12 March 2016 at 14:33:19 UTC, Alex wrote:/snipI thought this was supposed to halt with an error rather than compile and set all members to 1. The syntax, to me anyways, doesn't really communicate the intention of: set all members to 1.//arr[] = 1;Whereas the following doesfill(arr, 1);
Mar 12 2016
On Saturday, 12 March 2016 at 16:37:25 UTC, user42 wrote:On Saturday, 12 March 2016 at 14:33:19 UTC, Alex wrote:Well, this was not the question. As stated here: https://dlang.org/spec/arrays.html in the section "array setting", it is possible to set an array in such a manner. And my question was, why a specific array behaves not as expected. So, either there is a problem with filling an array, or, there is a problem with implicit conversion of a Nullable!T to its underlying type./snipI thought this was supposed to halt with an error rather than compile and set all members to 1. The syntax, to me anyways, doesn't really communicate the intention of: set all members to 1.//arr[] = 1;Whereas the following doesfill(arr, 1);
Mar 12 2016
On Saturday, 12 March 2016 at 18:33:16 UTC, Alex wrote:On Saturday, 12 March 2016 at 16:37:25 UTC, user42 wrote:Learned something new. I guess I missed that detail when I read that page.On Saturday, 12 March 2016 at 14:33:19 UTC, Alex wrote:Well, this was not the question. As stated here: https://dlang.org/spec/arrays.html in the section "array setting", it is possible to set an array in such a manner. And my question was, why a specific array behaves not as expected. So, either there is a problem with filling an array, or, there is a problem with implicit conversion of a Nullable!T to its underlying type./snipI thought this was supposed to halt with an error rather than compile and set all members to 1. The syntax, to me anyways, doesn't really communicate the intention of: set all members to 1.//arr[] = 1;Whereas the following doesfill(arr, 1);
Mar 13 2016