This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of TC1 status.

217. Facets example (Classifying Japanese characters) contains errors

Section: 99 [facets.examples] Status: TC1 Submitter: Martin Sebor Opened: 2000-02-29 Last modified: 2016-01-28

Priority: Not Prioritized

View all other issues in [facets.examples].

View all issues with TC1 status.

Discussion:

The example in 22.2.8, paragraph 11 contains the following errors:

1) The member function `My::JCtype::is_kanji()' is non-const; the function must be const in order for it to be callable on a const object (a reference to which which is what std::use_facet<>() returns).

2) In file filt.C, the definition of `JCtype::id' must be qualified with the name of the namespace `My'.

3) In the definition of `loc' and subsequently in the call to use_facet<>() in main(), the name of the facet is misspelled: it should read `My::JCtype' rather than `My::JCType'.

Proposed resolution:

Replace the "Classifying Japanese characters" example in 22.2.8, paragraph 11 with the following:

#include <locale>
namespace My {
    using namespace std;
    class JCtype : public locale::facet {
    public:
        static locale::id id;     //  required for use as a new locale facet
        bool is_kanji (wchar_t c) const;
        JCtype() {}
    protected:
        ~JCtype() {}
    };
}
//  file:  filt.C
#include <iostream>
#include <locale>
#include "jctype"                 //  above
std::locale::id My::JCtype::id;   //  the static  JCtype  member
declared above.
int main()
{
    using namespace std;
    typedef ctype<wchar_t> wctype;
    locale loc(locale(""),              //  the user's preferred locale...
               new My::JCtype);         //  and a new feature ...
    wchar_t c = use_facet<wctype>(loc).widen('!');
    if (!use_facet<My::JCtype>(loc).is_kanji(c))
        cout << "no it isn't!" << endl;
    return 0;
}