
3 Oct
2004
3 Oct
'04
9:53 a.m.
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