On 12/5/17 2:41 PM, kdevel wrote:
On Tuesday, 5 December 2017 at 17:25:57 UTC, Steven Schveighoffer wrote:
[...]
struct LowerCaseFirst(R) // if(isSomeString!R)
{
R src;
bool notFirst; // terrible name, but I want default false
dchar front() {
import std.uni: toLower;
return notFirst ? src.front : src.front.toLower;
}
void popFront() { notFirst = true; src.popFront; }
bool empty() { return src.empty; }
}
auto lowerCaseFirst(R)(R r)
{
return LowerCaseFirst!R(r);
}
Warning: it ain't going to be fast. Auto-decoding everywhere.
But one cannot use the return value of lowerCaseFirst as argument for
foo(string).
Define foo as:
foo(R)(R r) if (isInputRange!R && isSomeChar!(ElementType!R))
Then it can take any range of char types.
Only the use as argument to writeln seems to work. Also I
had to put
import std.range.primitives : front, popFront, empty;
outside the struct otherwise the compiler complains about missing front,
popFront and empty for type string.
Yeah, it wasn't a complete example. These are the extensions to arrays
that allow them to work as ranges.
-Steve