www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Ranges: How to take N last of elements of range

reply Ur nuz <neuranuz gmail.com> writes:
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
parent reply drug <drug2004 bk.ru> writes:
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
parent reply Ur nuz <neuranuz gmail.com> writes:
On Friday, 25 December 2015 at 20:06:04 UTC, drug wrote:
 25.12.2015 17:13, Ur nuz пишет:
      [...]
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.
Thanks for reply. This is useful
Dec 25 2015
parent Jakob Ovrum <jakobovrum gmail.com> writes:
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:
 25.12.2015 17:13, Ur nuz пишет:
      [...]
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.
Thanks for reply. This is useful
https://github.com/D-Programming-Language/phobos/pull/3855
Dec 27 2015