Код: Выделить всё
std::string b = "b";
is_in("a", { "a", "b", "c" });
is_in("d", { "a", "b", "c" });
is_in(b, { "a", "b", "c" }); // fails
is_in(b, std::array{ "a", "b", "c" });
Код: Выделить всё
template
bool is_in(const Element& e, const Container& c)
{
// https://stackoverflow.com/questions/20303821/how-to-check-if-string-is-in-array-of-strings
return std::find(std::begin(c), std::end(c), e) != std::end(c);
}
template
bool is_in(Element e, std::initializer_list l)
{
// return std::find(std::begin(l), std::end(l), e) != std::end(l);
return is_in(e, l);
}
Код: Выделить всё
no matching function for call to ‘is_in(std::string&,
)’
Подробнее здесь: https://stackoverflow.com/questions/695 ... tring-in-c
Мобильная версия