Google Code Jam 2011 Language Usage
Andrej Mitrovic
andrej.mitrovich at gmail.com
Sun May 8 14:28:05 PDT 2011
I'm very happy with using Jesse's interact library for user input:
https://github.com/he-the-great/JPDLibs/tree/cmdln
Last time I've used it I combined it with std.conv since I needed
either a number or a "q" from the user, e.g.:
int input;
auto line = userInput!string("Enter value:");
if (line == "q")
{
quit();
}
else if (!throws!(ConvException)( { input = to!int(line); } )) // try
converting to int
{
if (input >= -127 && input <= 127)
{
// do something
}
}
Here throws() is just a custom function that asserts that a delegate throws.
More information about the Digitalmars-d
mailing list