Are D classes proper reference types?

2021-06-23 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
D classes are distinct from structs because they are intended to be bound to a reference (pointer) and not addressed as a value (inline/copying). But for efficiency reasons, scoped classes can stack-allocate, but my understanding is that the compiler can still allocate it on the GC heap? So i

Re: is it possible to sort a float range ?

2021-06-23 Thread jfondren via Digitalmars-d-learn
On Thursday, 24 June 2021 at 02:33:42 UTC, someone wrote: On Thursday, 24 June 2021 at 01:36:47 UTC, Ali Çehreli wrote: import std.algorithm; lnumRange.sort!(r"a > b"c); return lnumRange; The above works OK. Funny thing indeed, at least to me, totally unexpected. ```d ret

Re: how to filter associative arrays with foreach ?

2021-06-23 Thread someone via Digitalmars-d-learn
On Monday, 21 June 2021 at 08:31:16 UTC, Ali Çehreli wrote: Two options for byKey and byKeyValue: import std; void main() { auto aa = [ "WS2" : 42, "WS3" : 43 ]; string strComputerIDunwanted = "WS2"; foreach (key; aa.byKey.filter!(k => k != strComputerIDunwanted)) { writeln(key, '

Re: is it possible to sort a float range ?

2021-06-23 Thread someone via Digitalmars-d-learn
On Thursday, 24 June 2021 at 01:36:47 UTC, Ali Çehreli wrote: import std.algorithm; lnumRange.sort!(r"a > b"c); return lnumRange; The above works OK. Funny thing indeed, at least to me, totally unexpected. ```d return lnumRange.sort!(r"a > b"c); /// does not work return l

Re: is it possible to sort a float range ?

2021-06-23 Thread Ali Çehreli via Digitalmars-d-learn
On 6/23/21 6:09 PM, mw wrote: > I think in most other popular language's std lib: > > container.sort(); > > or > > sort(container); > > > is just one call, and the user will expect the `container` is sorted > after the call. That's exactly the same in D. What's different is, D's sort() does not

Re: Default values in passing delegates to functions

2021-06-23 Thread Ali Çehreli via Digitalmars-d-learn
On 6/23/21 9:16 AM, Anonamoose wrote: > I have a script in which I want a special case where someone can input > something like a potential or a dispersion relation for use in physics > simulations. I want to clean up the implementation for users as not > every situation requires these. So I wrot

Re: is it possible to sort a float range ?

2021-06-23 Thread mw via Digitalmars-d-learn
On Thursday, 24 June 2021 at 00:47:28 UTC, mw wrote: On Thursday, 24 June 2021 at 00:32:31 UTC, Steven Schveighoffer This `SortedRange` definitely need better documentation. E.g. users can easily convert their `sort()` code to D from Java or Python code after reading the doc. I think in m

Re: is it possible to sort a float range ?

2021-06-23 Thread mw via Digitalmars-d-learn
On Thursday, 24 June 2021 at 00:32:31 UTC, Steven Schveighoffer wrote: On 6/23/21 7:07 PM, someone wrote: On Wednesday, 23 June 2021 at 22:46:28 UTC, Steven Schveighoffer wrote: Use the `release` method: ```d return lnumRange.sort!(...).release; ``` Fantastic, issue solved, I previously u

Re: is it possible to sort a float range ?

2021-06-23 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/23/21 7:07 PM, someone wrote: On Wednesday, 23 June 2021 at 22:46:28 UTC, Steven Schveighoffer wrote: Use the `release` method: ```d return lnumRange.sort!(...).release; ``` Fantastic, issue solved, I previously used sort ascending even descending but first time on floats. So I went

Re: is it possible to sort a float range ?

2021-06-23 Thread someone via Digitalmars-d-learn
On Wednesday, 23 June 2021 at 22:46:28 UTC, Steven Schveighoffer wrote: Use the `release` method: ```d return lnumRange.sort!(...).release; ``` -Steve Fantastic, issue solved, I previously used sort ascending even descending but first time on floats. So I went and searched phobos docs:

Re: is it possible to sort a float range ?

