Boost logo

Boost :

From: Jason McCarty (bclg_at_[hidden])
Date: 2003-08-05 11:35:13

[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 != ']')
  } else {
    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.


Jason McCarty

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