Boost logo

Boost :

From: Johan Råde (rade_at_[hidden])
Date: 2006-08-20 05:13:14


Robert Ramey has evicted my facets for non-finite numbers from the
serialization namespace :-) They clearly don't belong there.
So I've moved them to a new facets namespace.
I have moved the code in the vault from the Serialization folder to a
new Facets folder.
And I have started a new thread.

-------------------------------------------------------------------------

There is a serious problem with the design of the facets strict_num_put
and strict_num_get.
These facets are supposed to set the failbit of the stream when they
encounter non-finite numbers.

This may not be a good idea, because

   Facets derived from std::num_put and std::num_get
   should do formatting and parsing, not data validation.

The designers of the standard library made the following assumptions:

1. Facets derived from std::num_put do formatting.
2. Facets derived from std::num_get do parsing.
3. Formatting always succeeds.
4. Parsing may fail.

This led them to the following design decisions:

5. Facets derived from std::num_put do not have access to the stream state.
6. Facets derived from std::num_get do have access to the stream state.

The facets strict_num_put and and strict_num_get violate assumptions 1
and 2.
The facet strict_num_put does validation and formatting.
The facet strict_num_get does parsing and validation.

This makes it difficult to implement strict_num_put.
What should it do when validation fails?
It can not set the failbit of the stream.
The only thing it can do, is to throw an exception.
The stream will catch that exception and set the badbit!
At least with VC++ 7.1.
Why? The stream probably assumes that formatting facets do not throw
exceptions,
so it concludes that the exception was thrown by the stream buffer.
When the stream buffer is corrupted, the stream sets the badbit.
However, setting the badbit when data validation fails, is a bad idea.

   Suggested solution:
     Throw out the facets strict_num_put and strict_num_get.

   Comments?

The documentation of the library has been updated to reflect this problem.

--Johan Råde


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