help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Growing stacks in C++


From: Paul Hilfinger
Subject: Re: Growing stacks in C++
Date: Thu, 22 Jul 2010 15:58:09 -0700



Paul Hilfinger wrote:


 > > BTW: I observe that ISO C++ has a template function
 > > std::uninitialized_copy, defined in <memory>, which ought to work for
 > > copying a stack properly.
 > 

Hans Aberg wrote:

 > The algorithm is
 >    for (; first != last; ++result, ++first)
 >     new (static_cast<void*>(&*result))
 >      typename iterator_traits<ForwardIterator>::value_type(*first);
 > 
 > So it looks as it allocates for each iterator value, which isn't  
 > right. The C skeleton allocates a new block and then memcpy's over the  
 > data. Here one should iteratively call the copy-constructors. Then it  
 > might be easier to use std::vector or std::deque. Then using the C- 
 > skeleton start becoming complicated.
 > 

That's not what this means.  The 'new' operator here uses the standard
placement form, which does no allocation, but uses the given address 
(result) as the pointer value, invoking the copy constructor 
(value_type(*first)) on it.  This is indeed the desired behavior.

Paul



reply via email to

[Prev in Thread] Current Thread [Next in Thread]