Boost logo

Boost :

From: gmelquio_at_[hidden]
Date: 2003-08-05 12:16:31

En réponse à Jason McCarty <bclg_at_[hidden]>:

> [gah, I originally sent this to the wrong address]
> I found a slight annoyance with operator>> (istream&, interval<whatever>&):
> It can't cope with whitespace before its sentinel characters '[' and
> ',', causing some input operations to fail unnecessarily.
> I would recommend the following alternative implementation, modeled
> after a function in Stroustrup's TCPL.
> template<class T, class Policies> inline
> std::istream& operator>>(std::istream& is, interval<T, Policies>& r)
> {
> T l, u;
> char c = 0;
> is >> c;
> if (c == '[') {
> is >> l >> c;
> if (c == ',')
> is >> u >> c;
> if (c != ']')
> is.setstate(is.failbit);
> } else {
> is.putback(c);
> is >> l;
> u = l;
> }
> if (is)
> r.assign(l, u);
> return is;
> }
> This implementation also allows reading a scalar of type T, and
> creating a point interval with that value.
> Thoughts?

Since you are new to this mailing-list, you don't know all the discussions there
was about input/output and the library (mean/width, relative error, limited
number of digits, point representation, etc). To sumarize: <interval/io.hpp> is
a bit on the braindead side. It should never have been a real header. It was
rather designed as a quick and dirty hack to debug programs. It was up to the
user to provide well-built implementation for << and >> in their final programs
(it's the reason why io.hpp is not automatically included by interval.hpp so
that there is no multiple definition). In the next release, this header will
probably be moved to the example section so that there is no more misunderstanding.

In conclusion, don't include <interval/io.hpp> but directly define your own
operators. And thanks for your function, I will use it when I create the example



Boost list run by bdawes at, gregod at, cpdaniel at, john at