digitalmars.D.learn - understanding std.algorithm.mutation.fill behaivor.
- LeqxLeqx (22/22) Dec 27 2016 Perhaps this is a stupid question, and I apologize if it is, but
- Nemanja Boric (3/25) Dec 28 2016 So I don't repeat excellent answer:
Perhaps this is a stupid question, and I apologize if it is, but why doesn't this compile: import std.algorithm; import std.stdio; void main() { char[] array = [1, 2, 3, 4]; char value = 2; fill(array, value); } if this does: import std.algorithm; import std.stdio; void main() { int[] array = [1, 2, 3, 4]; int value = 2; fill(array, value); } when the only difference is the type, and the 'fill' method is meant to be generic? Thanks for your time.
Dec 27 2016
On Wednesday, 28 December 2016 at 05:09:34 UTC, LeqxLeqx wrote:Perhaps this is a stupid question, and I apologize if it is, but why doesn't this compile: import std.algorithm; import std.stdio; void main() { char[] array = [1, 2, 3, 4]; char value = 2; fill(array, value); } if this does: import std.algorithm; import std.stdio; void main() { int[] array = [1, 2, 3, 4]; int value = 2; fill(array, value); } when the only difference is the type, and the 'fill' method is meant to be generic? Thanks for your time.So I don't repeat excellent answer: http://stackoverflow.com/a/6401889/133707
Dec 28 2016
On Wednesday, 28 December 2016 at 08:10:41 UTC, Nemanja Boric wrote:On Wednesday, 28 December 2016 at 05:09:34 UTC, LeqxLeqx wrote:So in short, unlike in C/C++ world, you should only use char to store actual text, not data as would be common in C/C++. byte & ubyte are for that.Perhaps this is a stupid question, and I apologize if it is, but why doesn't this compile: import std.algorithm; import std.stdio; void main() { char[] array = [1, 2, 3, 4]; char value = 2; fill(array, value); } if this does: import std.algorithm; import std.stdio; void main() { int[] array = [1, 2, 3, 4]; int value = 2; fill(array, value); } when the only difference is the type, and the 'fill' method is meant to be generic? Thanks for your time.So I don't repeat excellent answer: http://stackoverflow.com/a/6401889/133707
Dec 28 2016
On Wednesday, 28 December 2016 at 08:27:29 UTC, abad wrote:On Wednesday, 28 December 2016 at 08:10:41 UTC, Nemanja Boric wrote:I see. That's good to know. Thank you both so much!On Wednesday, 28 December 2016 at 05:09:34 UTC, LeqxLeqx wrote:So in short, unlike in C/C++ world, you should only use char to store actual text, not data as would be common in C/C++. byte & ubyte are for that.Perhaps this is a stupid question, and I apologize if it is, but why doesn't this compile: import std.algorithm; import std.stdio; void main() { char[] array = [1, 2, 3, 4]; char value = 2; fill(array, value); } if this does: import std.algorithm; import std.stdio; void main() { int[] array = [1, 2, 3, 4]; int value = 2; fill(array, value); } when the only difference is the type, and the 'fill' method is meant to be generic? Thanks for your time.So I don't repeat excellent answer: http://stackoverflow.com/a/6401889/133707
Dec 29 2016