Hello!
It seems to me that over the past few years I have been writing something right while all normal people are celebrating the New Year. It's my tradition now! Actually, most of the core functionality of Codeforces was written on the New Year holidays of 2010: authorization, blogs, basic support for competitions.
Perhaps I want to spend the next year with interest improving something in the Codeforces infrastructure (yep, how you celebrate the New Year — so you will spend it). Or maybe it's just that it's not necessary to work on New Year's and I'm doing not what you need right now, but what would be nice to do someday.
This time I took a little time to add support for parsing command line parameters in testlib. I really don't like to write such lines of code int n = atoi(argv[3]); in generators. Actually for several reasons:
- it is unsafe that the 3rd command line parameter may be absent;
- It is unsafe that the 3rd command line parameter may not be a valid 32-bit integer.
Now, instead, you should write this: int n = opt<int>(3);. In addition, you can write like this int64_t m = opt<int64_t>(1); or bool t = opt<bool>(2); or even string s = opt(4);.
In addition, I supported named parameters. If there are too many parameters, then the entry g 10 20000 a true is less readable than g -n10 -m200000 -t=a -increment.
In this case, now you can use the following code snippets in your generator:
int n = opt<int>("n");
long long n = opt<long long>("m");
string t = opt("t");
bool increment = opt<bool>("increment");
You can freely mix parameter reading by index and by name.
The following options for writing named parameters are supported:
--key = valueor-key = value;--key valueor-key value— ifvalueis not a start of a new parameter (does not start with a hyphen or does not follow the letter after one/two hyphens);--k12345or-k12345— if the keykis one letter and then a digit comes;-propor--prop— to enable boolean properties.
Below are examples of how to run several fictional generators:
g1 -n1
g2 --len=4 --s=oops
g3 -inc -shuffle -n=5
g4 --length 5 --total 21 -ord
Perhaps in a hurry, I can write something not in the best way, or even with bugs. I suggest you look at my last commits. I will be glad to suggestions or fixes.
Thanks for attention.
What traditions do you have for the New Year?








Change Handle Feature



and you'll see the code with the highlighted problematic line and description with the possible reason of the mistake.


