Getopt default int init and zero

Suliman via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 19 05:09:38 PDT 2017


I would like to check if user specified `0` as getopt parameter. 
But the problem that `int`'s are default in `0`. So if user did 
not specified nothing `int x` will be zero, and all other code 
will work as if it's zero.

In std.typecons I found Nullable that allow init int to zero. I 
tried to do:

Nullable!int dateInterval;

try
{
	auto helpInformation = getopt(args,
	"interval|i",  "Interval of selection in dayes", &dateInterval
	);
}

But I am getting error:

conv.d(194,24): Error: template std.conv.toImpl cannot deduce 
function from argument types !(Nullable!int)(string), candidates 
are:
conv.d(435,11):        std.conv.toImpl(T, S)(S value) if 
(isImplicitlyConvertible!(S, T) && !isEnumStrToStr!(S, T) && 
!isNullToStr!(S, T))
conv.d(549,11):        std.conv.toImpl(T, S)(ref S s) if 
(isStaticArray!S)
conv.d(565,11):        std.conv.toImpl(T, S)(S value) if 
(!isImplicitlyConvertible!(S, T) && is(typeof(S.init.opCast!T()) 
: T) && !isExactSomeString!T && !is(typeof(T(value))))
conv.d(616,11):        std.conv.toImpl(T, S)(S value) if 
(!isImplicitlyConvertible!(S, T) && is(T == struct) && 
is(typeof(T(value))))
conv.d(665,11):        std.conv.toImpl(T, S)(S value) if 
(!isImplicitlyConvertible!(S, T) && is(T == class) && 
is(typeof(new T(value))))
conv.d(194,24):        ... (9 more, -v to show) ...
getopt.d(894,56): Error: template instance 
std.conv.to!(Nullable!int).to!string error instantiating
getopt.d(749,46):        instantiated from here: 
handleOption!(Nullable!int*)
getopt.d(758,23):        instantiated from here: 
getoptImpl!(string, string, Nullable!int*, string, string, bool*)
getopt.d(436,15):        instantiated from here: 
getoptImpl!(string, string, int[]*, string, string, 
Nullable!int*, string, string, bool*)
source\app.d(41,32):        instantiated from here: 
getopt!(string, string, int[]*, string, string, Nullable!int*, 
string, string, bool*)


More information about the Digitalmars-d-learn mailing list