Given: auto foo = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"s
I can convert all the characters to lowercase by:
use_facet<ctype<char>>(cout.getloc()).tolower(data(foo), next(data(foo), foo.size()));
But this depends upon cout.getloc()
containing the ctype<char>
facet
.
Presuming that I'm using an unmodified cout
can I assume that cout.getloc()
will contain the facet
ctype<char>
or do I need to confirm this before use with:
has_facet<ctype<char>>(cout.getloc())
From cppreference:
Each locale constructed in a C++ program holds at least the following standard facets [...]:
- std::ctype<char>
- ...
Any locale, meaning even locales not of the cout
object will support std::ctype<char>
.