www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How can I do dmd omite error when if compare two different data types

reply Marcone <marcone email.com> writes:
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
parent =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 5/3/20 4:03 PM, Marcone wrote:
 In C++ I just use -fpermissive
=20
 foreach(i; tuple(10, "lemon", false, "John", 1.6, 'c'))
 {
  =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 writeln(i);
  =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if(i =3D=3D "John") break; =
// Error
 }
I am not sure I understand your question because it already omits an=20 error. If you're asking how to get that code do what I think you want,=20 then the 'is' expression can be used with 'static if' to include the=20 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) =3D=3D string)) { if(i =3D=3D "John") break; } } } Ali
May 03 2020