|
Boost : |
From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2001-07-20 11:10:14
----- Original Message -----
From: Peter Dimov <pdimov_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Friday, July 20, 2001 12:51 PM
Subject: Re: [boost] Proposal: statefull objects
> From: "Fernando Cacciola" <fcacciola_at_[hidden]>
> > From: Peter Dimov <pdimov_at_[hidden]>
> > > From: "Fernando Cacciola" <fcacciola_at_[hidden]>
> > > > How should we deal with the case of x,y being outside the image?
> > >
> > > A function should not try to do too many things.
> > >
> > > bool is_inside(int x, int y) const;
> > > color_type get_pixel(int x, int y) const;
> > >
> > My point is not about returning pixels from an image. It is just an
> example.
> > I'm sure you can come out with an example that suits you. (A function
that
> > might not return a value in a situation were that is not an exception).
>
> I didn't mean to imply that stateful<T> is not useful. I just think that
> "case A" is not a good demonstration of its usefulness, that's all.
>
OK.
Here's another example, from real code:
stateful<point> polygon::find_any_point_inside( double clearance ) const ;
This function attempts to locate an arbitrary point inside the polygon, s.t.
its distance to the polygon is > clearance.
Of course, such a point might not exist (and is the caller responsible of
considering this a exceptional situation).
Before stateful<> this returned pair<point,bool>
>
> > Or simply take the case of set/map insert().
>
> Actually this is a bit different. The associative insert() always returns
a
> valid iterator, regardless of whether the 'bool' part is true. You'll have
> to decide whether your class is a discriminated union (you can't extract a
> value from it when it's empty(), operator* leads to undefined behaviour)
or
> a (T, bool) pair.
>
Aha...
All right, I get it...
> > You may think that I am solving my problems the wrong way, just like you
> did
> > with respect to the image example,
>
> No, not at all, sorry for giving the wrong impression.
>
It's OK.
Fernando Cacciola
Sierra s.r.l.
fcacciola_at_[hidden]
www.gosierra.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk