Title
I/O stream manipulators don't work for wide character streams
Status
cd1
Section
[std.manip]
Submitter
Andy Sawyer

Created on 1999-07-07.00:00:00 last changed 172 months ago

Messages

Date: 2010-10-21.18:28:33

[ Post-Tokyo: The issues list maintainer combined the proposed resolution of this issue with the proposed resolution for issue 216 as they both involved the same paragraphs, and were so intertwined that dealing with them separately appear fraught with error. The full text was supplied by Bill Plauger; it was cross checked against changes supplied by Andy Sawyer. It should be further checked by the LWG. ]

Date: 2010-10-21.18:28:33

[ Tokyo - The LWG noted that issue 216 involves the same paragraphs. ]

Date: 2010-10-21.18:28:33

[ Kona: Andy Sawyer and Beman Dawes will work to improve the wording of the proposed resolution. ]

Date: 2010-10-21.18:28:33

Proposed resolution:

Replace section [std.manip] except paragraph 1 with the following:

2- The type designated smanip in each of the following function descriptions is implementation-specified and may be different for each function.

smanip resetiosflags(ios_base::fmtflags mask);

-3- Returns: An object s of unspecified type such that if out is an instance of basic_ostream<charT,traits> then the expression out<<s behaves as if f(s, mask) were called, or if in is an instance of basic_istream<charT,traits> then the expression in>>s behaves as if f(s, mask) were called. The function f can be defined as:*

[Footnote: The expression cin >> resetiosflags(ios_base::skipws) clears ios_base::skipws in the format flags stored in the basic_istream<charT,traits> object cin (the same as cin >> noskipws), and the expression cout << resetiosflags(ios_base::showbase) clears ios_base::showbase in the format flags stored in the basic_ostream<charT,traits> object cout (the same as cout << noshowbase). --- end footnote]

     ios_base& f(ios_base& str, ios_base::fmtflags mask)
   {
   // reset specified flags
   str.setf(ios_base::fmtflags(0), mask);
   return str;
   }

The expression out<<s has type basic_ostream<charT,traits>& and value out. The expression in>>s has type basic_istream<charT,traits>& and value in.

 smanip setiosflags(ios_base::fmtflags mask);

-4- Returns: An object s of unspecified type such that if out is an instance of basic_ostream<charT,traits> then the expression out<<s behaves as if f(s, mask) were called, or if in is an instance of basic_istream<charT,traits> then the expression in>>s behaves as if f(s, mask) were called. The function f can be defined as:

     ios_base& f(ios_base& str, ios_base::fmtflags mask)
   {
   // set specified flags
   str.setf(mask);
   return str;
   }

The expression out<<s has type basic_ostream<charT,traits>& and value out. The expression in>>s has type basic_istream<charT,traits>& and value in.

smanip setbase(int base);

-5- Returns: An object s of unspecified type such that if out is an instance of basic_ostream<charT,traits> then the expression out<<s behaves as if f(s, base) were called, or if in is an instance of basic_istream<charT,traits> then the expression in>>s behaves as if f(s, base) were called. The function f can be defined as:

     ios_base& f(ios_base& str, int base)
   {
   // set basefield
   str.setf(base == 8 ? ios_base::oct :
   base == 10 ? ios_base::dec :
   base == 16 ? ios_base::hex :
   ios_base::fmtflags(0), ios_base::basefield);
   return str;
   }

The expression out<<s has type basic_ostream<charT,traits>& and value out. The expression in>>s has type basic_istream<charT,traits>& and value in.

smanip setfill(char_type c);

-6- Returns: An object s of unspecified type such that if out is (or is derived from) basic_ostream<charT,traits> and c has type charT then the expression out<<s behaves as if f(s, c) were called. The function f can be defined as:

      template<class charT, class traits>
   basic_ios<charT,traits>& f(basic_ios<charT,traits>& str, charT c)
   {
   // set fill character
   str.fill(c);
   return str;
   }

The expression out<<s has type basic_ostream<charT,traits>& and value out.

smanip setprecision(int n);

-7- Returns: An object s of unspecified type such that if out is an instance of basic_ostream<charT,traits> then the expression out<<s behaves as if f(s, n) were called, or if in is an instance of basic_istream<charT,traits> then the expression in>>s behaves as if f(s, n) were called. The function f can be defined as:

      ios_base& f(ios_base& str, int n)
   {
   // set precision
   str.precision(n);
   return str;
   }

The expression out<<s has type basic_ostream<charT,traits>& and value out. The expression in>>s has type basic_istream<charT,traits>& and value in
.
smanip setw(int n);

-8- Returns: An object s of unspecified type such that if out is an instance of basic_ostream<charT,traits> then the expression out<<s behaves as if f(s, n) were called, or if in is an instance of basic_istream<charT,traits> then the expression in>>s behaves as if f(s, n) were called. The function f can be defined as:

      ios_base& f(ios_base& str, int n)
   {
   // set width
   str.width(n);
   return str;
   }

The expression out<<s has type basic_ostream<charT,traits>& and value out. The expression in>>s has type basic_istream<charT,traits>& and value in.

Date: 1999-07-07.00:00:00

[std.manip] paragraph 3 says (clause numbering added for exposition):

Returns: An object s of unspecified type such that if [1] out is an (instance of) basic_ostream then the expression out<<s behaves as if f(s) were called, and if [2] in is an (instance of) basic_istream then the expression in>>s behaves as if f(s) were called. Where f can be defined as: ios_base& f(ios_base& str, ios_base::fmtflags mask) { // reset specified flags str.setf(ios_base::fmtflags(0), mask); return str; } [3] The expression out<<s has type ostream& and value out. [4] The expression in>>s has type istream& and value in.

Given the definitions [1] and [2] for out and in, surely [3] should read: "The expression out << s has type basic_ostream& ..." and [4] should read: "The expression in >> s has type basic_istream& ..."

If the wording in the standard is correct, I can see no way of implementing any of the manipulators so that they will work with wide character streams.

e.g. wcout << setbase( 16 );

Must have value 'wcout' (which makes sense) and type 'ostream&' (which doesn't).

The same "cut'n'paste" type also seems to occur in Paras 4,5,7 and 8. In addition, Para 6 [setfill] has a similar error, but relates only to ostreams.

I'd be happier if there was a better way of saying this, to make it clear that the value of the expression is "the same specialization of basic_ostream as out"&

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg1784
2010-10-21 18:28:33adminsetmessages: + msg1783
2010-10-21 18:28:33adminsetmessages: + msg1782
2010-10-21 18:28:33adminsetmessages: + msg1781
1999-07-07 00:00:00admincreate