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

forkit forkit at gmail.com
Thu Jan 13 20:46:15 UTC 2022


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!pointers.array;
>
> ```d
> import std.stdio : writeln;
> import std.algorithm : filter, map, each;
> import std.range : array;
>
> void main() @safe
> {
>     immutable strings = ["one", "one", "two", "one", "two", 
> "one", "one", "two"];
>     immutable(string)*[] pointers = strings.filter!(x => x == 
> "one").map!((ref x) @trusted => &x).array;
>     pointers.each!(p => writeln(p - &strings[0]));
> }
> ```

just perfect! thanks.


More information about the Digitalmars-d-learn mailing list