How to apply multiple operands to a single operator?
An example:
instead of
if (foo == "dog" || foo == "cat" || foo == "human")
I can have the following or similar:
if (foo == ("dog" || "cat" || "human"));
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your first version already includes multiple operators in one expression. It sounds like you want to apply multiple operands (“dog”, “cat”, “human”) to a single operator (
==in this case).For that specific example you could use:
But there’s no general one-size-fits-all version of this for all operators.
EDIT: As noted in comments, the above won’t perform as well as the hard-coded version.