Re: Populating nested AAs; "This wouldn't be so verbose in Ada 2020"

2019-12-07 Thread mipri via Digitalmars-d-learn
On Sunday, 8 December 2019 at 06:42:22 UTC, Paul Backus wrote: You can use the `require` function [1] for this: with (userHistory.require(host).require(user)) { if (isOk) ++ok; // renamed to avoid shadowing else ++evil; } Many "methods" for built-in AAs are located in the `object`

Re: Populating nested AAs; "This wouldn't be so verbose in Ada 2020"

2019-12-07 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 8 December 2019 at 04:17:45 UTC, mipri wrote: Hello, I've got this code: struct UserStats { int ok, evil; } // module-level variable UserStats[string][string] userHistory; and this code that populates it: // loop over DB query if (host !in userHistory)

Populating nested AAs; "This wouldn't be so verbose in Ada 2020"

2019-12-07 Thread mipri via Digitalmars-d-learn
Hello, I've got this code: struct UserStats { int ok, evil; } // module-level variable UserStats[string][string] userHistory; and this code that populates it: // loop over DB query if (host !in userHistory) userHistory[host] = typeof(userHistory[host]).init; if

Re: Using map result type

2019-12-07 Thread mipri via Digitalmars-d-learn
On Sunday, 8 December 2019 at 01:10:21 UTC, AA wrote: I'd like to accept the return type of map. From some previous questions that I should accept a template? In general this is what you want to do with any kind of range code, because you're not working with definite types, but with types that

Using map result type

2019-12-07 Thread AA via Digitalmars-d-learn
I'd like to accept the return type of map. From some previous questions that I should accept a template? So for something like: ``` void mapAccepter(Range)(Range r) { import std.array : array; import std.stdio : writeln; auto collected = r.array; writeln(collected); } void

Re: GC.collect inflating memory usage?

2019-12-07 Thread Rainer Schuetze via Digitalmars-d-learn
On 07/12/2019 12:20, cc wrote: > Given the following program: [...] > But when both FREE and COLLECT are enabled, things seem to spiral out of > control: > // FREE, COLLECT > Stats(16, 1048560, 16) >     848 4096 > 40960832  40964096 > 81920832  81924096 > 122880832 

Re: Profiling the memory in D

2019-12-07 Thread kerdemdemir via Digitalmars-d-learn
On Wednesday, 4 December 2019 at 22:51:45 UTC, Steven Schveighoffer wrote: I localized that the leak was actually being caused by websockets. I want to write down my experience because I did some weird stuff which seems to be working but I want to learn how it actually make sense and works.

Re: Thin UTF8 string wrapper

2019-12-07 Thread Joseph Rushton Wakeling via Digitalmars-d-learn
On Saturday, 7 December 2019 at 15:57:14 UTC, Jonathan M Davis wrote: There may have been some tweaks to std.encoding here and there, but for the most part, it's pretty ancient. Looking at the history, it's Seb who marked some if it as being a replacement for std.utf, which is just plain

Re: Thin UTF8 string wrapper

2019-12-07 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, December 7, 2019 5:23:30 AM MST Joseph Rushton Wakeling via Digitalmars-d-learn wrote: > On Saturday, 7 December 2019 at 03:23:00 UTC, Jonathan M Davis > > wrote: > > The module to look at here is std.utf, not std.encoding. > > Hmmm, docs may need updating then -- several functions

Re: Thin UTF8 string wrapper

2019-12-07 Thread Joseph Rushton Wakeling via Digitalmars-d-learn
On Saturday, 7 December 2019 at 03:23:00 UTC, Jonathan M Davis wrote: The module to look at here is std.utf, not std.encoding. Hmmm, docs may need updating then -- several functions in `std.encoding` explicitly state they are replacements for `std.utf`. Did you mean `std.uni`? It is

GC.collect inflating memory usage?

2019-12-07 Thread cc via Digitalmars-d-learn
Given the following program: //version=FREE; //version=COLLECT; import std.stdio; import std.datetime.stopwatch; import core.memory; immutable int[] intZ =