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). 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.

Reply via email to