|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-07-20 07:24:25
From: "Fernando Cacciola" <fcacciola_at_[hidden]>
> In order to introduce this proposal let's consider the following
situations:
>
> CASE A:
> =======
>
> struct image
> {
> ...
> int get_pixel( int x, int y) const ;
> ...
> } ;
>
> 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;
[Other cases that demonstrate the point better snipped.]
> I'd like to know your opinions.
This is a discriminated union, like 'any'. The only difference is that 'any'
accepts any type + void, while your proposed class accepts only T or void.
People that program in discriminated-union-capable languages would like your
proposal. :-) Do you think that optional<T> would be a better name?
-- Peter Dimov Multi Media Ltd.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk