[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?

Jason McCarty
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to