I'm away from work at the moment, so this isn't a considered reply.
However, the solution I've had at the back of my mind for this sort of problem, is to introduce exceptions in the same way as they have been put into mbl. If you have exceptions enabled, you get a nice error message. If you have then disabled, you get either some kind of error indication (i.e. an empty image), or an abort as appropriate.

From: vxl-maintainers-admin@lists.sourceforge.net on behalf of Tim Cootes
Sent: Fri 6/17/2005 10:57 AM
To: Amitha Perera
Cc: vxl-maintainers@lists.sourceforge.net
Subject: Re: [Vxl-maintainers] vil_image_view operator= API change

Hi Amitha,
I agree that failing silently is not terribly satisfactory, as it is
hard to track down.
Strictly, of course, one should write:

vil_image_view<vxl_byte> im=vil_load(filepath);
if (im.size()==0)
    // Uh-oh!
  vcl_cerr<<"I told you not to do that."<<vcl_endl;

However, we don't all remember to do this.

If one were to abort() on a failure to do a cheap conversion, one would
have to write

vil_image_view_base_sptr  im_ptr=vil_load(filepath);
if (!im_ptr)
  // Failed to load anything...
if (im_ptr->is_a()!="vil_image_view<vxl_byte>")
  // Wrong type!  Convert or die

This is a bit longer, but more explicit.

On the grounds that silent failure is generally a bad thing, I wouldn't
object to the copy operator aborting if it can't do it easily. 
However, Ian has a deeper knowledge of vil than I, and may have some


Amitha Perera wrote:

>I'd like to change the vil_image_view::operator= API to abort() if it
>cannot do a cheap assignment. I've already been bitten multiple times
>by the silent failure where the source and target types don't
>match. One particular example is
>  vil_image_view<vxl_byte> im = vil_load( "16-bit image" );
>will simply return a null image, and can take a lot of tracking down
>to figure out that there is a type mismatch.
>Does someone recall the original justification for silent failure? I
>suggest that if "cheap conversion compatibility" needs to be checked,
>then we create a new method "is_compatible", so that operator= will
>succeed iff is_compatible returns true.
>My next email will contain suggestion to make this error a compile
>time error when possible.
>SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
>from IBM. Find simple to follow Roadmaps, straightforward articles,
>informative Webcasts and more! Get everything you need to get up to
>speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
>Vxl-maintainers mailing list


Tim Cootes                                  Senior Lecturer
Imaging Science and Biomedical Engineering  tel   (+44) 0161 275 5146
The University of Manchester                fax   (+44) 0161 275 5145
Manchester M13 9PT , UK                     mailto:t.cootes@man.ac.uk

SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
Vxl-maintainers mailing list