[Issue 4716] New: std.stdio.input() or similar

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Aug 22 20:02:45 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=4716

           Summary: std.stdio.input() or similar
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2010-08-22 20:02:39 PDT ---
If not already present, a function template similar to this one may be useful
for the std.stdio module. Similar functions are present in Basic and Python
languages:


T input(T)(string msg) {
    write(msg);
    auto read = readln();
    static if (!is(T == string) && !is(T == dstring) &&!is(T == wstring))
        read = read.strip();
    return to!T(read);
}


To be used mostly in scripts, as:

double x = input!double("Enter value x: ");

Its name may be changed if there is collision with something different, but it
needs to be simple, given its purpose.

This function may be made much more refined, but I suggest to keep it simple.
Even the static if it contains is more complex than originally thought.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list