Le jeu 14/11/2002 � 16:31, Alisdair Meredith a �crit :
> I beleive this is some test code that does roughly something similar to
> the library implementation:
right, this code is equivalent to what format does, for some
format-string.
> int main()
> {
> std::cout.setf( std::ios::showbase );
> std::cout << "BCB hex test: "
> << std::setfill( '0' )
> << std::setw( 8 )
> << std::internal
> << std::hex
> << 0x1234 << std::endl;
> }
>
> Is this a correct simplification on the library algorithm for this test
> case?
you did not tell how you used format, but I assume
cout << format("BCB hex test: %08x") % 0x1234 << endl;
and then, yes, it's a correct simplification.
> I'm not sure about relying on 'internal' to separate 0x from 1234
> before padding. Is this the technique format uses? And if so, is it
> correct?
yes, and yes. :-)
> [I'm no streams expert, and will happily file a bug report with borland
> if someone can quote me a relevent section of the standard, if that is
> indeed the case]
the description of the effect of 'internal' padding in the norm is
rather ambiguous sometimes (e.g. the effect on strings is subject to
interpretation), but pretty clear in this case.
�21.3.7.9/4 (semantics of operator>> on a string) : � [...], padding
as described in stage 3 of 22.2.2.2.2, where n is the larger of
os.width() and str.size(); [...] �
the table 61 in �22.2.2.2.2/19 says where to pad, depending on which of
the four cases we are in.
the 4th case is "adjustfield == internal and representation after stage
1 began with 0x or 0X"
(the stage 1 is the basic number-to-string conversion)
for this case the location where to pad is "after 'x' or 'X' "
so, without a doubt, your program here must produce "0x001234"
If it doesnt, you can file a bug report to your stream's author.
--
Samuel
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost