Issue Details (XML | Word | Printable)

Key: STDCXX-296
Type: New Feature New Feature
Status: Open Open
Priority: Major Major
Assignee: Martin Sebor
Reporter: Martin Sebor
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
C++ Standard Library

std::basic_ostream::operator<<(const wchar_t*)

Created: 05/Oct/06 08:31 PM   Updated: 02/Jun/08 06:18 PM
Return to search
Component/s: 27. Input/Output
Affects Version/s: 4.1.2, 4.1.3, 4.1.4, 4.2.0, 4.2.1
Fix Version/s: 4.3.0

Time Tracking:
Original Estimate: 24h
Original Estimate - 24h
Remaining Estimate: 22h
Time Spent - 2h Remaining Estimate - 22h
Time Spent: 2h
Time Spent - 2h Remaining Estimate - 22h

File Attachments:
  Size
File Licensed for inclusion in ASF works ostream.diff 2006-10-05 09:22 PM Martin Sebor 4 kB
Environment: all

Severity: Usability


 Description  « Hide
There is a pair of generic insertion and extraction operators for const char* (i.e., that make it possible to insert/extract narrow character strings to/from a stream object specialized on wchar_t or even user-defined character type), but there are no such operators for wchar_t (i.e., that would
make it possible to insert/extract arrays of wchar_t elements to/from narrow streams or streams specialized on a user-defined character type).
Such operators would provide a useful and convenient interface to the low-level codecvt facet, one that could be used to perform in memory
codeset conversion just as easily and conveniently as fstream performs such conversions on files. Here's an example of how the insertion
operator could be used to easily convert from UCS to UTF-8:

#include <cassert> // for assert()
#include <cwchar> // for mbstate_t
#include <locale> // for codecvt, locale
#include <sstream> // for ostringstream

int main ()
{
std::stringstream ostrm;

typedef std::codecvt_byname<wchar_t, char, std::mbstate_t> Unicode;

ostrm.imbue (std::locale (ostrm.getloc (), new Unicode ("UTF-8@UCS")));

// convert the UCS Greek letters alpha, beta, gamma to UTF-8
// expected UTF-8 encoding: "\xce\xb1\xce\xb2\xce\xb3"
ostrm << L"\x3b1\x3b2\x3b3";

assert ("\xce\xb1\xce\xb2\xce\xb3" == ostrm.str ());
}



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Martin Sebor added a comment - 05/Oct/06 09:05 PM
Patch demonstrating the implementation of a generic insertion operator for const wchar_t*

Martin Sebor added a comment - 05/Oct/06 09:22 PM
A more generic implementation of the proposed insertion operator.

Martin Sebor added a comment - 07/Sep/07 02:27 PM
Too big for 4.2.1, scheduled for 4.3.

Martin Sebor added a comment - 02/Jun/08 06:17 PM
Added all releases to the list of affected versions and estimated effort.