How to use retro over findSplitBefore result?
MrSmith
mrsmith33 at yandex.ru
Wed Dec 4 09:43:21 PST 2013
I am trying to compile following code
import std.algorithm : findSplitBefore;
import std.range : retro;
import std.array : array;
// returns file path where name has suffix and prefix
string withSuffixPrefix(string filePath, string prefix, string
suffix)
{
auto splitted = filePath.retro.findSplitBefore("/");
return cast(string)splitted[1].retro.array
~ prefix
~ cast(string)splitted[0].retro.array //Fails!
~ suffix;
}
With following error:
build.d(56): Error: template std.range.retro does not match any
function template declaration. Candidates are:
/phobos/std/range.d(1455): std.range.retro(Range)(Range r) if
(isBidirectionalRange!(Unqual!Range))
build.d(56): Error: template std.range.retro(Range)(Range r) if
(isBidirectionalRange!(Unqual!Range)) cannot deduce template
function from argument types !()(Result)
Seems like i need to somehow convert splitted[0] to Bidirectional
range.
This function will be used like this:
assert(withSuffixPrefix("/some/random/path/to/file", "pref-",
".fl") == "/some/random/path/to/pref-file.fl");
More information about the Digitalmars-d-learn
mailing list