Type Parameter Deduction
Salih Dincer
salihdb at hotmail.com
Tue May 10 09:26:46 UTC 2022
Hi All,
The problem is that I want to disable the use of boolean type.
But this is not possible with contract programming or otherwise.
Actually, it's possible to fix it with contract programming or
otherwise throwing errors.
```d
alias ir = inclusiveRange;
auto inclusiveRange(T = int)(T f = T(0), T l = T(0), T s = T(1))
in(!is(T == bool), "Boolean type cannot be used!") {/*
{
static if(is(T == bool))
{
import std.format;
assert(false, format("This type (%s) cannot be used!",
typeid(T)));
}//*/
if(!l) {
l = f;
f = 0;
}
return InclusiveRange!T(f, l, s);
} /* Error:
* operation not allowed on `bool` `this.last -= this.step`
*/
```
However, the compiler catches other errors! How can I solve this
problem?
Thanks...
SDB at 79
More information about the Digitalmars-d-learn
mailing list