c++language-lawyerlocalecodecvt

When is std::codecvt<char, char, std::mbstate_t>::always_noconv() required to return true?


Does the standard (C++17) mandate that std::codecvt<char, char, std::mbstate_t>::always_noconv() returns true

The C++ standard does have something to say about it. From section 25.4.1.4 of C++17:

codecvt<char, char, mbstate_t> implements a degenerate conversion; it does not convert at all.

Taken out of context, this strongly suggests that it applies to all locales. Still, I'd appreciate hearing from anybody that can confirm it, or has arguments for why it should not be the case.


Solution

  • Ok, as was pointed out by cpplearner, the standard (C++17) also has the following text in the requirements for do_always_noconv() in section 25.4.1.4.2:

    codecvt<char,char, mbstate_t> returns true.

    If the text had instead been:

    The specialization codecvt<char,char, mbstate_t> returns true.

    I would no longer have any doubt.

    However, since this is indeed how similar statements are phrased under other functions in section 25.4.1.4.2, I take it that the intention is to require, that in the codecvt<char,char, mbstate_t> specialization, always_noconv() returns true.

    It follows then, that it is the case for all locales.