2021-06-23 Thread Jordan Wilson via Digitalmars-d-learn
On Wednesday, 23 June 2021 at 22:46:28 UTC, Steven Schveighoffer wrote: On 6/23/21 6:30 PM, Jordan Wilson wrote: On Wednesday, 23 June 2021 at 19:53:24 UTC, someone wrote: [...] ```sort``` returns a ```SortedRange```, and I believe you wish to return a float. So you can do either ```return

Re: is it possible to sort a float range ?

2021-06-23 Thread someone via Digitalmars-d-learn
On Wednesday, 23 June 2021 at 22:30:29 UTC, Jordan Wilson wrote: ```sort``` returns a ```SortedRange```, and I believe you wish to return a float. no, I want to return the range (full of floats) sorted -think it amount or prices or whatever

Re: Detect if a struct is a 3-float vector

2021-06-23 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/23/21 6:36 PM, JN wrote: I'm looking for a way to test a struct for these conditions: 1. has members named x, y and z 2. these members are floating point type This works, but feels kinda verbose, is there some shorter way? Can I somehow avoid the hasMember/getMember calls? ```d import s

Re: is it possible to sort a float range ?

2021-06-23 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/23/21 6:30 PM, Jordan Wilson wrote: On Wednesday, 23 June 2021 at 19:53:24 UTC, someone wrote: Please, look for the line marked +++ This is a structure with a public property returning a (still unsorted) range built on-the-fly from already-set properties, a basic range from a to z with n

Detect if a struct is a 3-float vector

2021-06-23 Thread JN via Digitalmars-d-learn
I'm looking for a way to test a struct for these conditions: 1. has members named x, y and z 2. these members are floating point type This works, but feels kinda verbose, is there some shorter way? Can I somehow avoid the hasMember/getMember calls? ```d import std.traits; struct Vector3f {

Re: is it possible to sort a float range ?

2021-06-23 Thread Jordan Wilson via Digitalmars-d-learn
On Wednesday, 23 June 2021 at 19:53:24 UTC, someone wrote: Please, look for the line marked +++ This is a structure with a public property returning a (still unsorted) range built on-the-fly from already-set properties, a basic range from a to z with n step where some specific values can be a

is it possible to sort a float range ?

2021-06-23 Thread someone via Digitalmars-d-learn
Please, look for the line marked +++ This is a structure with a public property returning a (still unsorted) range built on-the-fly from already-set properties, a basic range from a to z with n step where some specific values can be added in-between. The range is a float which I am currently

Re: String front, back return code point/unit

2021-06-23 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jun 23, 2021 at 04:01:24PM +, vit via Digitalmars-d-learn wrote: [...] > My question is not about ranges/iterators but if is good idea > autodecoding custom string or not. No. Autodecoding is one of the decisions we regret because it introduces an unavoidable overhead on basically eve

Default values in passing delegates to functions

2021-06-23 Thread Anonamoose via Digitalmars-d-learn
I have a script in which I want a special case where someone can input something like a potential or a dispersion relation for use in physics simulations. I want to clean up the implementation for users as not every situation requires these. So I wrote a function with the signature ``` d void

Re: String front, back return code point/unit

2021-06-23 Thread vit via Digitalmars-d-learn
On Wednesday, 23 June 2021 at 15:48:57 UTC, Tejas wrote: On Wednesday, 23 June 2021 at 15:31:04 UTC, vit wrote: Hello, I am implementing @nogc string struct similar to c++ std::basic_string (link https://code.dlang.org/packages/basic_string). C++ string has methods front, back and pop_back

Re: String front, back return code point/unit

2021-06-23 Thread Tejas via Digitalmars-d-learn
On Wednesday, 23 June 2021 at 15:31:04 UTC, vit wrote: Hello, I am implementing @nogc string struct similar to c++ std::basic_string (link https://code.dlang.org/packages/basic_string). C++ string has methods front, back and pop_back returning/deleting code units. D strings has functions (s

String front, back return code point/unit

2021-06-23 Thread vit via Digitalmars-d-learn
Hello, I am implementing @nogc string struct similar to c++ std::basic_string (link https://code.dlang.org/packages/basic_string). C++ string has methods front, back and pop_back returning/deleting code units. D strings has functions (std.range) front, back and popBack returning/deleting co