Boost logo

Boost :

Subject: Re: [boost] [proposal] safe_ref<T>
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2012-12-27 07:40:04

> It is similar to optional<T>, but in this case the idea is to not allow
> access to internal data if the pointer is null, only allowing a safe usage
> There is interest to add something like this to Boost?
> Any comments or remarks?

This is just my opinion, but I believe that this approach is wrong.
Dereferencing a null pointer is definitely wrong, but preventing it by
silently dropping some portions of code (that the programmer intended to
execute) doesn't look good either.

If a programmer wants to call function f() on some object, but he makes a
bug by forgetting to initialize the pointer/reference/handle, safe_ref
would give him a false impression that his function has been executed. If
you think of some rare cases where this behavior is exactly what one needs,
perhaps you should consider renaming the wrapper to something like
"ignoring_ref" or "skipping_ref". The part "safe" does not give an
indication of what the wrapper really does, and it is not that clear to me
if its behavior makes the program safer.


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