May 03, 2020 How can I do dmd omite error when if compare two different data types ? (-fpermissive) | ||||
---|---|---|---|---|
| ||||
In C++ I just use -fpermissive foreach(i; tuple(10, "lemon", false, "John", 1.6, 'c')) { writeln(i); if(i == "John") break; // Error } |
May 03, 2020 Re: How can I do dmd omite error when if compare two different data types ? (-fpermissive) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marcone | On 5/3/20 4:03 PM, Marcone wrote:
> In C++ I just use -fpermissive
>
> foreach(i; tuple(10, "lemon", false, "John", 1.6, 'c'))
> {
> writeln(i);
> if(i == "John") break; // Error
> }
I am not sure I understand your question because it already omits an error. If you're asking how to get that code do what I think you want, then the 'is' expression can be used with 'static if' to include the comparison into the program only for string types:
import std.typecons;
import std.stdio;
void main() {
foreach(i; tuple(10, "lemon", false, "John", 1.6, 'c')) {
writeln(i);
static if (is (typeof(i) == string)) {
if(i == "John") break;
}
}
}
Ali
|
Copyright © 1999-2021 by the D Language Foundation