I was able to determine the exact syntax, like in python (checking for a value in a container), so you can just check if the value is in any container that supports the begin()/ methods end().
Here is my implementation:
#include <algorithm>
#include <iostream>
#include <vector>
template<class T>
struct specified {
specified(T const& value) : value_(value) {}
T value_;
template<class Container>
bool operator * (Container const& cont) {
return (std::find(cont.begin(), cont.end(), value_) != cont.end());
}
};
struct general {
template<class T>
friend specified<T> operator *(T const& rhs, general const&) {
return specified<T>(rhs);
}
};
#define in * general() *
int main() {
std::vector<int> vec{1,2,3};
std::cout << 1 in vec << std::endl;
std::cout << 4 in vec << std::endl;
}
Live on coliru
My question is, does he have any pitfalls? It is safe?
EDIT:
String literal support
source
share