Re: dynamic array .length vs .reserve - what's the difference?

2020-07-30 Thread Ali Çehreli via Digitalmars-d-learn
On 7/30/20 4:42 PM, wjoe wrote: > So .capacity can't be assigned a value like length to reserve the RAM ? Yes, a read-only property... >> auto a = b; >> b = b[0 .. $-1]; >> b ~= someT; >> >> If that last line is done in-place, then it overwrites a[$-1]. > > So this is a case of sharing being

Re: dynamic array .length vs .reserve - what's the difference?

2020-07-30 Thread wjoe via Digitalmars-d-learn
On Thursday, 30 July 2020 at 16:33:22 UTC, Ali Çehreli wrote: On 7/30/20 8:58 AM, wjoe wrote:     b.reserve(n);     b.length = n; There may be something that I don't know but I think assigning to the .length property alone should be the same as reserving and then assigning.

Re: Gotcha with const std.range.chunks

2020-07-30 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 30, 2020 at 06:52:42PM +, sportsracer via Digitalmars-d-learn wrote: [...] > int[] xs = new int[100]; > const chunked = xs.chunks(10); > writeln(chunked[0][0]); > } > > Error: mutable method std.range.Chunks!(int[]).Chunks.opIndex is not > callable using a const

Gotcha with const std.range.chunks

2020-07-30 Thread sportsracer via Digitalmars-d-learn
Newcomer to the D language here. I was going to use `std.range.chunks` to get a two-dimensional, read-only view on data in one continuous array. But was surprised to find that this code doesn't compile: import std.range : chunks; import std.stdio : writeln; void main() { int[] xs = new

Re: dynamic array .length vs .reserve - what's the difference?

2020-07-30 Thread bachmeier via Digitalmars-d-learn
On Thursday, 30 July 2020 at 15:58:28 UTC, wjoe wrote: I just stumbled upon code like this: struct Foo(T) { T[] b; this(int n) { b.reserve(n); b.length = n; } } .reserve looks redundant. The docs are explaining .length nicely, however lack any specifics about

Re: dynamic array .length vs .reserve - what's the difference?

2020-07-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/30/20 11:58 AM, wjoe wrote: I just stumbled upon code like this: struct Foo(T) {     T[] b;     this(int n)     {     b.reserve(n);     b.length = n;     } } ..reserve looks redundant. It is, in this case. Reserve will extend the allocated length to n, but not adjust the

Re: dynamic array .length vs .reserve - what's the difference?

2020-07-30 Thread Ali Çehreli via Digitalmars-d-learn
On 7/30/20 8:58 AM, wjoe wrote:     b.reserve(n);     b.length = n; There may be something that I don't know but I think assigning to the .length property alone should be the same as reserving and then assigning. reserve is supposed to make sure no memory will be allocated as

dynamic array .length vs .reserve - what's the difference?

2020-07-30 Thread wjoe via Digitalmars-d-learn
I just stumbled upon code like this: struct Foo(T) { T[] b; this(int n) { b.reserve(n); b.length = n; } } .reserve looks redundant. The docs are explaining .length nicely, however lack any specifics about reserve. Changing the length of an array may relocate

Re: Overload comparison operators for "nullable" types

2020-07-30 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 30, 2020 at 01:41:05PM +, Oleg B via Digitalmars-d-learn wrote: [...] > Logically we can compare versions, but what must return `opCmp` if one of > versions has 'not comparible' state? [...] opCmp is allowed to return float; so you could return float.nan in this case. T --

Overload comparison operators for "nullable" types

2020-07-30 Thread Oleg B via Digitalmars-d-learn
Hello! For example we can imagine struct Version. Version can be old or new and can be 'badly formed' or 'undefined' or other 'not comparible' ('uncompatible') state. Logically we can compare versions, but what must return `opCmp` if one of versions has 'not comparible' state? I think

Re: How do I convert a Base64 image url string to a png/jpg image file?

2020-07-30 Thread aberba via Digitalmars-d-learn
On Thursday, 30 July 2020 at 12:28:08 UTC, Adam D. Ruppe wrote: On Thursday, 30 July 2020 at 12:22:46 UTC, aberba wrote: [...] I don't think I wrote it as a library yet, but the idea is pretty simple: they all start with "data:" so you look for that. Then there's a type after that, so you

Re: How do I convert a Base64 image url string to a png/jpg image file?

2020-07-30 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 30 July 2020 at 12:22:46 UTC, aberba wrote: I'm able to decode it to a buffer but the trouble is getting it from buffer to an actual image file. Any library function combination I can use? I don't think I wrote it as a library yet, but the idea is pretty simple: they all start

How do I convert a Base64 image url string to a png/jpg image file?

2020-07-30 Thread aberba via Digitalmars-d-learn
So I have a base64 image url string and I'm trying to generate a png,jpg image file from it. I'm able to decode it to a buffer but the trouble is getting it from buffer to an actual image file. Any library function combination I can use?

Re: Contributing to D wiki

2020-07-30 Thread John Burton via Digitalmars-d-learn
On Monday, 27 July 2020 at 16:58:13 UTC, H. S. Teoh wrote: On Mon, Jul 27, 2020 at 11:39:32AM +, John Burton via Digitalmars-d-learn wrote: [...] I tried looking there for information and examples of getting glfw3 statically linked into my program using LDC and didn't really find anything.

Re: Lack of asm volatile qualifier (explicitly) again.

2020-07-30 Thread Iain Buclaw via Digitalmars-d-learn
On Tuesday, 28 July 2020 at 06:57:36 UTC, Cecil Ward wrote: I read recently that all asm in D is regarded as ‘volatile’ in the GCC sense, which I take to mean that it is assume to potentially have side effects, and so cannot be optimised away to nothing by the compiler despite the lack of any