How can I do dmd omite error when if compare two different data types ? (-fpermissive)
Ali Çehreli
acehreli at yahoo.com
Sun May 3 23:12:15 UTC 2020
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
More information about the Digitalmars-d-learn
mailing list