On 23 Jul 2010, at 00:58, 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.


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.

Yes, sorry. From what I see (cf. 12.14.13), one may have to define
  void* operator new(size_t, void* p) { return p; }
Or is it in the standard?

  Hans



_______________________________________________
help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison

Reply via email to