Hello All,

I wrote the following convenience functions to aid in my studies. Unfortunately, I'm using Java books (Ali I will get to yours soon enough) so the need was necessitated by the frequency of use in the examples. Would appreciate a sanity check. Is there something that I should be thinking about am obviously not? Comments/criticisms appreciated.

------------ io.d ------------
module io;

public import std.stdio;

private string buffer;

auto next(T)()
{
        import std.traits;
        import std.conv;
        import std.string;

        if(buffer.length == 0)
                buffer = stdin.readln;

        static if (isSomeString!T) {
                scope (exit) buffer = null;
                return buffer.strip;
        }
        else {
                scope (exit) buffer = buffer.strip;
                return parse!T(buffer);
        }
}

auto next(T)(string msg)
{
        if (msg != null)
                msg.write;

        return next!T;
}
------------ End ------------

Thanks,
Andrew
  • next!T Andrew Edwards via Digitalmars-d-learn
    • Re: next!T Ali Çehreli via Digitalmars-d-learn
      • Re: next!T Andrew Edwards via Digitalmars-d-learn
      • Re: next!T Andrew Edwards via Digitalmars-d-learn
        • Re: next!T Chris Nicholson-Sauls via Digitalmars-d-learn
          • Re: next!T Andrew Edwards via Digitalmars-d-learn
            • Re: ne... Chris Nicholson-Sauls via Digitalmars-d-learn

Reply via email to