Re: How to alias

2022-01-14 Thread kyle via Digitalmars-d-learn
On Friday, 14 January 2022 at 17:56:48 UTC, Adam D Ruppe wrote: On Friday, 14 January 2022 at 17:48:41 UTC, kyle wrote: [...] alias works in term of compile-time names, not values. This means the `this` value, being run time, gets discarded. [...] Thanks Adam. We need a repository of

Re: How to alias

2022-01-14 Thread Adam D Ruppe via Digitalmars-d-learn
On Friday, 14 January 2022 at 17:48:41 UTC, kyle wrote: I'm trying to use ```alias``` in an operator overload to reduce typing, but what gets aliased is not what I expect. alias works in term of compile-time names, not values. This means the `this` value, being run time, gets discarded.

How to alias

2022-01-14 Thread kyle via Digitalmars-d-learn
I'm trying to use ```alias``` in an operator overload to reduce typing, but what gets aliased is not what I expect. Tested in DMD v2.098.1-dirty on Windows plus whatever versions of DMD, GDC, and LDC I have installed on Linux. Thanks. ``` struct Broke { double num; import std.traits

Re: Unintuitive behavior with shared classes & template member functions; is this intended?

2022-01-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/14/22 6:10 PM, Jaime wrote: Why does this happen? Is it intended behavior? I'm still somewhat new to D, so I'm not prepared to submit this as an issue quite yet; for all I know, there might be a good reason it works this way. This seems like a bug to me. This confusing problem really

Re: How to convert a chunks result to a two-dimensional array

2022-01-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/14/22 9:41 PM, Paul Backus wrote: On Saturday, 15 January 2022 at 01:49:14 UTC, forkit wrote: I want int[][] like this -> [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]] Any help will be appreciated. note: to2Darray is not a valid statement ;-) // --- module test; import

Unintuitive behavior with shared classes & template member functions; is this intended?

2022-01-14 Thread Jaime via Digitalmars-d-learn
Some code that produces the strange behavior I'm seeing: ```d shared class MyClass { this() {} this(As...)(As args) if (As.length > 0) {} } void main() { pragma(msg, typeof(new MyClass)); pragma(msg, typeof(new MyClass(1, 2, 3, "hello world"))); pragma(msg, typeof(new

Re: How to convert a chunks result to a two-dimensional array

2022-01-14 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jan 15, 2022 at 01:49:14AM +, forkit via Digitalmars-d-learn wrote: [...] > int[][] arrayOfarrays = iota(1, 16).chunks(5).to2Darray; // how to > convert this into [][] [...] auto arrayOfArrays = iota(1, 16).chunks(5).map!(r => r.array).array; T -- Winners never quit,

Re: How to convert a chunks result to a two-dimensional array

2022-01-14 Thread forkit via Digitalmars-d-learn
On Saturday, 15 January 2022 at 03:48:41 UTC, Steven Schveighoffer wrote: Alternatively (with only one allocation for the int[] data): ```d int[][] arrayOfArrays = iota(1, 16).array.chunks(5).array; ``` -Steve All answers were helpful ;-) But I like this one the best, because I find it

Re: How to convert a chunks result to a two-dimensional array

2022-01-14 Thread Salih Dincer via Digitalmars-d-learn
On Saturday, 15 January 2022 at 06:43:05 UTC, forkit wrote: On Saturday, 15 January 2022 at 03:48:41 UTC, Steven Schveighoffer wrote: int[][] arrayOfArrays = iota(1,16). array.chunks(5).array; -Steve All answers were helpful ;-) But I like this one the best, because I find it both easier

chunks result to array

2022-01-14 Thread forkit via Digitalmars-d-learn
I want to do the equivalent of this: int[][] arrayOfarrays = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]]; But getting the initialiser values using iota and chunks instead. Any help will be appreciated. note: to2Darray is not a valid statement ;-) // --- module test; import

How to convert a chunks result to a two-dimensional array

2022-01-14 Thread forkit via Digitalmars-d-learn
I want int[][] like this -> [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]] Any help will be appreciated. note: to2Darray is not a valid statement ;-) // --- module test; import std; void main() { int[][] arrayOfarrays = iota(1, 16).chunks(5).to2Darray; // how to convert

Re: How to convert a chunks result to a two-dimensional array

2022-01-14 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 15 January 2022 at 01:49:14 UTC, forkit wrote: I want int[][] like this -> [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]] Any help will be appreciated. note: to2Darray is not a valid statement ;-) // --- module test; import std; void main() { int[][]

Re: How to convert a chunks result to a two-dimensional array

2022-01-14 Thread forkit via Digitalmars-d-learn
On Saturday, 15 January 2022 at 02:41:08 UTC, Paul Backus wrote: import std.algorithm: map; import std.array: array; int[][] arrayOfArrays = iota(1, 16).chunks(5).map!array.array; oh. thanks! also it seems I reposted the same question (didn't realise this one got posted)

Re: chunks result to array

2022-01-14 Thread forkit via Digitalmars-d-learn
On Saturday, 15 January 2022 at 03:18:21 UTC, forkit wrote: oops. ignore this - was a repost of another post that I thought never got posted ;-)