Re: Selected elements from splitter output

2021-05-04 Thread Chris Piker via Digitalmars-d-learn
On Tuesday, 4 May 2021 at 22:02:11 UTC, Ali Çehreli wrote: On 5/4/21 1:40 PM, Chris Piker wrote: > I only care about columns 0, 2, 3, 4, 8, 9, 10. That's std.range.stride. > char[][] wanted = string_range.get( [1, 5, 7] ); // pseudo-code element That's std.range.indexed. Hey Thanks! And e

Re: Pointer indirections

2021-05-04 Thread Ali Çehreli via Digitalmars-d-learn
On 5/4/21 3:06 PM, Imperatorn wrote: >> Is there any limitation as to the number of pointer indirections? No. >> I have a construct: >>a.b.c.d = x; >> where all the variables are pointers to struct (the same struct). >> >> This fails with 'Access Violation', >> but if I change the code to:

Re: Pointer indirections

2021-05-04 Thread Imperatorn via Digitalmars-d-learn
On Tuesday, 4 May 2021 at 21:16:10 UTC, DLearner wrote: Hi Is there any limitation as to the number of pointer indirections? I have a construct: a.b.c.d = x; where all the variables are pointers to struct (the same struct). This fails with 'Access Violation', but if I change the code to

Re: Selected elements from splitter output

2021-05-04 Thread Ali Çehreli via Digitalmars-d-learn
On 5/4/21 3:02 PM, Ali Çehreli wrote: >// Note: The above works only because 'stride' applies >// "design by introspection" (DbI) and is able to work as a >// RandomAccessRanges. Ok, I was too enthusiastic there. The RandomAccessRange'ness of the input range changes how efficient st

Re: Selected elements from splitter output

2021-05-04 Thread Ali Çehreli via Digitalmars-d-learn
On 5/4/21 1:40 PM, Chris Piker wrote: > I only care about columns 0, 2, 3, 4, 8, 9, 10. That's std.range.stride. > char[][] wanted = string_range.get( [1, 5, 7] ); // pseudo-code element That's std.range.indexed. import std.range; import std.stdio; void main() { auto r = 10.iota.stride(2)

Pointer indirections

2021-05-04 Thread DLearner via Digitalmars-d-learn
Hi Is there any limitation as to the number of pointer indirections? I have a construct: a.b.c.d = x; where all the variables are pointers to struct (the same struct). This fails with 'Access Violation', but if I change the code to: temp = a.b.c; temp.d = x; everything seems to work. Be

Selected elements from splitter output

2021-05-04 Thread Chris Piker via Digitalmars-d-learn
Hi D I have a white-space delimited file with quite a few columns, but I only care about columns 0, 2, 3, 4, 8, 9, 10. Since I don't need most of the 60+ columns it seemed like: std.algorithm.iteration.splitter() would be a better function to use then std.array.split(). My problem is t

Re: Should this always work?

2021-05-04 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Tuesday, 4 May 2021 at 14:18:30 UTC, Ola Fosheim Grøstad wrote: On Tuesday, 4 May 2021 at 13:58:59 UTC, Steven Schveighoffer wrote: Yeah, I wasn't aware of the more general usage, I thought it was always a pointer adjustment. But I also am not steeped in the terminology, just parroting what

Re: Should this always work?

2021-05-04 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Tuesday, 4 May 2021 at 13:58:59 UTC, Steven Schveighoffer wrote: Yeah, I wasn't aware of the more general usage, I thought it was always a pointer adjustment. But I also am not steeped in the terminology, just parroting what I've heard. My understanding is that a thunk is the code object th

Re: Should this always work?

2021-05-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/4/21 6:03 AM, Ola Fosheim Grøstad wrote: On Tuesday, 4 May 2021 at 01:20:15 UTC, Q. Schroll wrote: On Saturday, 1 May 2021 at 06:17:36 UTC, Mike Parker wrote: On Saturday, 1 May 2021 at 04:55:10 UTC, frame wrote: I always thought as long as an object implements an interface, it should be

Re: Should this always work?

2021-05-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/4/21 9:21 AM, Paul Backus wrote: On Tuesday, 4 May 2021 at 10:21:42 UTC, Ola Fosheim Grøstad wrote: On Saturday, 1 May 2021 at 16:06:05 UTC, Steven Schveighoffer wrote: An interface cast involves a thunk (constant pointer adjustment) to get to the interface/object Yes, but it isn't a htt

Re: Should this always work?

2021-05-04 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 4 May 2021 at 01:20:15 UTC, Q. Schroll wrote: On Saturday, 1 May 2021 at 06:17:36 UTC, Mike Parker wrote: No. An interface is like a pointer to a pointer. Can you elaborate on this one? I don't really get it. Is an object handle also like a pointer to a pointer? (I feel like I c

Re: Should this always work?

2021-05-04 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 4 May 2021 at 10:21:42 UTC, Ola Fosheim Grøstad wrote: On Saturday, 1 May 2021 at 16:06:05 UTC, Steven Schveighoffer wrote: An interface cast involves a thunk (constant pointer adjustment) to get to the interface/object Yes, but it isn't a https://en.wikipedia.org/wiki/Thunk ? Th

Re: How to automatically generate function overloads

2021-05-04 Thread Blatnik via Digitalmars-d-learn
On Tuesday, 4 May 2021 at 11:21:20 UTC, Zone wrote: ```D template Vectorize_Unary_Function(alias fun) { float[N] Vectorize_Unary_Function(size_t N)(float[N] vec) { float[N] result; static foreach (i; 0 .. N) result[i] = fun(vec[i]); return result; }

Re: How to automatically generate function overloads

2021-05-04 Thread Zone via Digitalmars-d-learn
On Tuesday, 4 May 2021 at 11:00:42 UTC, Blatnik wrote: I'm porting over my linear algebra library from C++, and I have a bunch of functions that work on both scalars and vectors. The vector versions just apply the scalar function to every element of the vector, for example: ```D float clamp01

Re: How to automatically generate function overloads

2021-05-04 Thread Blatnik via Digitalmars-d-learn
On Tuesday, 4 May 2021 at 11:00:42 UTC, Blatnik wrote: How could I do this? I've already tried this: ```D mixin template Vectorize_Unary_Function(alias Function) { float[N] Function(size_t N)(float[N] vec) { float[N] result; static foreach (i; 0 .. N) result[i] = Function(vec

How to automatically generate function overloads

2021-05-04 Thread Blatnik via Digitalmars-d-learn
I'm porting over my linear algebra library from C++, and I have a bunch of functions that work on both scalars and vectors. The vector versions just apply the scalar function to every element of the vector, for example: ```D float clamp01(float x) { return x < 0 ? 0 : (x > 1 ? 1 : x); } float

Re: Should this always work?

2021-05-04 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Saturday, 1 May 2021 at 16:06:05 UTC, Steven Schveighoffer wrote: An interface cast involves a thunk (constant pointer adjustment) to get to the interface/object Yes, but it isn't a https://en.wikipedia.org/wiki/Thunk ?

Re: Should this always work?

2021-05-04 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Tuesday, 4 May 2021 at 01:20:15 UTC, Q. Schroll wrote: On Saturday, 1 May 2021 at 06:17:36 UTC, Mike Parker wrote: On Saturday, 1 May 2021 at 04:55:10 UTC, frame wrote: I always thought as long as an object implements an interface, it should be able to cast it from a void* if it really poin