The code below fails to compile with: override did not override any base class methods & do_is is not a member of ctype.
It works fine for wchar_t.
Tested on VC++ 2022, default settings. [EDIT] I got the same result for online GCC. It looks like it is a feature, but why?
#include <locale>
struct fail_t : std::ctype<char> // works for wchar_t
{
bool do_is(mask m, char_type c) const override
{
return ctype::do_is(m, c);
}
};
int main()
{
// nop
}
Perhaps not a complete answer, but the cppreference site page for the
std::ctype<char>specialization1 does briefly explain (bolding mine):Note also, on that page, that there is no
do_is()member function (inherited or otherwise).As for the "but why" part of your question: I guess the last (parenthesised) phrase covers that: which is generally faster.
1 I appreciate that cppreference does not represent any official C++ Standard; however, it is generally very reliable and the language used is often rather more understandable than that in those Standard documents.
Looking through this C++17 Draft Standard, there is another possible answer to the "but why" question: