Topic: tr1::shared_ptr and boost::shared_ptr


Author: "Axter" <google@axter.com>
Date: 18 Apr 2006 19:10:05 GMT
Raw View
What was the justification for the tr1 shared_ptr not to allow a custom
deleter like the boost::shared_ptr?

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: Pete Becker <petebecker@acm.org>
Date: Tue, 18 Apr 2006 15:25:43 CST
Raw View
Axter wrote:
> What was the justification for the tr1 shared_ptr not to allow a custom
> deleter like the boost::shared_ptr?
>

There is none. It's part of the TR1 spec.

--

Pete Becker
Roundhouse Consulting, Ltd.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: "Alf P. Steinbach" <alfps@start.no>
Date: Tue, 18 Apr 2006 15:59:40 CST
Raw View
* Pete Becker:
> Axter wrote:
>> What was the justification for the tr1 shared_ptr not to allow a custom
>> deleter like the boost::shared_ptr?
>>
>
> There is none. It's part of the TR1 spec.

Oops, I didn't notice that.

Is there any hope of having a custom delete function added, as with
boost::shared_ptr?

For example, boost::shared_ptr can be used with a class with protected
or private destructor, without being a friend of that class, by passing
it a deallocation function that does have access to the destructor.

For new code it's presumably no big deal to add friendship for a
standard smart-pointer, but code that relies on the above technique with
boost::smart_ptr won't work by simply replacing with std::shared_ptr
(assuming that's what the TR1 shared_ptr will end up as).

In short, it will require workarounds for all code that now uses
boost::shared_ptr and relies on the custom deleter, when such code is to
be changed to use the standard shared_ptr.  And if the class in question
can't be changed (adding friendship), then std::shared_ptr can't be
used.  I think it would reflect badly on the standard library if one had
to use boost::shared_ptr /in addition/ to std::shared_ptr.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: AlbertoBarbati@libero.it (Alberto Ganesh Barbati)
Date: Tue, 18 Apr 2006 23:42:46 GMT
Raw View
Pete Becker ha scritto:
> Axter wrote:
>> What was the justification for the tr1 shared_ptr not to allow a custom
>> deleter like the boost::shared_ptr?
>>
>
> There is none. It's part of the TR1 spec.
>

Uhm? In the latest publicly available draft of TR1 (dated 2005-06-24
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf)
tr1::shared_ptr definitely *has* support for custom deleters. In
particular, see clause 2.2.3.2. Are you saying that this feature has
been removed in a subsequent (non-publicly available) draft?

Ganesh

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: Pete Becker <petebecker@acm.org>
Date: Tue, 18 Apr 2006 22:57:30 CST
Raw View
Alf P. Steinbach wrote:
> * Pete Becker:
>
>> Axter wrote:
>>
>>> What was the justification for the tr1 shared_ptr not to allow a custom
>>> deleter like the boost::shared_ptr?
>>>
>>
>> There is none. It's part of the TR1 spec.
>
>
> Oops, I didn't notice that.
>
> Is there any hope of having a custom delete function added, as with
> boost::shared_ptr?
>

Sorry, the earlier "It's part of the TR1 spec" referred to custom
deleters. They're in there.

--

Pete Becker
Roundhouse Consulting, Ltd.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: v.haisman@sh.cvut.cz (Vaclav Haisman)
Date: Wed, 19 Apr 2006 03:57:03 GMT
Raw View
Axter wrote:
> What was the justification for the tr1 shared_ptr not to allow a custom
> deleter like the boost::shared_ptr?
>
Huh, without custom deleter it would be so much less useful. I find it
useful for wrapping simple C stuff like FILE* and gdImage* with fclose()
resp. gdImageDestroy() as custom deleter.

--
VH

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: howard.hinnant@gmail.com (Howard Hinnant)
Date: Wed, 19 Apr 2006 03:57:14 GMT
Raw View
In article <4al25bFtp3o9U1@individual.net>,
 "Alf P. Steinbach" <alfps@start.no> wrote:

> * Pete Becker:
> > Axter wrote:
> >> What was the justification for the tr1 shared_ptr not to allow a custom
> >> deleter like the boost::shared_ptr?
> >>
> >
> > There is none. It's part of the TR1 spec.
>
> Oops, I didn't notice that.
>
> Is there any hope of having a custom delete function added, as with
> boost::shared_ptr?

I'm staring at TR1 right now.  It says:

template<class T> class shared_ptr {
public:
..
   template<class Y, class D> shared_ptr(Y* p, D d);
..
};

Is this not custom deleter support?

Or are we mistakenly talking about custom allocators?

-Howard

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: tom_usenet@hotmail.com (Tom Widmer)
Date: Wed, 19 Apr 2006 14:55:02 GMT
Raw View
Alberto Ganesh Barbati wrote:
> Pete Becker ha scritto:
>
>>Axter wrote:
>>
>>>What was the justification for the tr1 shared_ptr not to allow a custom
>>>deleter like the boost::shared_ptr?
>>>
>>
>>There is none. It's part of the TR1 spec.
>>
>
>
> Uhm? In the latest publicly available draft of TR1 (dated 2005-06-24
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf)
> tr1::shared_ptr definitely *has* support for custom deleters. In
> particular, see clause 2.2.3.2. Are you saying that this feature has
> been removed in a subsequent (non-publicly available) draft?

There seems to be a misunderstanding. As a native english speaker, I
took Pete's comment to meant that:

1. There is no justification for the tr1 shared_ptr not to allow a
custom deleter like the boost::shared_ptr.
2. The custom deleter is part of the tr1::shared_ptr spec.

In other words, the OP asked an invalid question.

Tom

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: petebecker@acm.org (Pete Becker)
Date: Wed, 19 Apr 2006 16:16:14 GMT
Raw View
Alberto Ganesh Barbati wrote:
> Pete Becker ha scritto:
>
>>Axter wrote:
>>
>>>What was the justification for the tr1 shared_ptr not to allow a custom
>>>deleter like the boost::shared_ptr?
>>>
>>
>>There is none. It's part of the TR1 spec.
>>
>
>
> Uhm? In the latest publicly available draft of TR1 (dated 2005-06-24
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf)
> tr1::shared_ptr definitely *has* support for custom deleters. In
> particular, see clause 2.2.3.2. Are you saying that this feature has
> been removed in a subsequent (non-publicly available) draft?
>

No, there's no justification for not allowing it because it is allowed.

--

Pete Becker
Roundhouse Consulting, Ltd.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: "Axter" <google@axter.com>
Date: Thu, 20 Apr 2006 10:17:27 CST
Raw View
Howard Hinnant wrote:
> In article <4al25bFtp3o9U1@individual.net>,
>  "Alf P. Steinbach" <alfps@start.no> wrote:
>
> > * Pete Becker:
> > > Axter wrote:
> > >> What was the justification for the tr1 shared_ptr not to allow a custom
> > >> deleter like the boost::shared_ptr?
> > >>
> > >
> > > There is none. It's part of the TR1 spec.
> >
> > Oops, I didn't notice that.
> >
> > Is there any hope of having a custom delete function added, as with
> > boost::shared_ptr?
>
> I'm staring at TR1 right now.  It says:
>
> template<class T> class shared_ptr {
> public:
> ..
>    template<class Y, class D> shared_ptr(Y* p, D d);
> ..
> };
>
> Is this not custom deleter support?
>
> Or are we mistakenly talking about custom allocators?
>

I remember previously reading a comparison between TR1::shared_ptr and
boost::shared_ptr, and reading something about tr1::shared_ptr not
having custom deleter.
I just did a google search for the link, but I can't find it now.
Maybe I misread it.

Thanks for the link and correction.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]