digitalmars.D.learn - Ranges: How to take N last of elements of range
- Ur nuz (45/45) Dec 25 2015 How to take N last of elements of range?
- drug (6/22) Dec 25 2015 You can do following http://dpaste.dzfl.pl/41c57f89a5a0
- Ur nuz (2/10) Dec 25 2015 Thanks for reply. This is useful
- Jakob Ovrum (2/12) Dec 27 2015 https://github.com/D-Programming-Language/phobos/pull/3855
How to take N last of elements of range?
I have tried the following example in my code, but it says that
it deprecated. What is the other possible way?
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 );
}
}
It says the following:
/usr/include/dmd/phobos/std/range/package.d(224): Deprecation:
function std.algorithm.iteration.splitter!("a == b", string,
string).splitter.Result.popBack is deprecated - splitter!(Range,
Range) cannot be iterated backwards (due to separator overlap).
/usr/include/dmd/phobos/std/range/package.d(223): Deprecation:
function std.algorithm.iteration.splitter!("a == b", string,
string).splitter.Result.back is deprecated - splitter!(Range,
Range) cannot be iterated backwards (due to separator overlap).
declarative/parser.d(68): Error: template std.range.retro cannot
deduce function from argument types !()(Take!(Result!())),
candidates are:
/usr/include/dmd/phobos/std/range/package.d(188):
std.range.retro(Range)(Range r) if
(isBidirectionalRange!(Unqual!Range))
declarative/parser.d(130): Error: template instance
declarative.parser.Parser!(TextForwardRange!(string,
LocationConfig(true, true, true, true,
true))).Parser.LogerInfo.write!(string, string) error
instantiating
declarative/interpreter_test.d(11): instantiated from
here: Parser!(TextForwardRange!(string, LocationConfig(true,
true, true, true, true)))
Failed: ["dmd", "-v", "-o-", "declarative/interpreter_test.d",
"-Ideclarative"]
Dec 25 2015
25.12.2015 17:13, Ur 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.
Dec 25 2015
On Friday, 25 December 2015 at 20:06:04 UTC, drug wrote:25.12.2015 17:13, Ur nuz пишет:Thanks for reply. This is useful[...]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.
Dec 25 2015
On Saturday, 26 December 2015 at 05:31:59 UTC, Ur nuz wrote:On Friday, 25 December 2015 at 20:06:04 UTC, drug wrote:https://github.com/D-Programming-Language/phobos/pull/385525.12.2015 17:13, Ur nuz пишет:Thanks for reply. This is useful[...]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.
Dec 27 2015








Jakob Ovrum <jakobovrum gmail.com>