Boost logo

Boost :

From: Howard Hinnant (hinnant_at_[hidden])
Date: 2001-06-07 12:03:45


On Thursday, June 7, 2001, at 12:28 PM, Darin Adler wrote:

>> Also, should Line A read:
>>
>> s << o.widen(’(’)
>> << x.real()
>> << o.widen(',')
>> << x.imag()
>> << o.widen(’)’); // Line A
>>
>> (As in add a call to "widen()" on any formated character in case
>> "wchar"
>> is
>> the char type.)
>
> It does seem that this would be necessary. But since the code I quoted
> is
> from the standard, there must either be a reason that calls to widen
> aren'
> t needed, or a defect in the standard. I can't find an item in the
> library
> issues list, so it might be time to submit a defect report.

The standard has the namespace scope operator (27.6.2.1):

template<class charT, class traits>
basic_ostream<charT,traits>&
operator<<(basic_ostream<charT,traits>&, char);

>> Which of course brings up the question, if I had a "stringOfChars" do I
>> have
>> to loop through each one calling "widen()" on them individually?
>
> If efficiency is a concern, you can instead call the underlying widen
> from
> <ctype> that works on an array of characters. The code would be
> something
> roughly like:
>
> std::use_facet< std::ctype<char_type> >(o.getloc())
> .widen(str_start, str_end, result_buffer);
>
> Metrowerks adds a non-standard overload that widens a std::string. You
> may
> be able to write your own as a free function template if you find this
> comes up a lot. We could put that into some boost library if we find
> it's
> a common requirement.
>
> PS to Howard Hinnant: The Metrowerks non-standard overload for
> std::string
> is only half there in <ios>. It's there in the _MSL_NO_LOCALE case, but
> not in the normal case.

When locale support is turned off, there is a (non-standard) member
function of basic_ios called widen which takes a string.

When locale support is turned on, there is a (non-standard) member
function of ctype called widen which takes a string.

I put these in just as an aid in implementing the lib. I'm surprised
anybody noticed! :-)

-Howard


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk