On Fri, 22 Jan 2010 22:55:45 +0100, strtr <st...@spam.com> wrote:
This may be is a very basic question, but is there a way to let me omit
a repeating variable when doing multiple boolean operations?
if ( var == a || var == b || var == c || var == d)
if ( var == (a || b || c || d) )
bool anySame( T, U... )( T arg1, U args ) {
foreach ( arg; args ) {
if ( arg1 == arg ) {
return true;
}
}
return false;
}
bool allSame( T, U... )( T arg1, U args ) {
foreach ( arg; args ) {
if ( arg1 != arg ) {
return false;
}
}
return true;
}
Not tested, but they should work:
if ( anySame( var, a, b, c, d ) ) {
}
if ( allSame( var, a, b, c, d ) ) {
}
--
Simen