Noah Roberts
8/14/2009 4:35:00 PM
Juha Nieminen wrote:
> Noah Roberts wrote:
>> Juha Nieminen wrote:
>>> Hicham Mouline wrote:
>>>> ... my colleague says.
>>>>
>>>> I disagree on the "Never".
>>>>
>>>> Opinions about this "rule of thumb" welcome.
>>> I would like to see him implement a doubly-linked list with smart
>>> pointers.
>> Just look at the code for std::list.
>
> Which uses raw pointers, not smart ones.
First off, note the wording of the standard being discussed:
"Never ever use a raw pointer when a smart pointer can do the same job."
Demanding that someone use a smart pointer where it supposedly can't do
the job (it can) to counter such a standard is a straw man.
Second off, note that no raw pointer is exposed by std::list.
std::vector *might* expose a pointer but it does so in such a way that
it's actually smarter than your average raw pointer. It has traits
attached to it, turning it into an iterator (a smart pointer). The
std::list template cannot do this.
When a smart pointer can't do the job (or isn't the best way),
sufficient encapsulation can render its bite negligible.