Ranges: How to take N last of elements of range

via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Dec 25 06:13:15 PST 2015


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"]




More information about the Digitalmars-d-learn mailing list