Specifically in C++
if (x == a || x == b)
I wish there was an abbreviated way of expressing if x equals a or b.
Specifically in C++
if (x == a || x == b)
I wish there was an abbreviated way of expressing if x equals a or b.
if (std::boost::comparisons::std::equals_either(x) > b)
inline int x_eq_a_or_b( int x, int a, int b )
{
return ( x == a || x == b );
}
C++ was a mistake
Using some math trick? No. But that's what macros are for.
constexpr auto my_or (auto x, auto a, auto b)
{
return x == a or x == b;
}
If(!(X^A) || !(X^B))
...
Oh wait even better:
If(X^~A || X^~B)
...
niggerlicious
big brain
Oh wait there's a problem with that one. Hotfix:
If(!(X&~A) | !(X&~B))
...
#include
using namespace std;
int x = b = 5, a = 2;
int my_list[2] = {a, b};
if (find(my_list.begin(), my_list.end(), x) != my_list.end()){
// Do stuff
}
kek
for some annoying reason I don't think any language has this feature even though I want to do it all the time.
You mean besides defining a function?
If x == b this fails...
1/(b/a/b) == b
1 == b(b/a/b)
1 == b(1/a)
1 == b/a
a == b -> bad assumption
if x in (a, b):
print("you're mother is a nigger")
if x in [a, b]:
print "python a shit"
apparently i cant read and didnt see this was already posted
sorry for being a nonce
If you don't care about the order of your comparisons, please use a set.
>>> import dis
>>> def test_tuple(x):
... return x in (1, 2)
...
>>> dis.dis(test_tuple)
2 0 LOAD_FAST 0 (x)
2 LOAD_CONST 1 ((1, 2))
4 COMPARE_OP 6 (in)
6 RETURN_VALUE
>>> def test_list(x):
... return x in [1, 2]
...
>>> dis.dis(test_list)
2 0 LOAD_FAST 0 (x)
2 LOAD_CONST 1 ((1, 2))
4 COMPARE_OP 6 (in)
6 RETURN_VALUE
>>> def test_set(x):
... return x in {1, 2}
...
>>> dis.dis(test_set)
2 0 LOAD_FAST 0 (x)
2 LOAD_CONST 1 (frozenset({1, 2}))
4 COMPARE_OP 6 (in)
6 RETURN_VALUE