How can I better check whether two char variables are in some set of values?

You could write a fold-expression that compares 2 characters to a string:

template<typename ...Days>
bool any_of(char a, char b, Days ...days)
{
    return (... || (a == days[0] && b == days[1]));
}

and then use it like this:

while (! any_of(std::tolower(dayOne), std::tolower(dayTwo), "mo", "tu", "we", "th", "fr", "sa", "su"))
    // keep asking for input

Here’s a demo.

This should satisfy the requirement of using 2 char inputs.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)