From: David Turner (dkturner_at_[hidden])
Date: 2004-10-03 04:53:59


Hi

My apologies if this has been raised before. I've written a tiny class
called "p_ref" which is virtually identical to boost::ref except that it
(1) has a default constructor and (2) tests the pointer before
dereferencing it, raising a std::logic_error if it is null.

The reason for this is simply to be able to declare:

   std::vector<p_ref<const std::string> > keys() const;

I admit that this is really just an efficiency consideration, and
therefore must yield to considerations of correctness and elegance, but
I find it useful.

I think it makes some sense to have both ref and pref, because the
intent behind them is slightly different.

Source attached.

Regards
David Turner