Re: A slice consisting of non-consecutive elements of an array?

2022-01-13 Thread forkit via Digitalmars-d-learn
On Thursday, 13 January 2022 at 20:32:40 UTC, Stanislav Blinov wrote: On Thursday, 13 January 2022 at 19:52:27 UTC, forkit wrote: Any idea on how I can get a ptr (without hardcoding C style) e.g. something like this: immutable(string)*[] pointers = strings.filter!(x => x == "one").to!pointer

Re: A slice consisting of non-consecutive elements of an array?

2022-01-13 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 13 January 2022 at 19:52:27 UTC, forkit wrote: Any idea on how I can get a ptr (without hardcoding C style) e.g. something like this: immutable(string)*[] pointers = strings.filter!(x => x == "one").to!pointers.array; ```d import std.stdio : writeln; import std.algorithm : filt

Re: A slice consisting of non-consecutive elements of an array?

2022-01-13 Thread forkit via Digitalmars-d-learn
On Wednesday, 12 January 2022 at 06:16:49 UTC, vit wrote: Yes std.algorithm : filter. ```d import std.stdio : writeln; import std.algorithm : filter; void main()@safe{ auto a = ["one", "one", "two", "one", "two", "one", "one", "two"]; writeln(a); writeln(a.filter

Re: A slice consisting of non-consecutive elements of an array?

2022-01-11 Thread vit via Digitalmars-d-learn
On Wednesday, 12 January 2022 at 06:58:47 UTC, vit wrote: On Wednesday, 12 January 2022 at 06:43:40 UTC, forkit wrote: On Wednesday, 12 January 2022 at 06:16:49 UTC, vit wrote: Yes std.algorithm : filter. ```d import std.stdio : writeln; import std.algorithm : filter; void main()@safe{

Re: A slice consisting of non-consecutive elements of an array?

2022-01-11 Thread vit via Digitalmars-d-learn
On Wednesday, 12 January 2022 at 06:43:40 UTC, forkit wrote: On Wednesday, 12 January 2022 at 06:16:49 UTC, vit wrote: Yes std.algorithm : filter. ```d import std.stdio : writeln; import std.algorithm : filter; void main()@safe{ auto a = ["one", "one", "two", "one", "two", "one",

Re: A slice consisting of non-consecutive elements of an array?

2022-01-11 Thread forkit via Digitalmars-d-learn
On Wednesday, 12 January 2022 at 06:16:49 UTC, vit wrote: Yes std.algorithm : filter. ```d import std.stdio : writeln; import std.algorithm : filter; void main()@safe{ auto a = ["one", "one", "two", "one", "two", "one", "one", "two"]; writeln(a); writeln(a.filter

Re: A slice consisting of non-consecutive elements of an array?

2022-01-11 Thread vit via Digitalmars-d-learn
On Wednesday, 12 January 2022 at 05:27:08 UTC, forkit wrote: I am familiar with the concept of a slice in D. However, a slice is a consecutive slice, is in not? (e.g) [4..$-1] I would like a slice (or a view, or whatever name you wanna call it), of particular elements within an array that ma

A slice consisting of non-consecutive elements of an array?

2022-01-11 Thread forkit via Digitalmars-d-learn
I am familiar with the concept of a slice in D. However, a slice is a consecutive slice, is in not? (e.g) [4..$-1] I would like a slice (or a view, or whatever name you wanna call it), of particular elements within an array that may not be consecutive. e.g. [4-7,8,10,13-16] Consider below: