I\'ve got a list of elements, say, integers and I want to check if my variable (another integer) is one of the elements from the list. In python I\'d do:
my_list
A one-liner solution, similar to python, would be (std::set {1, 2, 3, 4}).count(my_var) > 0.
(std::set {1, 2, 3, 4}).count(my_var) > 0
Minimal working example
int my_var = 3; bool myVarIn = (std::set {1, 2, 3, 4}).count(my_var) > 0; std::cout << std::boolalpha << myVarIn << std::endl;
prints true or false dependent of the value of my_var.
true
false