| Thread overview | ||||||
|---|---|---|---|---|---|---|
|
December 28, 2016 understanding std.algorithm.mutation.fill behaivor. | ||||
|---|---|---|---|---|
| ||||
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.
| ||||
December 28, 2016 Re: understanding std.algorithm.mutation.fill behaivor. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to LeqxLeqx | 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 | |||
December 28, 2016 Re: understanding std.algorithm.mutation.fill behaivor. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Nemanja Boric | 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:
>> 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
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.
| |||
December 30, 2016 Re: understanding std.algorithm.mutation.fill behaivor. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to abad | 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:
>> 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
>
> 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.
I see. That's good to know. Thank you both so much!
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply