Ranges: How to take N last of elements of range

drug via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Dec 25 12:06:04 PST 2015


25.12.2015 17:13, Ur at nuz пишет:
> static struct LogerInfo
>      {
>          string func;
>          int line;
>
>          void write(T...)(T data)
>          {
>              import std.stdio;
>              import std.algorithm: splitter;
>              import std.range: retro;
>              import std.range: take;
>              import std.array: array;
>
>              string shortFuncName =
> func.splitter(".").retro.take(2).retro.array;
>              writeln( shortFuncName, "[", line, "]:  ", data );
>          }
>      }
You can do following http://dpaste.dzfl.pl/41c57f89a5a0
The reason of compile error is your using a range as a separator, change 
it to single symbol and it works. Also I used 'array' after 'take' to 
make range bidirectional to let next 'retro' works. And 'join' joins 
result to string with '.' as a separator.


More information about the Digitalmars-d-learn mailing list