I am trying to understand how to use gsl::narrow_cast instead of static_cast.
I found here on stackoverflow a function that has a string as a parameter and returns true if all characters are ASCII (first 127 characters).
bool IsCleanString(const std::string& str)
{
return !std::any_of(str.begin(), str.end(), [](char c) {
return narrow_cast<unsigned char>(c) > 127;
});
}
I have implemented this function in my code and I noticed Visual Studio suggests the use of either gsl::narrow or gsl::narrow_cast.
My first question is how to use gsl functions? I have looked at other questions on the website and I haven't found one that tells how to even see the gsl class/library (I am building a dll)
And the second question is what would be the correct syntax for this function, is it even necessary to change it in this case?
Thanks.