testlib icon indicating copy to clipboard operation
testlib copied to clipboard

[Suggestion] Checking whether some opt keys exist & Specifying default values

Open alex9801 opened this issue 5 years ago • 2 comments

One possible syntax would be: bool has_n = has_opt<int>("n"); // true if integer n is specified as key, false otherwise int n = opt<int>("n", 100); // if integer n is not specified as key, returns default value 100

Also, it would be nice if bool type keys defaults to false, unless otherwise specified. It would suit -prop / --prop syntax better.

Currently, there is no way to implement such feature in user code without directly accessing __testlib_opts variable.

alex9801 avatar Jan 13 '20 09:01 alex9801

I meet the same issue. Make the bool type key false is very common in use. But now we can only use --key=false to solve it.

cubercsl avatar Mar 07 '20 13:03 cubercsl

I implemented all except int n = opt("n", 100);

MikeMirzayanov avatar Mar 18 '20 22:03 MikeMirzayanov

A bit late, but #136 implements this feature. Great!

alex9801 avatar Aug 24 '22 01:08 alex9801