Subject: Re: [boost] std::map::find() wrapper
From: Nevin Liber (nevin_at_[hidden])
Date: 2011-05-04 15:14:31
On 4 May 2011 13:42, Marsh Ray <marsh_at_[hidden]> wrote:
> On 05/04/2011 01:12 PM, Olaf van der Spek wrote:
>> On Wed, May 4, 2011 at 7:51 PM, Denis Shevchenko
>> <for.dshevchenko_at_[hidden]> wrote:
>>> No, it's not dogma. Raw pointers are not the universal evil, but I never
>>> raw pointers because I *can* write my code without raw pointers. :-)
>> That still doesn't tell me why that's better in this case.
> Because it uses the C++ type system to restrict the number of possible
> interpretations about the valid operations on the returned value, thus
> communicating information that would otherwise go unspecified.
If, for instance, you pass a shared_ptr, you are saying that the callee is
allowed to be involved with ownership. This is functionality I typically
don't want to grant willy-nilly to every function I call.
If you want to use the C++ type system to enforce this kind of thing, create
new types to wrap the raw pointers; don't reuse things like shared_ptr for
this. (And if you are creating new types, then good for you, and I remove
my objection. But it isn't typical, at least in my experience.)
> Sometimes this lets the compiler help spot problems with the program's
Could you elaborate? Again, we are talking about pointers not involved with
-- Nevin ":-)" Liber <mailto:nevin_at_[hidden]> (847) 691-1404
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk