Can't add a const ubyte to a dynamic array of ubyte?

2019-08-20 Thread ads via Digitalmars-d-learn
import std.stdio; ubyte[] extend(in uint[] arr) { ubyte[] result; foreach (n; arr) { if (n < 10) { result ~= n; // source/app.d(10,11): Error: cannot append type const(uint) to type ubyte[]

Re: Can't add a const ubyte to a dynamic array of ubyte?

2019-08-20 Thread Daniel Kozak via Digitalmars-d-learn
On Tue, Aug 20, 2019 at 11:30 AM ads via Digitalmars-d-learn wrote: > > > How can I get around this? I want to ensure that the array is not > mutated in the function in the signature too. > https://run.dlang.io/is/tehp3j import std.stdio; ubyte[] extend(in uint[] arr) { ubyte[] result;

Re: Can't add a const ubyte to a dynamic array of ubyte?

2019-08-20 Thread a11e99z via Digitalmars-d-learn
On Tuesday, 20 August 2019 at 09:27:36 UTC, ads wrote: import std.stdio; ubyte[] extend(in uint[] arr) { ubyte[] result; foreach (n; arr) { if (n < 10) result ~= n; else { impo

Re: Can't add a const ubyte to a dynamic array of ubyte?

2019-08-20 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, August 20, 2019 3:27:36 AM MDT ads via Digitalmars-d-learn wrote: > import std.stdio; > > ubyte[] extend(in uint[] arr) > { > ubyte[] result; > foreach (n; arr) > { > if (n < 10) > { > result ~= n; > // source/app.d(10,11): Error: ca

Re: Can't add a const ubyte to a dynamic array of ubyte?

2019-08-20 Thread a11e99z via Digitalmars-d-learn
On Tuesday, 20 August 2019 at 09:49:21 UTC, Daniel Kozak wrote: On Tue, Aug 20, 2019 at 11:30 AM ads via Digitalmars-d-learn wrote: you do not allow a person to think about a problem (and it’s easy here). you carried him through a puddle now, but when he dives into Sea D, you will not be t