|
|
| View previous topic :: View next topic |
|
|
| Author |
Message |
Cem.Kaner
Joined: 20 May 2008 Posts: 1741
|
Posted: Fri Jun 06, 2008 11:50 am Post subject: Re:passing ref to ptr again as ref to ptr.... |
|
|
On Apr 28, 12:17 pm, gpderetta <gpdere...@gmail.com> wrote:
- Hide quoted text -
- Show quoted text -
> On Apr 28, 11:12 am, James Kanze <james.ka...@gmail.com> wrote:
> > On Apr 24, 11:53 pm, "Bo Persson" <b...@gmb.dk> wrote:
> > > osama...@gmail.com wrote:
> > [...]
> > > > Does that mean references and templates are not to be mixed?
> > > No, they work very well together. I think the void* is the
> > > problem here, and that you are trying too hard to optimize the
> > > code.
> > > I would trust my compiler here, and just write
> > > template<class T>
> > > class GenericQueue
> > > {
> > > bool Pop(T&);
> > > };
> > Given that he requires pointer semantics, and copying a pointer
> > cannot throw, there's no reason not to just use
> > T* pop() ;
> > in the generic interface.
> > > if that is the interface needed (it probably is not - take a
> > > look at std::queue and std::stack).
> > There's a slight difference. The standard containers are
> > designed to store values, not (only) pointers. So the
> > alternatives are:
> > -- return a T, but not be thread safe,
> > [...]
> > Globally, I think the first alternative was dismissed because of
> > the lack of thread safety (although I think it was what was used
> > in the original STL); of the latter two, the last seems to offer
> > the most flexibility, and was chosen.
> IIRC, it had more to do with exception safety: if the copy
> constructor throws an exception when returning the pop'd
> object, you will lose the object with no way to recover it (it
> has already been removed from the internal queue). There is
> no such a problem with the separated 'T&top()' and 'void
> pop()'
Yes. I don't know why I wrote thread---the issue was definitely
exceptions, and the impossibility to offer a strong guarantee.
--
James Kanze (GABI Software) email:james.ka...@gmail.com
Conseils en informatique orient�e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S�mard, 78210 St.-Cyr-l'�cole, France, +33 (0)1 30 23 00 34 |
|
| Back to top |
|
 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
Powered by phpBB © 2001, 2005 phpBB Group
|