Movatterモバイル変換


[0]ホーム

URL:



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

217. Facets example (Classifying Japanese characters) contains errors

Section: 99 [facets.examples]Status:TC1Submitter: Martin SeborOpened: 2000-02-29Last modified: 2016-01-28

Priority:Not Prioritized

View all otherissues in [facets.examples].

View all issues withTC1 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 functionmust be const in order for it to be callable on a const object (a reference towhich which is what std::use_facet<>() returns).

2) In file filt.C, the definition of `JCtype::id' must be qualified with thename 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"                 //  abovestd::locale::id My::JCtype::id;   //  the static  JCtype  memberdeclared 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;}

[8]ページ先頭

©2009-2026 Movatter.jp