Home of Testers Forum Index Home of Testers
Nothing else, only testing!
Welcome to our Classroom!
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

passing ref to ptr again as ref to ptr....
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9
 
Post new topic   Reply to topic    Home of Testers Forum Index -> Testers' Weapons - C++
View previous topic :: View next topic  
Author Message
Cem.Kaner



Joined: 20 May 2008
Posts: 1741

PostPosted: Fri Jun 06, 2008 11:50 am    Post subject: Re:passing ref to ptr again as ref to ptr.... Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Home of Testers Forum Index -> Testers' Weapons - C++ All times are GMT
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9
Page 9 of 9

 
Jump to:  
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