Re: alias Error: need 'this'

2023-03-19 Thread bomat via Digitalmars-d-learn
On Sunday, 19 March 2023 at 12:29:19 UTC, Salih Dincer wrote: It is possible to achieve the convenience you want to achieve in 2 ways. One of them is to use a static member but if not, to use an alias inside the container. Thanks for the suggested workaround, I can live with the `static`

Re: alias Error: need 'this'

2023-03-19 Thread Basile B. via Digitalmars-d-learn
On Sunday, 19 March 2023 at 13:49:36 UTC, bomat wrote: Thanks for the suggested workaround, I can live with the `static` solution, I guess. I still don't understand why it's necessary, though. Since a `struct` is a value type and, as I understand it, stack allocated, what difference does it

Re: Traverse a DList and insert / remove in place?

2023-03-19 Thread Armando via Digitalmars-d-learn
ok there is the issue of not knowing how to traverse the list after removing the current element (=> the one that came after of course). But how about even just keeping a pointer (range) to 'element' that can be used after the list has been traversed in full to use in remove / insertAfter? I

Re: Difference between using `import` with/without the colon

2023-03-19 Thread Jeremy via Digitalmars-d-learn
On Sunday, 19 March 2023 at 08:47:32 UTC, Basile B. wrote: On Sunday, 19 March 2023 at 07:20:17 UTC, Jeremy wrote: [...] The colon-form, aka "selective import" has for effect 1. to create a local alias so this can indeed speedup symbol lookups in the sense that search will succeed before

Traverse a DList and insert / remove in place?

2023-03-19 Thread Armando via Digitalmars-d-learn
Say I have a DList. I am looking for a vanilla way to insert/remove elements in place while traversing that list. ```d import std.container : DList; struct myType{ int id; // [...] other stuff } auto list = DList!myType(); // [...] populate list with elements ``` To remove the element

Re: alias Error: need 'this'

2023-03-19 Thread Ali Çehreli via Digitalmars-d-learn
On 3/19/23 06:49, bomat wrote: > I can live with the `static` > solution, I guess. If you could, you would define it 'static' anyway. :) Because you highly likely needed a distinct 'variableWithALongName' member for each MyStruct object, that wouldn't work. > Shouldn't it be the exact same

Re: Difference between using `import` with/without the colon

2023-03-19 Thread Basile B. via Digitalmars-d-learn
On Sunday, 19 March 2023 at 07:20:17 UTC, Jeremy wrote: Hello, is there any difference at all between the following lines, as an example: ```d import std.regex; import std.regex : matchFirst; ``` What technical differences does it make (except for having the identifier available), using the

std.net.curl.HTTP: can't download more than 3.6K

2023-03-19 Thread Jeremy via Digitalmars-d-learn
Hello, I'm new to D and the `std.net.curl` library. I'm using the `HTTP` struct because I need to set headers for an API, and most of the time, I can only download 3.6 kilobytes at a time. Would this be a problem with the library not following redirects or something else? I'm not really sure

alias Error: need 'this'

2023-03-19 Thread bomat via Digitalmars-d-learn
Hi, I read about aliases today and thought it would be handy for shortening repeated access to struct members. However, I'm clearly missing something. Here's some example code: ``` int variableWithALongName = 42; alias alias1 = variableWithALongName; alias1 = 43; assert(variableWithALongName

Difference between using `import` with/without the colon

2023-03-19 Thread Jeremy via Digitalmars-d-learn
Hello, is there any difference at all between the following lines, as an example: ```d import std.regex; import std.regex : matchFirst; ``` What technical differences does it make (except for having the identifier available), using the colon? Does it make any speed/optimization changes or am

Re: alias Error: need 'this'

2023-03-19 Thread Salih Dincer via Digitalmars-d-learn
On Sunday, 19 March 2023 at 11:52:50 UTC, bomat wrote: It works fine with the `int` variable, but with the struct member I get a compilation error: ``` Error: need `this` for `memberWithALongName` of type `int` ``` What is that supposed to mean? It is possible to achieve the convenience you

Re: std.net.curl.HTTP: can't download more than 3.6K

2023-03-19 Thread Jeremy via Digitalmars-d-learn
Nevermind, it was my fault. I fixed my problem by appending the received buffer to my data buffer instead of overwriting my data buffer each time.