I have some string comparison logic in my program, e.g:
std::unordered_set<std::string> relational_operators{
"==",
"!=",
">",
"<",
">=",
"<="
};
bool is_relational(std::string token) {
relational_operators.contains(token);
}
if (is_relational(token)) {
// ...do stuff
}
All values of set are known at compile time, but checks will be done on user input. How such strings are usually stored in c++? I don't know if storing a set like this is a good idea, probably not because it can possibly throw an error when allocation happens (IDE warnings).
So for example if i had another set of strings (supported operators):
std::unordered_set<std::string> supported_operators {
// ...
};
Support for new operators will be added over time. So i just want to add a new operator to a set. So basically i want to avoid situation like this:
bool is_supported_op(std::string token) {
return token == "<" || token == ">" || token == "!="; // ... many more ||
}